0
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-10-29 08:58:01 -04:00

fix(core): Make dynamic import async errors catchable (#9505)

Fixes #6259
This commit is contained in:
Nayeem Rahman 2021-02-18 22:36:02 +00:00 committed by GitHub
parent bb30e9291e
commit 555595e6d0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 20 additions and 0 deletions

View file

@ -0,0 +1,5 @@
try {
await import("./delayed_error.ts");
} catch (error) {
console.log(`Caught: ${error.stack}`);
}

View file

@ -0,0 +1,2 @@
[WILDCARD]Caught: Error: foo
at [WILDCARD]/delayed_error.ts:[WILDCARD]

View file

@ -0,0 +1,2 @@
await new Promise((r) => setTimeout(r, 100));
throw new Error("foo");

View file

@ -2779,6 +2779,11 @@ console.log("finish");
output: "084_worker_custom_inspect.ts.out",
});
itest!(_085_dynamic_import_async_error {
args: "run --allow-read 085_dynamic_import_async_error.ts",
output: "085_dynamic_import_async_error.ts.out",
});
itest!(js_import_detect {
args: "run --quiet --reload js_import_detect.ts",
output: "js_import_detect.ts.out",

View file

@ -822,6 +822,12 @@ impl JsRuntime {
);
let promise = v8::Local::<v8::Promise>::try_from(value)
.expect("Expected to get promise as module evaluation result");
let empty_fn = |_scope: &mut v8::HandleScope,
_args: v8::FunctionCallbackArguments,
_rv: v8::ReturnValue| {};
let empty_fn = v8::FunctionTemplate::new(scope, empty_fn);
let empty_fn = empty_fn.get_function(scope).unwrap();
promise.catch(scope, empty_fn);
let promise_global = v8::Global::new(scope, promise);
let mut state = state_rc.borrow_mut();
state.pending_promise_exceptions.remove(&promise_global);