diff options
author | Nayeem Rahman <nayeemrmn99@gmail.com> | 2021-02-18 22:36:02 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-19 09:36:02 +1100 |
commit | 555595e6d02d1fc1adb535df074d258389fab509 (patch) | |
tree | 73257523ea5f5ac44293b6820d72e8dae038b7b5 | |
parent | bb30e9291e2e3964aac2d2ca05b739dcc67d64a0 (diff) |
fix(core): Make dynamic import async errors catchable (#9505)
Fixes #6259
-rw-r--r-- | cli/tests/085_dynamic_import_async_error.ts | 5 | ||||
-rw-r--r-- | cli/tests/085_dynamic_import_async_error.ts.out | 2 | ||||
-rw-r--r-- | cli/tests/delayed_error.ts | 2 | ||||
-rw-r--r-- | cli/tests/integration_tests.rs | 5 | ||||
-rw-r--r-- | core/runtime.rs | 6 |
5 files changed, 20 insertions, 0 deletions
diff --git a/cli/tests/085_dynamic_import_async_error.ts b/cli/tests/085_dynamic_import_async_error.ts new file mode 100644 index 000000000..aa5ff7277 --- /dev/null +++ b/cli/tests/085_dynamic_import_async_error.ts @@ -0,0 +1,5 @@ +try { + await import("./delayed_error.ts"); +} catch (error) { + console.log(`Caught: ${error.stack}`); +} diff --git a/cli/tests/085_dynamic_import_async_error.ts.out b/cli/tests/085_dynamic_import_async_error.ts.out new file mode 100644 index 000000000..974c2e426 --- /dev/null +++ b/cli/tests/085_dynamic_import_async_error.ts.out @@ -0,0 +1,2 @@ +[WILDCARD]Caught: Error: foo + at [WILDCARD]/delayed_error.ts:[WILDCARD] diff --git a/cli/tests/delayed_error.ts b/cli/tests/delayed_error.ts new file mode 100644 index 000000000..76057e627 --- /dev/null +++ b/cli/tests/delayed_error.ts @@ -0,0 +1,2 @@ +await new Promise((r) => setTimeout(r, 100)); +throw new Error("foo"); diff --git a/cli/tests/integration_tests.rs b/cli/tests/integration_tests.rs index b55111154..47acdc9ee 100644 --- a/cli/tests/integration_tests.rs +++ b/cli/tests/integration_tests.rs @@ -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", diff --git a/core/runtime.rs b/core/runtime.rs index 31229aaa3..35f9e7e43 100644 --- a/core/runtime.rs +++ b/core/runtime.rs @@ -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); |