import javafx.scene.Scene;
import javafx.scene.layout.StackPane;
import javafx.scene.web.WebEngine;
import javafx.scene.web.WebView;
import javafx.stage.Stage;
import netscape.javascript.JSObject;
public class CharBindingFailure extends Application {
public char c = 'm';
public char doChar(char c) {
return c;
}
@Override
public void start(Stage stage) throws Exception {
WebView view = new WebView();
WebEngine engine = view.getEngine();
stage.setScene(new Scene(new StackPane(view), 320, 240));
stage.setOnShown((e) -> {
JSObject window = (JSObject) engine.executeScript("window;");
window.setMember("testObject", this);
window.setMember("testValue", 'a');
Object resultObject = engine.executeScript("testValue");
System.out.println(resultObject instanceof Character);
resultObject = engine.executeScript("testObject.doChar(testValue)");
System.out.println(resultObject instanceof Character);
resultObject = engine.executeScript("testObject.doChar('n')");
System.out.println(resultObject instanceof Character);
resultObject = engine.executeScript("testObject.c = 'hello world';");
System.out.println(resultObject instanceof String);
resultObject = engine.executeScript("testObject.c;");
System.out.println(resultObject instanceof Character);
});
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}
Above code should print "true" all cases.