> 3. stopping the script in higher optimized code is impossible under
> the current rhino conditions. I can use the Thread.stop() method but
> am reluctant to do so as it is unsafe. Is it possible to have a stop()
> or interrupt() function to stop execution of a malicious script thats
> running in highly optimized context ?
You're right that this is a feature request and a good one. The right
way to do this is to implement Context.observeInstructionCount for
compiled mode. There would need to be some way to indicate to the
compiler that you'd like to observe the count, and then compile in
callbacks from the generated Java classes at key points (backwards
jumps, function returns) that increment a counter by some value that
approximates the count of executed Java instructions. The runtime
could then monitor these like is already done for interpreted scripts.
Created attachment 283434 [details] [diff] [review]
A Patch for Codegen.java
the function addInstructionCount adds a call in the compiled call to ScriptRuntime to append the number of instructions that is appropriate
Created attachment 283435 [details] [diff] [review]
Patch to ScriptRuntime.java
Added the function that is being called by the compiled class - and adds the instruction count that is given by the argument.
Created attachment 283437 [details] [diff] [review]
PAtch to compilerEnviros.java
Created attachment 283438 [details]
PAtch to Context.java
I changed the approach a bit and added some additional supporting code.
new revision: 1.17; previous revision: 1.16
new revision: 1.261; previous revision: 1.260
new revision: 1.278; previous revision: 1.277
new revision: 1.256; previous revision: 1.255
new revision: 1.14; previous revision: 1.13
new revision: 1.32; previous revision: 1.31