From: <rb...@us...> - 2017-07-13 17:03:32
|
Revision: 14652 http://sourceforge.net/p/htmlunit/code/14652 Author: rbri Date: 2017-07-13 17:03:29 +0000 (Thu, 13 Jul 2017) Log Message: ----------- fix ClassCastException in Array.from. Modified Paths: -------------- trunk/htmlunit/src/changes/changes.xml 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/changes/changes.xml =================================================================== --- trunk/htmlunit/src/changes/changes.xml 2017-07-13 16:39:55 UTC (rev 14651) +++ trunk/htmlunit/src/changes/changes.xml 2017-07-13 17:03:29 UTC (rev 14652) @@ -8,6 +8,9 @@ <body> <release version="2.28" date="???" description="Bugfixes"> + <action type="fix" dev="rbri"> + JavaScript: fix ClassCastException in Array.from. + </action> <action type="add" dev="rbri" due-to="Anton Demydenko" issue="1884"> Support for form attributes formaction, formmethod, formtarget and formenctype added. </action> 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-07-13 16:39:55 UTC (rev 14651) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/ArrayCustom.java 2017-07-13 17:03:29 UTC (rev 14652) @@ -29,6 +29,7 @@ * Contains some missing features of Rhino NativeArray. * * @author Ahmed Ashour + * @author Ronald Brill */ public final class ArrayCustom { @@ -50,7 +51,7 @@ final Scriptable scriptable = (Scriptable) arrayLike; final Object length = scriptable.get("length", scriptable); if (length != Scriptable.NOT_FOUND) { - final int size = (int) length; + final int size = (int) Context.toNumber(length); array = new Object[(int) size]; for (int i = 0; i < size; i++) { array[i] = scriptable.get(i, scriptable); Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/NativeArrayTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/NativeArrayTest.java 2017-07-13 16:39:55 UTC (rev 14651) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/NativeArrayTest.java 2017-07-13 17:03:29 UTC (rev 14652) @@ -36,6 +36,7 @@ * @author Marc Guillemot * @author Frank Danek * @author Ahmed Ashour + * @author Ronald Brill */ @RunWith(BrowserRunner.class) public class NativeArrayTest extends WebDriverTestCase { @@ -274,7 +275,7 @@ @Test @Alerts(DEFAULT = {"3", "a", "b", "c"}, IE = "not supported") - public void from() throws Exception { + public void fromString() throws Exception { final String html = "<html>\n" + "<head>\n" @@ -300,6 +301,34 @@ * @throws Exception if the test fails */ @Test + @Alerts(DEFAULT = {"3", "a", "b", "c"}, + IE = "not supported") + public void fromArray() throws Exception { + final String html + = "<html>\n" + + "<head>\n" + + "<script>\n" + + " if (Array.from) {\n" + + " var arr = Array.from(['a', 'b', 'c']);\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 = {"2", "abc", "[object Window]"}, IE = "not supported") public void fromSet() throws Exception { |