eval in DebuggerSupport.java fails.
Attila Szegedi
attila.szegedi at oracle.com
Thu Oct 2 14:29:04 UTC 2014
Not all locals live in the scope object. If you look at the code Nashorn emits[*] you will see that Nashorn strives to use JVM bytecode local variables whenever it can. Only function local variables that need to be visible in a nested lexical context (e.g. nested function) will be pushed into the scope object.
Attila.
--
[*] Use the --print-code command line switch to jjs. Programmatically, use "-Dnashorn.args=--print-code" or use NashornScriptEngineFactory explicitly and invoke its getScriptEngine(String...) method to pass command line arguments.
On Sep 30, 2014, at 10:36 AM, Kuperman Sergey <seastranger at gmail.com> wrote:
> Kuperman Sergey <seastranger at ...> writes:
>
>>
>> Hello ! I am not sure it is the right place to ask but i will try anyway )
>> My team is trying to develop a JS debugger poc running Nashorn , and we
>> encountered an issue when trying to implement evaluation in function context:
>> We run some JS function with:
>> ScriptEngineManager sem = new ScriptEngineManager();
>> ScriptEngine engine = sem.getEngineByName("nashorn");
>> engine.eval("load (\"src/com/sap/rdl/runjs/file.js\");");
>> in another app we set a breakpoint in a function, and try to invoke eval()
>> function from DebuggerSupport.java , while passing to it :scope variable we
>> received from the relevant frame's visibleVariables (JDI).
>> eval succeeds when global or upper scope defined variables are involved, but
>> if i use an expression with local function variable, i receive ECMAException
>> no such variable defined.. it seems to me that eval needs local vars to be
>> defined within the scope but they are not ..
>> Is there anything i could do to make it work ?
>>
>> Thanks in advance
>>
>> Sergey
>> SAP RDL development team
>>
>>
>
> A little further investigation shows, that nashorn :scope loads variables
> lazily - only when needed or if eval function is used inside js.
> Is there a way to force :scope to contain all vars regardless of use ? I
> mean except using dummy eval statement that would be an ugly workaround..
> thanks in advance
> Sergey
>
>
More information about the nashorn-dev
mailing list