Vidar Ramdal <vi...@...> writes:
>
> I tried to mock up a simple ESP console, where I could enter a line of
> script and have it evaluated on the server side.
> Everything works well, except that variables are not persisted between
> eval()s. So that:
>
> engine.eval("var foo = ''bar");
> engine.eval("foo.length");
>
> ... does not return 3 (the length of "bar"), but instead throws a
> ReferenceError: "foo" is not defined.
>
> When I run the code in outside of Sling, I get a
> com.sun.script.javascript.RhinoScriptEngine instead of the
> o.a.s.scripting.javascript.internal.RhinoJavaScriptEngine. With Sun's
> implementation, I get the result I want.
>
> Is this a bug, and if not, is there a way to accomplish what I want?
>
Hi Vidar,
Try using [1] instead. I believe that your first statement fails, therefore,
the engine is properly evaluating the second statement.
Respectfully,
John
[1]
engine.eval("var foo = 'bar'");
engine.eval("foo.length");