-
Notifications
You must be signed in to change notification settings - Fork 846
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pausing script executions from Java through Context.observeInstructionCount & .captureContinuation #1475
Comments
Which ContextFactory docs are you taking your inspiration from? As to the exception you're getting: based on where in the code the exception in thrown (Rhino expected there to be a That would make your usecase (currently) not supported, but maybe you can figure out a way to support your usecase and provide a PR |
I meant the javadoc of
I'm pretty new to rhino and still learning how it works. I'll be glad to provide a PR if I figure the solution out someday. |
Unfortunately, you won't be able to use continuations for this purpose. Continuations must be captured either at a point in code that is a function call, or a constructor (so, either call to a Java method that does Additionally, when you resume a continuation you need to pass it a return value. Somewhat counterintuitively, the way continuations are resumed is not that the execution continues at the point where the continuation is captured. Rather, the function in which the continuation was captured immediately returns with the given return value. Instruction count observer can interrupt script execution anywhere, and continuations must be captured at function/constructor calls, hence your bug when you attempted to capture or resume them from an arbitrary point. I'm not saying this is impossible to solve, but it would be pretty hard and I'm not sure we'd want to support the additional complexity. |
Rhino version: 1.7.15
Java version: 21
I'm trying to imeplement a feature that allows Java to pause script executions while observing based on the example in the docs of
ContextFactory
. There will be untrusted scripts in my case so I need to pause them from Java side.The codes above throw exceptions however.
Is this not supported?
The text was updated successfully, but these errors were encountered: