When using a WebEngine and calling from Javascript a Java function that calls a Javascript function, the JRE crashes (see the code for the exact situation)
---- Begin code
import netscape.javascript.JSObject;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.concurrent.Worker.State;
import javafx.scene.web.WebEngine;
import javafx.scene.web.WebView;
import javafx.stage.Stage;
public class Main extends Application {
public static void main(String[] args) {
Application.launch(Main.class);
}
public class ParentFunctions {
public void parentfunc(final JSObject obj) {
Platform.runLater(new Runnable() {
@Override
public void run() {
obj.call("success");
}
});
}
};
@Override
public void start(Stage stage) throws Exception {
final WebEngine engine = new WebEngine();
engine.loadContent("<script type='text/javascript'>function init(javaobj) { javaobj.parentfunc({ success : function() {document.write('success');} }); }</script>");
engine.getLoadWorker().stateProperty().addListener(new ChangeListener<State>() {
@Override
public void changed(ObservableValue<? extends State> paramObservableValue, State paramT1, State newState) {
if(newState == State.SUCCEEDED) {
JSObject window = (JSObject) engine.executeScript("window");
window.call("init", new ParentFunctions());
}
}
});
}
}
---- End code
I'm not sure I can attach files, so I haven't included the crash log.
---- Begin code
import netscape.javascript.JSObject;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.concurrent.Worker.State;
import javafx.scene.web.WebEngine;
import javafx.scene.web.WebView;
import javafx.stage.Stage;
public class Main extends Application {
public static void main(String[] args) {
Application.launch(Main.class);
}
public class ParentFunctions {
public void parentfunc(final JSObject obj) {
Platform.runLater(new Runnable() {
@Override
public void run() {
obj.call("success");
}
});
}
};
@Override
public void start(Stage stage) throws Exception {
final WebEngine engine = new WebEngine();
engine.loadContent("<script type='text/javascript'>function init(javaobj) { javaobj.parentfunc({ success : function() {document.write('success');} }); }</script>");
engine.getLoadWorker().stateProperty().addListener(new ChangeListener<State>() {
@Override
public void changed(ObservableValue<? extends State> paramObservableValue, State paramT1, State newState) {
if(newState == State.SUCCEEDED) {
JSObject window = (JSObject) engine.executeScript("window");
window.call("init", new ParentFunctions());
}
}
});
}
}
---- End code
I'm not sure I can attach files, so I haven't included the crash log.