Is there any way to simply stop the execution of a running script?
I've read the docs and archives and understand that the preferred
methods are for the script to either throw an exception OR for me to
use the observeInstructionCount capability of Rhino.

My issue is that neither of those are ideal for my case. I provide a
hosted service and I want to allow untrusted end-users to execute
arbitrary code written in JavaScript. I've been able to lock down what
objects they can talk to, thanks to ClassShutter. I can also use the
instruction count trick as one method to stop runaway scripts.

But I also have a need to simply stop a script on command at any given
moment in time. Calling Thread.interrupt() works well for when the
script is engaged in an interruptible operation (ie: Thread.sleep(),
file I/O, network calls, etc). But what if the script is in while loop
and isn't calling any interruptible code?

Maybe I'm trivializing how Rhino works, but because it's evaluated on
the fly could there not be some simple "check" that happens after each
instruction and looks to see if a stop flag has been set to true? This
is of course the simple-but-recommended way to stop things in Java,
even since they deprecated Thread.stop():

http://java.sun.com/j2se/1.4.2/docs/guide/misc/threadPrimitiveDeprecation.html

I found one email archive basically saying they bit the bullet and
called Thread.stop(), but I have a LOT of synchronization going on and
the risk that I'd break the multi-threaded code is too high for me to
consider it right now. It also doesn't help that the thread is
actually managed by an Executor, so I don't actually get a handle to
the executing Thread from other threads and instead only get access to
either the calling object (w/ references to the Rhino Context) and the
Future.cancel(true), which causes an interrupt.

I would really appreciate any thoughts on how I can achieve this. Thanks!

Patrick
_______________________________________________
dev-tech-js-engine-rhino mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-js-engine-rhino

Reply via email to