Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8124863

JVM crash when calling to and from Javascript from a WebEngine

    XMLWordPrintable

Details

    • Bug
    • Resolution: Cannot Reproduce
    • P4
    • 8
    • 7u6
    • javafx
    • Windows 7 x64
      java version "1.7.0_13"
      Java(TM) SE Runtime Environment (build 1.7.0_13-b20)
      Java HotSpot(TM) 64-Bit Server VM (build 23.7-b01, mixed mode)

    • web

    Description

      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.

      Attachments

        Activity

          People

            peterz Peter Zhelezniakov
            duke J. Duke
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              Imported: