Looks like the API doesn't currently expose that functionality, you'd have
to add it. Something like (untested):
// Returns true if a pending termination request was found and handled.
bool v8::Isolate::HandleTerminationRequests() {
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(this);
StackLimitCheck check(i_isolate);
if (check.InterruptRequested() &&
i_isolate->stack_guard()->HasTerminationRequest()) {
i_isolate->TerminateExecution();
return true;
}
return false;
}
The return value is useful if your code is currently in the middle of an
expensive operation (such as a loop) from which it can return early.
Or you can just use the extra function call on the JS side, that's
certainly easier and probably fast enough (even for a tight rendering loop).
On Wed, Jul 30, 2025 at 10:27 AM jmr <[email protected]> wrote:
> How do I check in my own native code if termination is happening, and how
> do I throw the uncatchable error?
> IsTerminating seems to return false on the exit of my native call, and
> yes, I can throw an error, but not one that cannot be caught
>
> On Tuesday, 29 July 2025 at 13:22:39 UTC+1 Jakob Kummerow wrote:
>
>> This an optimization: if a loop contains a call, it doesn't need to emit
>> its own stack checks in order to support interrupt requests, because the
>> callee will contain a stack check.
>> So you can add an interrupt check to your native code that you're calling.
>> It *might* be feasible to fix this on the V8 side by checking if the
>> call's target is known to be a non-JS function... not sure.
>>
>> (FWIW, the specific given example is a bit unconvincing: a "tight
>> rendering loop" that "native_sleep(1000)"s all the time can certainly take
>> the minuscule overhead of a function call.)
>>
>>
>> On Tue, Jul 29, 2025 at 9:47 AM jmr <[email protected]> wrote:
>>
>>> Hi,
>>>
>>> I've got code as follows in js:
>>>
>>> while (true) { native_sleep(1000); }
>>>
>>> Effectively js keeps leaving and re-entering native code repeatedly
>>> without affecting it's own stack. I noticed that in a situation like this
>>> TerminateExecution simply does not work.
>>>
>>> If I change my code to:
>>>
>>> func js_sleep(arg) { native_sleep(arg); }
>>> while (true) { js_sleep(1000); }
>>>
>>> Then it works, but this adds an unnecessary js stackframe, which for a
>>> tight rendering loop might not be great.
>>>
>>> Is there a way to propagate termination without an extra js frame
>>> somehow?
>>> I.e., could the termination checks be done when entering/leaving native
>>> calls?
>>> Can I somehow force the propagation to kick in once I'm leaving my
>>> native call?
>>>
>>> Thanks.
>>>
>>> --
>>> --
>>> v8-users mailing list
>>> [email protected]
>>> http://groups.google.com/group/v8-users
>>> ---
>>> You received this message because you are subscribed to the Google
>>> Groups "v8-users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to [email protected].
>>> To view this discussion visit
>>> https://groups.google.com/d/msgid/v8-users/2c2b769d-d599-4493-a459-2f05da527cadn%40googlegroups.com
>>> <https://groups.google.com/d/msgid/v8-users/2c2b769d-d599-4493-a459-2f05da527cadn%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>>
>> --
> --
> v8-users mailing list
> [email protected]
> http://groups.google.com/group/v8-users
> ---
> You received this message because you are subscribed to the Google Groups
> "v8-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion visit
> https://groups.google.com/d/msgid/v8-users/950f397f-0fe2-4acc-96a6-2b7694befdc2n%40googlegroups.com
> <https://groups.google.com/d/msgid/v8-users/950f397f-0fe2-4acc-96a6-2b7694befdc2n%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
--
--
v8-users mailing list
[email protected]
http://groups.google.com/group/v8-users
---
You received this message because you are subscribed to the Google Groups
"v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion visit
https://groups.google.com/d/msgid/v8-users/CAKSzg3TgDEvyQVk9wrApmN3qSnhHzZPz%3DvLF9tmwvmZKQhbr5g%40mail.gmail.com.