Monitoring and interrupting the execution, analogs of JS_SetOperationCallback/JS_SetBranchCallback in SpiderMonkey?

61 views
Skip to first unread message

Martin Lemke

unread,
Jul 23, 2009, 4:12:40 AM7/23/09
to v8-users
I would like to monitor the execution of the script in v8,
interrupting it if the execution takes an excessive amount of time,
e.g. as a result of an endless loop. If you are familiar, SpiderMonkey
JS engine has JS_SetOperationCallback (JS_SetBranchCallback) API which
can be adopted for that purpose.

From what I learned about v8, the only way would be to run an instance
of the v8 interpreter in a separate process, monitor it externally and
terminate the process when I decide that the processing takes too much
time.

I hoped that SetCounterFunction and SetCreateHistogramFunction may
help but apparently they do not cover the execution stage, or at least
they do not produce anything if I am inside an endless loop which
doesn't affect the garbage collection.

Could be that I missed something? Is there a better way to monitor the
time of the execution and interrupt it when necessary?

Thanks,
Martin

Mads Sig Ager

unread,
Jul 23, 2009, 4:18:06 AM7/23/09
to v8-u...@googlegroups.com
Hi Martin,

you are not missing anything. Currently, using a separate process
that you can kill if your JavaScript enters an infinite loop or
otherwise takes too much time is the only way to go. We are
considering adding a way of terminating V8 execution from the side
(which would lead to throwing a thread termination exception which
cannot be caught by JavaScript try catch handlers), but it is not
there yet.

Cheers, -- Mads

Kenji

unread,
Jul 23, 2009, 4:53:43 AM7/23/09
to v8-users
Hi all, I'm looking for an execution time-out feature as well.
It's sad to know v8 doesn't have a way to do that, because I can't let
any script to block my server.

I really hope this missing feature will be implemented very soon.

Cheers,
Kenji

Mads Sig Ager

unread,
Aug 19, 2009, 2:41:44 PM8/19/09
to v8-u...@googlegroups.com
Script termination from the side has now been added to V8. Look for
the TerminateExecution methods in the API and have a look at the
test/cctest/test-thread-termination.cc test file for examples of using
it.

Cheers, -- Mads
Reply all
Reply to author
Forward
0 new messages