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

JVM crash when calling to and from Javascript from a WebEngine

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P4
    • Resolution: Cannot Reproduce
    • Affects Version/s: 7u6
    • Fix Version/s: 8
    • Component/s: javafx
    • Labels:
    • Environment:

      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)

    • Subcomponent:
      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

            • Assignee:
              peterz Peter Zhelezniakov
              Reporter:
              duke J. Duke (Inactive)
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Imported: