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

Javascript instanceof not working for subclasses of Event in WebView

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P4
    • Resolution: Duplicate
    • Affects Version/s: 8u271, openjfx11, openjfx15, openjfx16
    • Fix Version/s: None
    • Component/s: javafx
    • Subcomponent:
      web
    • CPU:
      generic
    • OS:
      generic

      Description

      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


        Attachments

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

          Issue Links

            Activity

              People

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

                Dates

                Created:
                Updated:
                Resolved: