Possible scope leak in Nashorn
timvolpe at gmail.com
Tue Dec 10 09:15:04 PST 2013
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 .
> - André
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
Regarding the wrapping - do you think the argument wrapping is going to
impose a significant performance penalty? I'm thinking of CommonJS based
systems like node or vert.x (JS) where you are calling between scopes
basically every time you call the api.
More information about the nashorn-dev