I'm just a bit confused about scopes, and scripts, and reusing
compiled code and when (or, more likely, when not) to call
initStandardObjects.
Here's my goal.
I have an event coming in to the system, and the JavaScript is being
used to run rules against it, mostly for side effects.
My intent was that I would be able to have 3 different scopes. A
Global Scope that is shared across all events in the the system. An
Event scope that lives with the event as rules are run against it, A
Rule scope which is limited to the rule itself.
So, if I have 3 blocks of JS, and I compile each of them with
compileString, I get 3 scripts.
Should I just do something like this:
Scriptable root = context.initStandardObject();
Scriptable global = context.compileString(...);
Scriptable event = context.compileString(...);
Scriptable rule = context.compileString(...);
global.setParentScope(root);
event.setParentScope(global);
result = rule.exec(context, event);
Is that the best way to keep these parts separated, and keep reusing
these blocks of code?
Later, say, when a new event shows up, I'd like to create a new event
scope, bind and event value in to it for use by the script, and then
just link them up as above and run the rule. That should work?
And while Contexts are thread safe, the Scriptables are not, correct?
I would need a unique Scriptable instance per thread, or synchronize
access (should not be a problem for this project).
If I do it this way, and, say, the "rule" code did something like "eval
("a = 1");", where would "a" end up being placed? Does it stay in
"rule"? end up in "root"? and does that survive execution?
Am I making any sense whatsoever?
Thanks for any insight.
Regards,
Will Hartung
_______________________________________________
dev-tech-js-engine-rhino mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-js-engine-rhino