Calling v8::Isolate::ThrowError/Exception from an interrupt callback?

66 views
Skip to first unread message

ClearScript Developers

unread,
Jan 17, 2024, 11:15:36 AM1/17/24
to v8-dev
Hello!

Suppose a long-running script is periodically interrupted via v8::Isolate::RequestInterrupt. The interrupt callback can call v8::Isolate::TerminateExecution to stop the script forcefully.

Is it "legal" for the callback to call v8::Isolate::ThrowError/Exception instead? That worked in 11.8, but 12.1 seems to lose the exception.

Thanks!

ClearScript Developers

unread,
Jan 19, 2024, 12:15:58 PM1/19/24
to v8-dev
Hello again!

It turns out that, in 12.1, calling v8::Isolate::ThrowError from an interrupt callback now causes a DCHECK_EQ failure in v8::internal::Isolate::VerifyBuiltinsResult.

We've compared the 11.8 and 12.1 code, and it looks like the difference may have to do with scheduled exceptions vs. pending exceptions. That distinction seems to have been removed in 12.1, and, as a result, calling v8::Isolate::ThrowError from an interrupt callback is now a guaranteed crash.

Can someone confirm that? Is it a bug?

Thanks!

ClearScript Developers

unread,
Jan 19, 2024, 4:38:34 PM1/19/24
to v8-dev
We managed to restore the functionality as follows:

diff --git a/src/execution/stack-guard.cc b/src/execution/stack-guard.cc
index efcaf8cd10b..0e7cfbb704d 100644
--- a/src/execution/stack-guard.cc
+++ b/src/execution/stack-guard.cc
@@ -383,6 +385,8 @@ Tagged<Object> StackGuard::HandleInterrupts(InterruptLevel level) {
 
   isolate_->counters()->stack_interrupts()->Increment();
 
+  if (isolate_->has_exception()) return ReadOnlyRoots(isolate_).exception();
+
   return ReadOnlyRoots(isolate_).undefined_value();
 }
 
V8 team, please let us know if this is worth a PR. Thanks!
Reply all
Reply to author
Forward
0 new messages