From: <rb...@us...> - 2017-07-22 12:38:17
|
Revision: 14687 http://sourceforge.net/p/htmlunit/code/14687 Author: rbri Date: 2017-07-22 12:38:14 +0000 (Sat, 22 Jul 2017) Log Message: ----------- add some more try/catch blocks to ignore the problem in IE also, add test that shows the problem Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/JavaScriptEngine.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlInlineFrame2Test.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-07-22 07:53:10 UTC (rev 14686) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/JavaScriptEngine.java 2017-07-22 12:38:14 UTC (rev 14687) @@ -415,7 +415,18 @@ final Method jsConstructor = ActiveXObject.class.getDeclaredMethod("jsConstructor", Context.class, Object[].class, Function.class, boolean.class); final FunctionObject functionObject = new HiddenFunctionObject("ActiveXObject", jsConstructor, window); - functionObject.addAsConstructor(window, prototype); + try { + functionObject.addAsConstructor(window, prototype); + } + catch (final Exception e) { + // TODO see issue #1897 + if (LOG.isWarnEnabled()) { + final String newline = System.lineSeparator(); + LOG.warn("Error during JavaScriptEngine.init(WebWindow, Context)" + newline + + e.getMessage() + newline + + "prototype: " + prototype.getClassName()); + } + } } } @@ -484,10 +495,34 @@ private static void defineConstructor(final Window window, final Scriptable prototype, final ScriptableObject constructor) { constructor.setParentScope(window); - ScriptableObject.defineProperty(prototype, "constructor", constructor, - ScriptableObject.DONTENUM | ScriptableObject.PERMANENT | ScriptableObject.READONLY); - ScriptableObject.defineProperty(constructor, "prototype", prototype, - ScriptableObject.DONTENUM | ScriptableObject.PERMANENT | ScriptableObject.READONLY); + try { + ScriptableObject.defineProperty(prototype, "constructor", constructor, + ScriptableObject.DONTENUM | ScriptableObject.PERMANENT | ScriptableObject.READONLY); + } + catch (final Exception e) { + // TODO see issue #1897 + if (LOG.isWarnEnabled()) { + final String newline = System.lineSeparator(); + LOG.warn("Error during JavaScriptEngine.init(WebWindow, Context)" + newline + + e.getMessage() + newline + + "prototype: " + prototype.getClassName()); + } + } + + try { + ScriptableObject.defineProperty(constructor, "prototype", prototype, + ScriptableObject.DONTENUM | ScriptableObject.PERMANENT | ScriptableObject.READONLY); + } + catch (final Exception e) { + // TODO see issue #1897 + if (LOG.isWarnEnabled()) { + final String newline = System.lineSeparator(); + LOG.warn("Error during JavaScriptEngine.init(WebWindow, Context)" + newline + + e.getMessage() + newline + + "prototype: " + prototype.getClassName()); + } + } + window.defineProperty(constructor.getClassName(), constructor, ScriptableObject.DONTENUM); } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlInlineFrame2Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlInlineFrame2Test.java 2017-07-22 07:53:10 UTC (rev 14686) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlInlineFrame2Test.java 2017-07-22 12:38:14 UTC (rev 14687) @@ -230,4 +230,29 @@ assertEquals(getExpectedAlerts(), getCollectedAlerts(driver)); } + + /** + * See issue #1897. + * In the end the strict mode should not be used for the setup of + * the new window. + * + * @throws Exception if the test fails + */ + @Test + @Alerts("IFRAME") + public void createIframeFromStrictFunction() throws Exception { + final String html = "<html><head>\n" + + "<script>\n" + + " function test() {\n" + + " 'use strict';\n" + + " var iFrame = document.createElement('iframe');\n" + + " alert(iFrame.tagName);\n" + + " }\n" + + "</script>\n" + + "</head>\n" + + "<body onload='test()'>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } } |