|
20 | 20 | import com.google.gwt.thirdparty.guava.common.collect.ImmutableSet; |
21 | 21 | import com.google.gwt.thirdparty.guava.common.collect.Maps; |
22 | 22 |
|
23 | | -import org.apache.commons.logging.Log; |
24 | | -import org.apache.commons.logging.LogFactory; |
25 | 23 | import org.htmlunit.AlertHandler; |
26 | 24 | import org.htmlunit.BrowserVersion; |
27 | 25 | import org.htmlunit.FailingHttpStatusCodeException; |
|
31 | 29 | import org.htmlunit.ScriptException; |
32 | 30 | import org.htmlunit.WebClient; |
33 | 31 | import org.htmlunit.WebWindow; |
34 | | -import org.htmlunit.corejs.javascript.Context; |
35 | | -import org.htmlunit.corejs.javascript.Function; |
36 | | -import org.htmlunit.corejs.javascript.JavaScriptException; |
37 | 32 | import org.htmlunit.corejs.javascript.ScriptableObject; |
38 | 33 | import org.htmlunit.html.HtmlPage; |
39 | 34 | import org.htmlunit.javascript.JavaScriptEngine; |
@@ -177,7 +172,7 @@ protected void setupWebClient(WebClient webClient) { |
177 | 172 | treeLogger); |
178 | 173 | webClient.setJavaScriptEngine(hostedEngine); |
179 | 174 | } else { |
180 | | - JavaScriptEngine webEngine = new WebJavaScriptEngine(webClient); |
| 175 | + JavaScriptEngine webEngine = new JavaScriptEngine(webClient); |
181 | 176 | webClient.setJavaScriptEngine(webEngine); |
182 | 177 | } |
183 | 178 | if (System.getProperty("gwt.htmlunit.debug") != null) { |
@@ -207,85 +202,12 @@ private static class HostedJavaScriptEngine extends JavaScriptEngine { |
207 | 202 | public void initialize(WebWindow webWindow, Page page) { |
208 | 203 | // Hook in the hosted-mode plugin after initializing the JS engine. |
209 | 204 | super.initialize(webWindow, page); |
210 | | - Window window = (Window) webWindow.getScriptableObject(); |
| 205 | + Window window = webWindow.getScriptableObject(); |
211 | 206 | window.defineProperty("__gwt_HostedModePlugin", |
212 | 207 | new HostedModePluginObject(this, webClient, logger), ScriptableObject.READONLY); |
213 | 208 | } |
214 | 209 | } |
215 | 210 |
|
216 | | - /** |
217 | | - * JavaScriptEngine subclass that fixes a bug when calling {@code window.onerror}. |
218 | | - * Make sure to remove when updating HtmlUnit. |
219 | | - * |
220 | | - * @see <a href="https://sourceforge.net/p/htmlunit/bugs/1924/">HtmlUnit bug #1924</a> |
221 | | - */ |
222 | | - private static class WebJavaScriptEngine extends JavaScriptEngine { |
223 | | - private static final Log LOG = LogFactory.getLog(JavaScriptEngine.class); |
224 | | - private final WebClient webClient; |
225 | | - |
226 | | - WebJavaScriptEngine(WebClient webClient) { |
227 | | - super(webClient); |
228 | | - this.webClient = webClient; |
229 | | - } |
230 | | - |
231 | | - @Override |
232 | | - protected void handleJavaScriptException(ScriptException scriptException, |
233 | | - boolean triggerOnError) { |
234 | | - // XXX(tbroyer): copied from JavaScriptEngine to call below triggerOnError |
235 | | - // instead of Window's triggerOnError. |
236 | | - |
237 | | - // Trigger window.onerror, if it has been set. |
238 | | - final HtmlPage page = scriptException.getPage(); |
239 | | - if (triggerOnError && page != null) { |
240 | | - final WebWindow window = page.getEnclosingWindow(); |
241 | | - if (window != null) { |
242 | | - final Window w = (Window) window.getScriptableObject(); |
243 | | - if (w != null) { |
244 | | - try { |
245 | | - triggerOnError(w, scriptException); |
246 | | - } catch (final Exception e) { |
247 | | - handleJavaScriptException(new ScriptException(page, e, null), false); |
248 | | - } |
249 | | - } |
250 | | - } |
251 | | - } |
252 | | - final JavaScriptErrorListener javaScriptErrorListener = |
253 | | - webClient.getJavaScriptErrorListener(); |
254 | | - if (javaScriptErrorListener != null) { |
255 | | - javaScriptErrorListener.scriptException(page, scriptException); |
256 | | - } |
257 | | - // Throw a Java exception if the user wants us to. |
258 | | - if (webClient.getOptions().isThrowExceptionOnScriptError()) { |
259 | | - throw scriptException; |
260 | | - } |
261 | | - // Log the error; ScriptException instances provide good debug info. |
262 | | - LOG.info("Caught script exception", scriptException); |
263 | | - } |
264 | | - |
265 | | - private void triggerOnError(Window w, ScriptException e) { |
266 | | - // XXX(tbroyer): copied from HtmlUnit's javascript.host.Window |
267 | | - // with fix unwrapping the JS exception before passing it back to JS. |
268 | | - final Object o = w.getOnerror(); |
269 | | - if (o instanceof Function) { |
270 | | - final Function f = (Function) o; |
271 | | - final String msg = e.getMessage(); |
272 | | - final String url = e.getPage().getUrl().toExternalForm(); |
273 | | - final int line = e.getFailingLineNumber(); |
274 | | - |
275 | | - final int column = e.getFailingColumnNumber(); |
276 | | - |
277 | | - Object jsError = null; |
278 | | - if (e.getCause() instanceof JavaScriptException) { |
279 | | - jsError = ((JavaScriptException) e.getCause()).getValue(); |
280 | | - } |
281 | | - |
282 | | - Object[] args = new Object[]{msg, url, line, column, jsError}; |
283 | | - |
284 | | - f.call(Context.getCurrentContext(), w, w, args); |
285 | | - } |
286 | | - } |
287 | | - } |
288 | | - |
289 | 211 | private static final Map<String, BrowserVersion> BROWSER_MAP = Maps.newHashMap(); |
290 | 212 | private static final Map<BrowserVersion, String> USER_AGENT_MAP = Maps.newHashMap(); |
291 | 213 |
|
|
0 commit comments