|
23 | 23 | import org.apache.commons.logging.LogFactory; |
24 | 24 | import org.htmlunit.FailingHttpStatusCodeException; |
25 | 25 | import org.htmlunit.SgmlPage; |
| 26 | +import org.htmlunit.WebClient; |
26 | 27 | import org.htmlunit.WebWindow; |
27 | 28 | import org.htmlunit.html.HtmlPage.JavaScriptLoadResult; |
28 | 29 | import org.htmlunit.javascript.AbstractJavaScriptEngine; |
@@ -73,7 +74,8 @@ public static void onAllChildrenAddedToPage(final ScriptElement script, final bo |
73 | 74 | LOG.debug("Script node added: " + element.asXml()); |
74 | 75 | } |
75 | 76 |
|
76 | | - if (!element.getPage().getWebClient().isJavaScriptEngineEnabled()) { |
| 77 | + final WebClient webClient = element.getPage().getWebClient(); |
| 78 | + if (!webClient.isJavaScriptEngineEnabled()) { |
77 | 79 | LOG.debug("Script found but not executed because javascript engine is disabled"); |
78 | 80 | return; |
79 | 81 | } |
@@ -116,23 +118,19 @@ public void execute() { |
116 | 118 | } |
117 | 119 | }; |
118 | 120 |
|
119 | | - final AbstractJavaScriptEngine<?> engine = element.getPage().getWebClient().getJavaScriptEngine(); |
120 | | - if (engine != null |
121 | | - && element.hasAttribute("async") && !engine.isScriptRunning()) { |
| 121 | + final AbstractJavaScriptEngine<?> engine = webClient.getJavaScriptEngine(); |
| 122 | + if (element.hasAttribute("async") && !engine.isScriptRunning()) { |
122 | 123 | final HtmlPage owningPage = element.getHtmlPageOrNull(); |
123 | 124 | owningPage.addAfterLoadAction(action); |
124 | 125 | } |
125 | | - else if (engine != null |
126 | | - && (element.hasAttribute("async") |
127 | | - || postponed && StringUtils.isBlank(element.getTextContent()))) { |
| 126 | + else if (element.hasAttribute("async") |
| 127 | + || postponed && StringUtils.isBlank(element.getTextContent())) { |
128 | 128 | engine.addPostponedAction(action); |
129 | 129 | } |
130 | 130 | else { |
131 | 131 | try { |
132 | 132 | action.execute(); |
133 | | - if (engine != null) { |
134 | | - engine.processPostponedActions(); |
135 | | - } |
| 133 | + engine.processPostponedActions(); |
136 | 134 | } |
137 | 135 | catch (final RuntimeException e) { |
138 | 136 | throw e; |
|
0 commit comments