1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-11 18:17:48 -05:00

fix(core): BorrowMutError in nested error (#15352)

This commit is contained in:
Bartek Iwańczuk 2022-07-30 16:09:42 +02:00 committed by crowlkats
parent f1a80fb212
commit f3a496214c
No known key found for this signature in database
GPG key ID: A82C9D461FC483E8
4 changed files with 24 additions and 15 deletions

View file

@ -2792,3 +2792,9 @@ itest!(unhandled_rejection_sync_error {
args: "run --check unhandled_rejection_sync_error.ts", args: "run --check unhandled_rejection_sync_error.ts",
output: "unhandled_rejection_sync_error.ts.out", output: "unhandled_rejection_sync_error.ts.out",
}); });
itest!(nested_error {
args: "run nested_error.ts",
output: "nested_error.ts.out",
exit_code: 1,
});

3
cli/tests/testdata/nested_error.ts vendored Normal file
View file

@ -0,0 +1,3 @@
throw {
foo: new Error(),
};

View file

@ -0,0 +1,4 @@
error: Uncaught {
foo: Error
at file:///[WILDCARD]testdata/nested_error.ts:2:8
}

View file

@ -192,20 +192,17 @@ impl JsError {
let msg = v8::Exception::create_message(scope, exception); let msg = v8::Exception::create_message(scope, exception);
let mut exception_message = None; let mut exception_message = None;
// Nest this state borrow. A mutable borrow can occur when accessing `stack` let state_rc = JsRuntime::state(scope);
// in this outer scope, invoking `Error.prepareStackTrace()` which calls
// `op_apply_source_map`. let js_format_exception_cb =
{ state_rc.borrow().js_format_exception_cb.clone();
let state_rc = JsRuntime::state(scope); if let Some(format_exception_cb) = js_format_exception_cb {
let state = state_rc.borrow(); let format_exception_cb = format_exception_cb.open(scope);
if let Some(format_exception_cb) = &state.js_format_exception_cb { let this = v8::undefined(scope).into();
let format_exception_cb = format_exception_cb.open(scope); let formatted = format_exception_cb.call(scope, this, &[exception]);
let this = v8::undefined(scope).into(); if let Some(formatted) = formatted {
let formatted = format_exception_cb.call(scope, this, &[exception]); if formatted.is_string() {
if let Some(formatted) = formatted { exception_message = Some(formatted.to_rust_string_lossy(scope));
if formatted.is_string() {
exception_message = Some(formatted.to_rust_string_lossy(scope));
}
} }
} }
} }
@ -263,7 +260,6 @@ impl JsError {
let mut source_line = None; let mut source_line = None;
let mut source_line_frame_index = None; let mut source_line_frame_index = None;
{ {
let state_rc = JsRuntime::state(scope);
let state = &mut *state_rc.borrow_mut(); let state = &mut *state_rc.borrow_mut();
// When the stack frame array is empty, but the source location given by // When the stack frame array is empty, but the source location given by