From: <asa...@us...> - 2017-01-26 17:10:53
|
Revision: 13429 http://sourceforge.net/p/htmlunit/code/13429 Author: asashour Date: 2017-01-26 17:10:50 +0000 (Thu, 26 Jan 2017) Log Message: ----------- JavaScript: fix Symbol creation. Issue 1852 Modified Paths: -------------- trunk/htmlunit/src/changes/changes.xml trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Symbol.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/SymbolTest.java Modified: trunk/htmlunit/src/changes/changes.xml =================================================================== --- trunk/htmlunit/src/changes/changes.xml 2017-01-26 16:56:30 UTC (rev 13428) +++ trunk/htmlunit/src/changes/changes.xml 2017-01-26 17:10:50 UTC (rev 13429) @@ -8,6 +8,9 @@ <body> <release version="2.25" date="???" description="Java 8, InteractivePage and SvgPage removed, Bugfixes"> + <action type="fix" dev="asashour" issue="1852"> + JavaScript: fix Symbol creation. + </action> <action type="fix" dev="asashour"> HtmlOption: clicking should unselect other options, even if the parent select is 'multiple'. </action> Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Symbol.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Symbol.java 2017-01-26 16:56:30 UTC (rev 13428) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Symbol.java 2017-01-26 17:10:50 UTC (rev 13429) @@ -94,7 +94,8 @@ Symbol symbol = map.get(name); if (symbol == null) { - symbol = new Symbol(name); + symbol = new Symbol(); + symbol.name_ = name; symbol.setParentScope(scope); symbol.setPrototype(scope.getPrototype(symbol.getClass())); map.put(name, symbol); @@ -221,7 +222,8 @@ if (symbol == null) { final SimpleScriptable parentScope = (SimpleScriptable) thisObj.getParentScope(); - symbol = new Symbol(key); + symbol = new Symbol(); + symbol.name_ = key; symbol.setParentScope(parentScope); symbol.setPrototype(parentScope.getPrototype(symbol.getClass())); thisObj.put(key, thisObj, symbol); Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/SymbolTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/SymbolTest.java 2017-01-26 16:56:30 UTC (rev 13428) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/SymbolTest.java 2017-01-26 17:10:50 UTC (rev 13429) @@ -364,4 +364,25 @@ + "</body></html>"; loadPageWithAlerts2(html); } + + /** + * @throws Exception if an error occurs + */ + @Test + @Alerts(DEFAULT = "called", + IE = {}) + public void inFunction() throws Exception { + final String html = "<html><head><script>\n" + + "function test() {\n" + + " if (window.Symbol) {\n" + + " [].forEach.call('_', function(e) {\n" + + " var x = Symbol.toPrimitive;\n" + + " alert('called');\n" + + " });\n" + + " }\n" + + "}\n" + + "</script></head><body onload='test()'>\n" + + "</body></html>\n"; + loadPageWithAlerts2(html); + } } |