changeset 9605:96ccef04f86f

8133775: Some WebNode tests crash JVM Reviewed-by: arajkumar Contributed-by: a.ankit.srivastava@oracle.com
author kcr
date Fri, 04 Mar 2016 12:22:13 -0800
parents de87459ed168
children e111a3367804
files modules/web/src/main/java/com/sun/javafx/webkit/prism/PrismInvoker.java modules/web/src/main/java/com/sun/webkit/Invoker.java modules/web/src/main/java/com/sun/webkit/dom/JSObject.java modules/web/src/test/java/test/javafx/scene/web/MiscellaneousTest.java
diffstat 4 files changed, 28 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/modules/web/src/main/java/com/sun/javafx/webkit/prism/PrismInvoker.java	Fri Mar 04 09:08:22 2016 -0800
+++ b/modules/web/src/main/java/com/sun/javafx/webkit/prism/PrismInvoker.java	Fri Mar 04 12:22:13 2016 -0800
@@ -58,7 +58,7 @@
         return Toolkit.getToolkit().isFxUserThread();
     }
 
-    @Override protected void checkEventThread() {
+    @Override public void checkEventThread() {
         Toolkit.getToolkit().checkFxUserThread();
     }
 
--- a/modules/web/src/main/java/com/sun/webkit/Invoker.java	Fri Mar 04 09:08:22 2016 -0800
+++ b/modules/web/src/main/java/com/sun/webkit/Invoker.java	Fri Mar 04 12:22:13 2016 -0800
@@ -79,7 +79,7 @@
      * @throws IllegalStateException if the current thread is not the event
      *         thread
      */
-    protected void checkEventThread() {
+    public void checkEventThread() {
         if (!isEventThread()) {
             throw new IllegalStateException("Current thread is not event thread"
                     + ", current thread: " + Thread.currentThread().getName());
--- a/modules/web/src/main/java/com/sun/webkit/dom/JSObject.java	Fri Mar 04 09:08:22 2016 -0800
+++ b/modules/web/src/main/java/com/sun/webkit/dom/JSObject.java	Fri Mar 04 12:22:13 2016 -0800
@@ -25,6 +25,7 @@
 
 package com.sun.webkit.dom;
 
+import com.sun.webkit.Invoker;
 import java.security.AccessControlContext;
 import java.security.AccessController;
 import netscape.javascript.JSException;
@@ -49,6 +50,7 @@
 
     @Override
     public Object eval(String s) throws JSException {
+        Invoker.getInvoker().checkEventThread();
         return evalImpl(peer, peer_type, s);
     }
     private static native Object evalImpl(long peer, int peer_type,
@@ -56,6 +58,7 @@
 
     @Override
     public Object getMember(String name) {
+        Invoker.getInvoker().checkEventThread();
         return getMemberImpl(peer, peer_type, name);
     }
     private static native Object getMemberImpl(long peer, int peer_type,
@@ -63,6 +66,7 @@
 
     @Override
     public void setMember(String name, Object value) throws JSException {
+        Invoker.getInvoker().checkEventThread();
         setMemberImpl(peer, peer_type, name, value,
                       AccessController.getContext());
     }
@@ -72,6 +76,7 @@
 
     @Override
     public void removeMember(String name) throws JSException {
+        Invoker.getInvoker().checkEventThread();
         removeMemberImpl(peer, peer_type, name);
     }
     private static native void removeMemberImpl(long peer, int peer_type,
@@ -79,6 +84,7 @@
 
     @Override
     public Object getSlot(int index) throws JSException {
+        Invoker.getInvoker().checkEventThread();
         return getSlotImpl(peer, peer_type, index);
     }
     private static native Object getSlotImpl(long peer, int peer_type,
@@ -86,6 +92,7 @@
 
     @Override
     public void setSlot(int index, Object value) throws JSException {
+        Invoker.getInvoker().checkEventThread();
         setSlotImpl(peer, peer_type, index, value,
                     AccessController.getContext());
     }
@@ -95,6 +102,7 @@
 
     @Override
     public Object call(String methodName, Object... args) throws JSException {
+        Invoker.getInvoker().checkEventThread();
         return callImpl(peer, peer_type, methodName, args,
                         AccessController.getContext());
     }
@@ -104,6 +112,7 @@
 
     @Override
     public String toString() {
+        Invoker.getInvoker().checkEventThread();
         return toStringImpl(peer, peer_type);
     }
     private static native String toStringImpl(long peer, int peer_type);
--- a/modules/web/src/test/java/test/javafx/scene/web/MiscellaneousTest.java	Fri Mar 04 09:08:22 2016 -0800
+++ b/modules/web/src/test/java/test/javafx/scene/web/MiscellaneousTest.java	Fri Mar 04 12:22:13 2016 -0800
@@ -127,6 +127,23 @@
         });
     }
 
+    // JDK-8133775
+    @Test(expected = IllegalStateException.class) public void testDOMObjectThreadOwnership() {
+          class IllegalStateExceptionChecker {
+              public Object resultObject;
+              public void start() {
+                 WebEngine engine = new WebEngine();
+                 // Get DOM object from JavaFX Application Thread.
+                 resultObject = engine.executeScript("document.createElement('span')");
+              }
+           }
+           IllegalStateExceptionChecker obj = new IllegalStateExceptionChecker();
+           submit(obj::start);
+           // Try accessing the resultObject created in JavaFX Application Thread
+           // from someother thread. It should throw an exception.
+           obj.resultObject.toString();
+     }
+
     private WebEngine createWebEngine() {
         return submit(() -> new WebEngine());
     }