From: <rb...@us...> - 2018-03-17 17:41:18
|
Revision: 15170 http://sourceforge.net/p/htmlunit/code/15170 Author: rbri Date: 2018-03-17 17:41:07 +0000 (Sat, 17 Mar 2018) Log Message: ----------- setting the Map size property is now ignored (or throws a Type error in strict mode) Issue 1956 Modified Paths: -------------- trunk/htmlunit/src/changes/changes.xml trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Map.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleDeclaration.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/MapTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleDeclaration2Test.java Modified: trunk/htmlunit/src/changes/changes.xml =================================================================== --- trunk/htmlunit/src/changes/changes.xml 2018-03-15 16:42:58 UTC (rev 15169) +++ trunk/htmlunit/src/changes/changes.xml 2018-03-17 17:41:07 UTC (rev 15170) @@ -8,6 +8,12 @@ <body> <release version="2.30" date="xx, 2018" description="Bugfixes, URLSearchParams implemented, start adding support of user defined iterators, CHROME 64"> + <action type="fix" dev="rbri" issue="1956"> + Setting the Map size property is now ignored (or throws a Type error in strict mode). + </action> + <action type="fix" dev="rbri" issue="1956"> + Setting the CSSStyleDeclaration length property is now ignored (or throws a Type error in strict mode). + </action> <action type="add" dev="rbri"> Setters for window.innerWidth/Height and window.outerWidth/Height added. </action> Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Map.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Map.java 2018-03-15 16:42:58 UTC (rev 15169) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Map.java 2018-03-17 17:41:07 UTC (rev 15170) @@ -22,6 +22,8 @@ import java.util.LinkedHashMap; import com.gargoylesoftware.htmlunit.javascript.SimpleScriptable; +import com.gargoylesoftware.htmlunit.javascript.configuration.CanSetReadOnly; +import com.gargoylesoftware.htmlunit.javascript.configuration.CanSetReadOnlyStatus; import com.gargoylesoftware.htmlunit.javascript.configuration.JsxClass; import com.gargoylesoftware.htmlunit.javascript.configuration.JsxConstructor; import com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction; @@ -145,6 +147,7 @@ * @return the size */ @JsxGetter + @CanSetReadOnly(CanSetReadOnlyStatus.IGNORE) public int getSize() { return map_.size(); } Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleDeclaration.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleDeclaration.java 2018-03-15 16:42:58 UTC (rev 15169) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleDeclaration.java 2018-03-17 17:41:07 UTC (rev 15170) @@ -132,6 +132,8 @@ import com.gargoylesoftware.htmlunit.css.StyleElement; import com.gargoylesoftware.htmlunit.html.HtmlElement; import com.gargoylesoftware.htmlunit.javascript.SimpleScriptable; +import com.gargoylesoftware.htmlunit.javascript.configuration.CanSetReadOnly; +import com.gargoylesoftware.htmlunit.javascript.configuration.CanSetReadOnlyStatus; import com.gargoylesoftware.htmlunit.javascript.configuration.JsxClass; import com.gargoylesoftware.htmlunit.javascript.configuration.JsxConstructor; import com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction; @@ -1410,6 +1412,7 @@ * @return the {@code length} property */ @JsxGetter + @CanSetReadOnly(CanSetReadOnlyStatus.IGNORE) public int getLength() { return getStyleMap().size(); } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/MapTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/MapTest.java 2018-03-15 16:42:58 UTC (rev 15169) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/MapTest.java 2018-03-17 17:41:07 UTC (rev 15170) @@ -473,4 +473,55 @@ loadPageWithAlerts2(html); } + /** + * @throws Exception if the test fails + */ + @Test + @Alerts({"0", "0"}) + public void setSize() throws Exception { + final String html + = "<html>\n" + + "<head>\n" + + "<script>\n" + + "function test() {\n" + + " var map = new Map();\n" + + " try {\n" + + " alert(map.size);\n" + + " map.size = 100;\n" + + " alert(map.size);\n" + + " } catch(e) { alert(e); }\n" + + "}\n" + + "</script></head>\n" + + "<body onload='test()'>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts({"0", "Type error"}) + public void setSizeStrictMode() throws Exception { + final String html + = "<html>\n" + + "<head>\n" + + "<script>\n" + + "function test() {\n" + + " 'use strict';\n" + + " var map = new Map();\n" + + " try {\n" + + " alert(map.size);\n" + + " map.size = 100;\n" + + " alert(map.size);\n" + + " } catch(e) { alert('Type error'); }\n" + + "}\n" + + "</script></head>\n" + + "<body onload='test()'>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } + } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleDeclaration2Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleDeclaration2Test.java 2018-03-15 16:42:58 UTC (rev 15169) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleDeclaration2Test.java 2018-03-17 17:41:07 UTC (rev 15170) @@ -284,7 +284,7 @@ final String html = "<html>\n" - + "<head><title>Tester</title>\n" + + "<head>\n" + "<script>\n" + "function test() {\n" + " var style = document.getElementById('myDiv').style;\n" @@ -309,4 +309,55 @@ actual = StringUtils.replace(actual, "\r\n", "\n"); assertEquals(expected, actual); } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts({"0", "0"}) + public void setLength() throws Exception { + final String html + = "<html>\n" + + "<head>\n" + + "<script>\n" + + "function test() {\n" + + " var style = document.body.style;\n" + + " try {\n" + + " alert(style.length);\n" + + " style.length = 100;\n" + + " alert(style.length);\n" + + " } catch(e) { alert(e); }\n" + + "}\n" + + "</script></head>\n" + + "<body onload='test()'>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts({"0", "Type error"}) + public void setLengthStrictMode() throws Exception { + final String html + = "<html>\n" + + "<head>\n" + + "<script>\n" + + "function test() {\n" + + " 'use strict';\n" + + " var style = document.body.style;\n" + + " try {\n" + + " alert(style.length);\n" + + " style.length = 100;\n" + + " alert(style.length);\n" + + " } catch(e) { alert('Type error'); }\n" + + "}\n" + + "</script></head>\n" + + "<body onload='test()'>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } } |