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

Javascript instanceof not working for subclasses of Event in WebView

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • jfx11, 8u271, jfx15, jfx16
    • javafx
    • web
    • generic
    • generic

      ADDITIONAL SYSTEM INFORMATION :
      Linux x86_64 / Ubuntu Mate 21.04 / openJDK 16.0.1

      The problem has been around since at least Java 12/JavaFX 12 and is also present on Windows 7 and 10 x86_64.

      A DESCRIPTION OF THE PROBLEM :
      JavaScript instanceof is not evaluated correctly for subclasses of Event in the JavaFX WebView.

      The submitted example HTML behaves as expected on e.g. Chrome, Opera, Firefox, Edge.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Create an HTML file with embedded or imported JavaScript.

      Create a subclass of Event within a script tag in the HTML file. Create an instance of the class and use instanceof on it.


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The instanceof operator should return true.
      ACTUAL -
      The instanceof operator returns false.

      ---------- BEGIN SOURCE ----------
      import javafx.application.Application;
      import javafx.scene.Scene;
      import javafx.scene.web.WebView;
      import javafx.stage.Stage;


      public class Demo extends Application {

      @Override
      public void start(final Stage stage) throws Exception {
      final var view = new WebView();
      final var scene = new Scene(view);

      stage.setWidth(800);
      stage.setHeight(600);
      stage.setScene(scene);
      stage.show();

      final var content =
      """
      <!DOCTYPE html>
      <html>
      <body>
      <script>
      class B extends Event {
      this(type) {
      this.type = type;
      }
      }
      const myObject = new B("type");
      const p = document.createElement("p");
      const text = `myObject is instanceof B: ${myObject instanceof B}`;
      p.textContent = text;
      document.body.appendChild(p);
      </script>
      </body>
      </html>
      """;

      view.getEngine().loadContent(content);
      }

      public static void main(String[] args) {
      launch(args);
      }

      }
      ---------- END SOURCE ----------

      FREQUENCY : always


        1. Demo.java
          1.0 kB
        2. Capture_17.PNG
          Capture_17.PNG
          29 kB
        3. Capture_16.PNG
          Capture_16.PNG
          33 kB

            arapte Ambarish Rapte
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: