Quantcast

[HtmlUnit] SVN: [13831] trunk/htmlunit/src

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[HtmlUnit] SVN: [13831] trunk/htmlunit/src

asashour-2
Revision: 13831
          http://sourceforge.net/p/htmlunit/code/13831
Author:   asashour
Date:     2017-03-19 21:38:57 +0000 (Sun, 19 Mar 2017)
Log Message:
-----------
JavaScript: handle calls after JavaScriptEngine.shutdown()

Modified Paths:
--------------
    trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/JavaScriptEngine.java
    trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/JavaScriptEngineTest.java

Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/JavaScriptEngine.java
===================================================================
--- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/JavaScriptEngine.java 2017-03-19 20:27:24 UTC (rev 13830)
+++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/JavaScriptEngine.java 2017-03-19 21:38:57 UTC (rev 13831)
@@ -101,7 +101,7 @@
 
     private static final Log LOG = LogFactory.getLog(JavaScriptEngine.class);
 
-    private final WebClient webClient_;
+    private WebClient webClient_;
     private final HtmlUnitContextFactory contextFactory_;
     private final JavaScriptConfiguration jsConfig_;
 
@@ -632,10 +632,12 @@
      * @param webWindow the WebWindow to be registered.
      */
     public synchronized void registerWindowAndMaybeStartEventLoop(final WebWindow webWindow) {
-        if (javaScriptExecutor_ == null) {
-            javaScriptExecutor_ = BackgroundJavaScriptFactory.theFactory().createJavaScriptExecutor(webClient_);
+        if (webClient_ != null) {
+            if (javaScriptExecutor_ == null) {
+                javaScriptExecutor_ = BackgroundJavaScriptFactory.theFactory().createJavaScriptExecutor(webClient_);
+            }
+            javaScriptExecutor_.addWindow(webWindow);
         }
-        javaScriptExecutor_.addWindow(webWindow);
     }
 
     /**
@@ -655,6 +657,7 @@
      * Shutdown the JavaScriptEngine.
      */
     public void shutdown() {
+        webClient_ = null;
         if (javaScriptExecutor_ != null) {
             javaScriptExecutor_.shutdown();
             javaScriptExecutor_ = null;

Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/JavaScriptEngineTest.java
===================================================================
--- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/JavaScriptEngineTest.java 2017-03-19 20:27:24 UTC (rev 13830)
+++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/JavaScriptEngineTest.java 2017-03-19 21:38:57 UTC (rev 13831)
@@ -1466,4 +1466,19 @@
             t2.join();
         }
     }
+
+    /**
+     * Tests case where {@link JavaScriptEngine#registerWindowAndMaybeStartEventLoop(WebWindow)}
+     * is being called after {@link JavaScriptEngine#shutdown()}.
+     */
+    @Test
+    public void useAfterShutdownShouldNotCreateThreads() {
+        @SuppressWarnings("resource")
+        final WebClient webClient = getWebClient();
+        final WebWindow window = webClient.getCurrentWindow();
+        final JavaScriptEngine engine = webClient.getJavaScriptEngine();
+        webClient.close();
+        engine.registerWindowAndMaybeStartEventLoop(window);
+        assertTrue(getJavaScriptThreads().isEmpty());
+    }
 }


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
HtmlUnit-develop mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/htmlunit-develop
Loading...