Possible scope leak in Nashorn
Tim Fox
timvolpe at gmail.com
Tue Dec 10 10:00:54 PST 2013
On 10/12/13 17:15, Tim Fox wrote:
> On 10/12/13 16:52, André Bargull wrote:
>>> Thanks, I adapted the code to use ScriptUtils.wrap() and encountered a
>>> strange situation where JSON.stringify returns undefined for a valid JS
>>> object. Maybe another scope problem?
>>>
>>> Here is a reproducer:https://gist.github.com/purplefox/7893408
>>
>> No, it's not a scope problem. JSON.stringify isn't able to process
>> ScriptObjectMirror objects, see ll. 263-270 in NativeJSON.java [1].
>>
>> - André
>>
>> [1]
>> http://hg.openjdk.java.net/nashorn/jdk8/nashorn/file/tip/src/jdk/nashorn/internal/objects/NativeJSON.java
>
> I see, so when a JS method in one scope is invoked from another scope
> all the arguments get automatically wrapped in a ScriptObjectMirror. I
> suppose NativeJSON needs to check for ScriptObjectMirror and unwrap
> internally before attempting to stringify (?)
>
> I wonder if anyone could suggest a workaround for now? (it's not
> obvious to me)
>
>
I've managed to work around this for now by not using the JSON impl in
Nashorn but hacking Crockford's pure JS version
<https://github.com/douglascrockford/JSON-js>https://github.com/douglascrockford/JSON-js
and using that.
<https://github.com/douglascrockford/JSON-js>
More information about the nashorn-dev
mailing list