David,

At issue is the fact that WebEngine JS objects come from WebJS (not Nashorn) 
and are really Java objects from Nashorn's perspective (including undefined.)  
In order for them to be treated like Nashorn JavaScript objects you need to 
wrap these objects in something like a JSAdaptor.  See 
https://blogs.oracle.com/nashorn/entry/porting_from_the_browser_to for starting 
points.

Cheers,

-- Jim




> On Mar 27, 2015, at 8:11 AM, David P. Caldwell 
> <[email protected]> wrote:
> 
> So it's very cool, and unexpected, that JavaScript objects obtained
> from a JavaFX WebEngine show up as something like ordinary Nashorn
> objects in Nashorn scripts. That's an unexpected bonus (I was planning
> on using .setMember() and all that stuff from
> netscape.javascript.JSObject).
> 
> The objects behave a bit strangely, though. So I've got a couple of
> bug reports, I guess.
> 
> Here's a script that demonstrates the ones I've found so far:
> 
> var WebEngine = Java.type("javafx.scene.web.WebEngine");
> var engine = new WebEngine();
> 
> var window = engine.executeScript("window");
> 
> print("foo = " + window.foo);
> print("typeof(window.foo) = " + typeof(window.foo));
> if (window.foo) {
>    print("window.foo is truthy");
> }
> 
> Output:
> $ /usr/lib/jvm/jdk1.8.0_40/bin/jjs -fx nashorn.js
> foo = undefined
> typeof(window.foo) = string
> window.foo is truthy
> 
> I actually am using a much more complicated embedding that is done
> from Java, so I can tell you the problem is not in the implementation
> of the -fx flag.
> 
> Other than that, I can't see much; I haven't delved into the Nashorn
> code, let alone whatever magic enables this.
> 
> -- David.

Reply via email to