Method on Isolate to check for interrupts

23 views
Skip to first unread message

Noa

unread,
Apr 22, 2026, 11:59:22 AMApr 22
to v8-dev
Hi all,

I'm using `v8::Isolate::TerminateExecution` for a couple of different things, and am trying to make sure that execution will stop as soon as possible after it's requested. In one place, we call TerminateExecution inside of a host function, in the context of a HandleScope, and I'd like to make sure that execution doesn't continue in JS after that function returns (currently, `IsExecutionTerminating() == false` directly after calling TerminateExecution). I also want to check that there's no execution termination in-queue at the start of the call of a host function.

Looking at the v8 source, it seems like `v8::internal::StackGuard::HandleInterrupts` (or perhaps `v8::internal::StackLimitCheck::HandleStackOverflowAndTerminationRequest`) would be the ideal function to call in both of these situations, but neither are exposed in the public API. Would it be reasonable to expose a `v8::Isolate::HandleInterrupts` method that would forward to one of those internal functions?

Alternatively, my first case could be fixed by a non-thread-safe `v8::Isolate::TerminateExecutionNow`, which directly calls `v8::internal::Isolate::TerminateExecution` (i.e, `Throw(termination_exception)`). This would be nice to have, but not fundamentally different from `TerminateExecution(); HandleInterrupts()`.

In any case, I'd be willing to submit a patch implementing this method, if that would be welcomed.

Best,
Noa

Erik Corry

unread,
Apr 23, 2026, 6:00:41 AMApr 23
to v8-...@googlegroups.com
The stack guard should be checked on every call and on every back edge
of a loop in JS, so it should be happening quite fast. Are you seeing
that it doesn't immediately stop when you return to JS?
> --
> --
> v8-dev mailing list
> v8-...@googlegroups.com
> http://groups.google.com/group/v8-dev
> ---
> You received this message because you are subscribed to the Google Groups "v8-dev" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to v8-dev+un...@googlegroups.com.
> To view this discussion visit https://groups.google.com/d/msgid/v8-dev/d104b942-e71d-469f-893c-ad04e805ad14n%40googlegroups.com.



--
--
Erik Corry, working on V8 at Cloudflare

Noa

unread,
Apr 23, 2026, 1:56:23 PMApr 23
to v8-...@googlegroups.com
I don't think that's been observed, so I guess my coworker just wrote
this part of our code not knowing the frequency at which the interrupt
flag is checked. It'd kind of be nice as a user to have a guarantee,
since there's no way to know for sure that v8 is inserting those
interrupt checks, though I suppose it is indeed a pretty safe assumption
that there would be a stack check on every call. If what you say is
true, I guess we don't actually have a need for this, so thank you. (I
do still think it'd be a reasonable API to provide for e.g. recursive or
long-running host calls.)
Noa, they/she
github.com/coolreader18

Reply all
Reply to author
Forward
0 new messages