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)
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.
Thanks!