From: <rb...@us...> - 2018-05-18 12:04:09
|
Revision: 15273 http://sourceforge.net/p/htmlunit/code/15273 Author: rbri Date: 2018-05-18 12:04:03 +0000 (Fri, 18 May 2018) Log Message: ----------- Set constructor now supports parameters of type iterator also Modified Paths: -------------- trunk/htmlunit/src/changes/changes.xml trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Iterator.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/SetTest.java Modified: trunk/htmlunit/src/changes/changes.xml =================================================================== --- trunk/htmlunit/src/changes/changes.xml 2018-05-18 12:02:37 UTC (rev 15272) +++ trunk/htmlunit/src/changes/changes.xml 2018-05-18 12:04:03 UTC (rev 15273) @@ -8,6 +8,9 @@ <body> <release version="2.31" date="xx, 2018" description="Bugfixes, FIREFOX_45 is deprecated, special GAE handlings removed"> + <action type="fix" dev="rbri"> + Set constructor now supports parameters of type iterator also. + </action> <action type="add" dev="rbri"> document.fonts added. </action> Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Iterator.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Iterator.java 2018-05-18 12:02:37 UTC (rev 15272) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Iterator.java 2018-05-18 12:04:03 UTC (rev 15273) @@ -34,6 +34,7 @@ * A JavaScript object for {@code Iterator}. * * @author Ahmed Ashour + * @author Ronald Brill */ public class Iterator extends SimpleScriptable { @@ -115,6 +116,22 @@ final Scriptable thisObj, final Scriptable scriptable, final Consumer<Object> processor) { + + if (scriptable instanceof ES6Iterator) { + ScriptableObject next = (ScriptableObject) ScriptableObject.callMethod(scriptable, "next", null); + boolean done = (boolean) next.get(ES6Iterator.DONE_PROPERTY); + Object value = next.get(ES6Iterator.VALUE_PROPERTY); + + while (!done) { + processor.accept(value); + + next = (ScriptableObject) ScriptableObject.callMethod(scriptable, "next", null); + done = (boolean) next.get(ES6Iterator.DONE_PROPERTY); + value = next.get(ES6Iterator.VALUE_PROPERTY); + } + return true; + } + if (!(scriptable instanceof SymbolScriptable)) { return false; } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/SetTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/SetTest.java 2018-05-18 12:02:37 UTC (rev 15272) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/SetTest.java 2018-05-18 12:04:03 UTC (rev 15273) @@ -198,6 +198,28 @@ * @throws Exception if the test fails */ @Test + @Alerts(DEFAULT = {"7", "true", "false"}, + IE = {"0", "false", "false"}) + public void constructorStringIteratorParam() throws Exception { + final String html + = "<html><head><title>foo</title><script>\n" + + "function test() {\n" + + " var strIter = 'HtmlUnit'[Symbol.iterator]();" + + " var mySet = new Set(strIter);\n" + + " alert(mySet.size);\n" + + " alert(mySet.has('t'));\n" + + " alert(mySet.has('x'));\n" + + "}\n" + + "</script></head><body onload='test()'>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if the test fails + */ + @Test @Alerts(DEFAULT = {"3", "true", "false"}, IE = {"0", "false", "false"}) public void constructorSetParam() throws Exception { |