mirror of
https://github.com/denoland/deno.git
synced 2024-12-22 07:14:47 -05:00
fix(core/runtime): always cancel termination in exception handling (#15514)
This commit is contained in:
parent
3caec9721e
commit
e39d4e3e7f
4 changed files with 22 additions and 10 deletions
|
@ -2738,6 +2738,13 @@ itest!(report_error_handled {
|
|||
output: "report_error_handled.ts.out",
|
||||
});
|
||||
|
||||
// Regression test for https://github.com/denoland/deno/issues/15513.
|
||||
itest!(report_error_end_of_program {
|
||||
args: "run --quiet report_error_end_of_program.ts",
|
||||
output: "report_error_end_of_program.ts.out",
|
||||
exit_code: 1,
|
||||
});
|
||||
|
||||
itest!(spawn_stdout_inherit {
|
||||
args: "run --quiet --unstable -A spawn_stdout_inherit.ts",
|
||||
output: "spawn_stdout_inherit.ts.out",
|
||||
|
|
1
cli/tests/testdata/report_error_end_of_program.ts
vendored
Normal file
1
cli/tests/testdata/report_error_end_of_program.ts
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
reportError(new Error("foo"));
|
4
cli/tests/testdata/report_error_end_of_program.ts.out
vendored
Normal file
4
cli/tests/testdata/report_error_end_of_program.ts.out
vendored
Normal file
|
@ -0,0 +1,4 @@
|
|||
error: Uncaught Error: foo
|
||||
reportError(new Error("foo"));
|
||||
^
|
||||
at [WILDCARD]/report_error_end_of_program.ts:1:13
|
|
@ -1156,14 +1156,14 @@ pub(crate) fn exception_to_err_result<'s, T>(
|
|||
) -> Result<T, Error> {
|
||||
let state_rc = JsRuntime::state(scope);
|
||||
|
||||
let is_terminating_exception = scope.is_execution_terminating();
|
||||
let was_terminating_execution = scope.is_execution_terminating();
|
||||
// If TerminateExecution was called, cancel isolate termination so that the
|
||||
// exception can be created. Note that `scope.is_execution_terminating()` may
|
||||
// have returned false if TerminateExecution was indeed called but there was
|
||||
// no JS to execute after the call.
|
||||
scope.cancel_terminate_execution();
|
||||
let mut exception = exception;
|
||||
|
||||
if is_terminating_exception {
|
||||
// TerminateExecution was called. Cancel isolate termination so that the
|
||||
// exception can be created..
|
||||
scope.cancel_terminate_execution();
|
||||
|
||||
{
|
||||
// If the termination is the result of a `Deno.core.terminate` call, we want
|
||||
// to use the exception that was passed to it rather than the exception that
|
||||
// was passed to this function.
|
||||
|
@ -1191,8 +1191,8 @@ pub(crate) fn exception_to_err_result<'s, T>(
|
|||
);
|
||||
}
|
||||
|
||||
if is_terminating_exception {
|
||||
// Re-enable exception termination.
|
||||
if was_terminating_execution {
|
||||
// Resume exception termination.
|
||||
scope.terminate_execution();
|
||||
}
|
||||
|
||||
|
@ -3448,7 +3448,7 @@ assertEquals(1, notify_return_value);
|
|||
Deno.core.ops.op_set_promise_reject_callback((type, promise, reason) => {
|
||||
Deno.core.ops.op_promise_reject();
|
||||
});
|
||||
|
||||
|
||||
throw new Error('top level throw');
|
||||
"#;
|
||||
|
||||
|
|
Loading…
Reference in a new issue