I encountered a "fatal error" that I cannot understand. From docs : you need to create an interface object (of any class) and make it known to JavaScript by calling JSObject.setMember() .
Here's the Java exchange code and use of the interface object:
// somewhere in the code JSObject window = (JSObject) engine.executeScript("window"); window.setMember("foo", new Foo()); // <-- shares window.call("testFoo"); // <-- uses // somewhere else class Foo { public void bar() { System.out.println("baz"); } }
And here is the JavaScript code using this object:
window.testFoo = function() { window.foo.bar(); }
This happens if I fire it manually, as shown above, or if I fire it through some kind of JavaScript event.
source share