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/CAKSzg3QfJJ82OUxME2NtN9QVk6xxW%3D%2BjHV4qFYYEGS_DaZx_6A%40mail.gmail.com.

Reply via email to