Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] destrucutre AggregateError #425

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 51 additions & 1 deletion core/runtime/tests/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ if (errMessage !== "higher-level sync error: original sync error") {
r#"
(async () => {
let errMessage;
const { op_err_async } = Deno.core.ensureFastOps();
const { op_err_async } = Deno.core.ensureFastOps();
try {
await op_err_async();
} catch (err) {
Expand Down Expand Up @@ -115,3 +115,53 @@ fn syntax_error() {
let frame = js_error.frames.first().unwrap();
assert_eq!(frame.column_number, Some(12));
}

#[tokio::test]
async fn aggregate_error() {
let mut runtime = JsRuntime::new(Default::default());
let src = r#"
(async () => {
await Promise.any([]);
})()
"#;
let value_global = runtime
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any chance these could be integration and/or unit tests? I'd like to avoid adding more of these tests which are a bit awkward to maintain in Rust.

.execute_script_static("test_aggregate_error.js", src)
.unwrap();
let resolve = runtime.resolve(value_global);
let e = runtime
.with_event_loop_promise(resolve, PollEventLoopOptions::default())
.await
.unwrap_err();
let js_error = e.downcast::<JsError>().unwrap();

assert_eq!(js_error.frames.len(), 0);
}

#[tokio::test]
async fn aggregate_error_destructure() {
let mut runtime = JsRuntime::new(Default::default());
let src = r#"
(async () => {
try {
await Promise.any([]);
} catch (e) {
return Deno.core.destructureError(e).frames;
}
})()
"#;
let value_global = runtime
.execute_script_static("test_aggregate_error_destructure.js", src)
.unwrap();
let resolve = runtime.resolve(value_global);
let out = runtime
.with_event_loop_promise(resolve, PollEventLoopOptions::default())
.await
.unwrap();

let scope = &mut runtime.handle_scope();

let out = v8::Local::new(scope, out);
let out = v8::Local::<v8::Array>::try_from(out).unwrap();

assert_eq!(out.length(), 0);
}
Loading