JDK-8271016 : Javascript instanceof not working for subclasses of Event in WebView
  • Type: Bug
  • Component: javafx
  • Sub-Component: web
  • Affected Version: 8u271,openjfx11,openjfx15,openjfx16
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: generic
  • CPU: generic
  • Submitted: 2021-07-16
  • Updated: 2021-12-06
  • Resolved: 2021-12-06
Related Reports
Duplicate :  
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



Comments
I can confirm that this fails in JDK 8u271 and JavaFX 16. It passes in JDK 8u291 and JavaFX 17, so it is fixed by the WebKit 610.2 update, JDK-8259635.
06-12-2021

Issue does not occur with and after releases 8u291 b09, openjfx17. As the issue does not occur with new releases, it seems not required to fix with earlier releases.
04-08-2021

Checked with attached testcase in Ubuntu 20.04 and Windows 10, Issue is reproducible Test result: ============ openjfx17ea: Pass <attached screenshot><Capture_17.png> openjfx16: Fail <attached screenshot><Capture_16.png openjfx15: Fail openjfx11: Fail
21-07-2021