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:
parent
bb30e9291e
commit
555595e6d0
5 changed files with 20 additions and 0 deletions
5
cli/tests/085_dynamic_import_async_error.ts
Normal file
5
cli/tests/085_dynamic_import_async_error.ts
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
try {
|
||||||
|
await import("./delayed_error.ts");
|
||||||
|
} catch (error) {
|
||||||
|
console.log(`Caught: ${error.stack}`);
|
||||||
|
}
|
2
cli/tests/085_dynamic_import_async_error.ts.out
Normal file
2
cli/tests/085_dynamic_import_async_error.ts.out
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
[WILDCARD]Caught: Error: foo
|
||||||
|
at [WILDCARD]/delayed_error.ts:[WILDCARD]
|
2
cli/tests/delayed_error.ts
Normal file
2
cli/tests/delayed_error.ts
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
await new Promise((r) => setTimeout(r, 100));
|
||||||
|
throw new Error("foo");
|
|
@ -2779,6 +2779,11 @@ console.log("finish");
|
||||||
output: "084_worker_custom_inspect.ts.out",
|
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 {
|
itest!(js_import_detect {
|
||||||
args: "run --quiet --reload js_import_detect.ts",
|
args: "run --quiet --reload js_import_detect.ts",
|
||||||
output: "js_import_detect.ts.out",
|
output: "js_import_detect.ts.out",
|
||||||
|
|
|
@ -822,6 +822,12 @@ impl JsRuntime {
|
||||||
);
|
);
|
||||||
let promise = v8::Local::<v8::Promise>::try_from(value)
|
let promise = v8::Local::<v8::Promise>::try_from(value)
|
||||||
.expect("Expected to get promise as module evaluation result");
|
.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 promise_global = v8::Global::new(scope, promise);
|
||||||
let mut state = state_rc.borrow_mut();
|
let mut state = state_rc.borrow_mut();
|
||||||
state.pending_promise_exceptions.remove(&promise_global);
|
state.pending_promise_exceptions.remove(&promise_global);
|
||||||
|
|
Loading…
Reference in a new issue