Skip to content

Commit

Permalink
Ensure that js.tryCatch exception is not empty
Browse files Browse the repository at this point in the history
  • Loading branch information
jasnell committed May 24, 2023
1 parent 3e7ef62 commit 4da87da
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/workerd/jsg/jsg.h
Original file line number Diff line number Diff line change
Expand Up @@ -1802,9 +1802,18 @@ class Lock {
try {
return func();
} catch (JsExceptionThrown&) {
if (!tryCatch.CanContinue()) {
// If tryCatch.HasCaught() is false, it typically means that JsExceptionThrown
// was thrown without an exception actually being scheduled on the isolate.
// This may happen in particular when the JsExceptionThrows was the result of
// TerminateException() but V8 has since cleared the terminate flag because all
// JavaScript call frames have been unwound. Hence, we want to treat this the
// same as if `CanContinue()` returned false.
// TODO(cleanup): Do more investigation, maybe explicitly check for the termination
// flag or arrange to maintain our own separate termination flag to avoid confusion.
if (!tryCatch.CanContinue() || !tryCatch.HasCaught()) {
throw;
}

error = Value(v8Isolate, tryCatch.Exception());
} catch (kj::Exception& e) {
error = exceptionToJs(kj::mv(e));
Expand Down

0 comments on commit 4da87da

Please sign in to comment.