From: <rb...@us...> - 2017-12-29 20:51:12
|
Revision: 15050 http://sourceforge.net/p/htmlunit/code/15050 Author: rbri Date: 2017-12-29 20:51:09 +0000 (Fri, 29 Dec 2017) Log Message: ----------- relax the cast a bit Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/ArrayCustom.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/NativeArrayTest.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/ArrayCustom.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/ArrayCustom.java 2017-12-28 16:44:40 UTC (rev 15049) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/ArrayCustom.java 2017-12-29 20:51:09 UTC (rev 15050) @@ -19,9 +19,9 @@ import com.gargoylesoftware.htmlunit.javascript.SimpleScriptable; +import net.sourceforge.htmlunit.corejs.javascript.BaseFunction; import net.sourceforge.htmlunit.corejs.javascript.Context; import net.sourceforge.htmlunit.corejs.javascript.Function; -import net.sourceforge.htmlunit.corejs.javascript.FunctionObject; import net.sourceforge.htmlunit.corejs.javascript.Scriptable; import net.sourceforge.htmlunit.corejs.javascript.Undefined; @@ -57,10 +57,11 @@ array[i] = scriptable.get(i, scriptable); } } + final Object iterator = scriptable.get(Symbol.ITERATOR_STRING, scriptable); if (iterator != Scriptable.NOT_FOUND) { final List<Object> list = new ArrayList<>(); - final Iterator it = (Iterator) ((FunctionObject) iterator) + final Iterator it = (Iterator) ((BaseFunction) iterator) .call(context, thisObj.getParentScope(), scriptable, new Object[0]); SimpleScriptable next = it.next(); boolean done = (boolean) next.get("done"); Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/NativeArrayTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/NativeArrayTest.java 2017-12-28 16:44:40 UTC (rev 15049) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/NativeArrayTest.java 2017-12-29 20:51:09 UTC (rev 15050) @@ -365,6 +365,69 @@ * @throws Exception if the test fails */ @Test + @Alerts(DEFAULT = {"3", "1", "two", "3"}, + IE = "not supported") + @NotYetImplemented + public void fromUserDefinedIterable() throws Exception { + final String html + = "<html>\n" + + "<head>\n" + + "<script>\n" + + " if (Array.from) {\n" + + " var myIterable = {};\n" + + " myIterable[Symbol.iterator] = function*() {\n" + + " yield 1;\n" + + " yield 'two';\n" + + " yield 3;\n" + + " };\n" + + " var arr = Array.from(myIterable);\n" + + " alert(arr.length);\n" + + " for (var i = 0; i < arr.length; i++) {\n" + + " alert(arr[i]);\n" + + " }\n" + + " } else {\n" + + " alert('not supported');\n" + + " }\n" + + "</script>\n" + + "</head>\n" + + "<body>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = "0", + IE = "not supported") + public void fromNativeObject() throws Exception { + final String html + = "<html>\n" + + "<head>\n" + + "<script>\n" + + " if (Array.from) {\n" + + " var arr = Array.from({firstName: 'Erika', age: 42});\n" + + " alert(arr.length);\n" + + " for (var i = 0; i < arr.length; i++) {\n" + + " alert(arr[i]);\n" + + " }\n" + + " } else {\n" + + " alert('not supported');\n" + + " }\n" + + "</script>\n" + + "</head>\n" + + "<body>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if the test fails + */ + @Test @Alerts({"true", "true", "true", "true", "false", "false", "false", "false", "false", "false", "false", "false", "false"}) public void isArray() throws Exception { |