From: <mgu...@us...> - 2013-09-11 08:00:22
|
Revision: 8466 http://sourceforge.net/p/htmlunit/code/8466 Author: mguillem Date: 2013-09-11 08:00:18 +0000 (Wed, 11 Sep 2013) Log Message: ----------- JavaScript: fixed ClassCastException on TypedArray creation with start offset specified. (#1542) Modified Paths: -------------- trunk/htmlunit/src/changes/changes.xml trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/ArrayBufferViewBase.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/Int8ArrayTest.java Modified: trunk/htmlunit/src/changes/changes.xml =================================================================== --- trunk/htmlunit/src/changes/changes.xml 2013-09-08 17:45:52 UTC (rev 8465) +++ trunk/htmlunit/src/changes/changes.xml 2013-09-11 08:00:18 UTC (rev 8466) @@ -8,6 +8,9 @@ <body> <release version="2.13" date="???" description="Bugfixes"> + <action type="fix" dev="mguillem" issue="1542"> + JavaScript: fixed ClassCastException on TypedArray creation with start offset specified. + </action> <action type="add" dev="rbri" issue="1537"> Correct processing of the target window for anchors with hash-only href attribute. </action> Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/ArrayBufferViewBase.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/ArrayBufferViewBase.java 2013-09-08 17:45:52 UTC (rev 8465) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/ArrayBufferViewBase.java 2013-09-11 08:00:18 UTC (rev 8466) @@ -55,13 +55,17 @@ } else if (object instanceof ArrayBuffer) { final ArrayBuffer array = (ArrayBuffer) object; - if (byteOffset == Undefined.instance) { - byteOffset = 0; + + double dbByteOffset = Context.toNumber(byteOffset); + if (dbByteOffset != dbByteOffset) { // test if == NaN + dbByteOffset = 0; } - if (length == Undefined.instance) { - length = array.getByteLength(); + + double dbLength = Context.toNumber(length); + if (dbLength != dbLength) { // test if == NaN + dbLength = array.getByteLength(); } - super.constructor(array, (Integer) byteOffset, (Integer) length); + super.constructor(array, (int) dbByteOffset, (int) dbLength); } else { Context.reportRuntimeError("Invalid type " + object.getClass().getName()); Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/Int8ArrayTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/Int8ArrayTest.java 2013-09-08 17:45:52 UTC (rev 8465) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/Int8ArrayTest.java 2013-09-11 08:00:18 UTC (rev 8466) @@ -26,6 +26,7 @@ * * @version $Revision$ * @author Ahmed Ashour + * @author Marc Guillemot */ @RunWith(BrowserRunner.class) public class Int8ArrayTest extends WebDriverTestCase { @@ -82,6 +83,31 @@ * @throws Exception if the test fails */ @Test + @Alerts(IE = "exception", FF3_6 = "exception", DEFAULT = { "2", "-45", "52" }) + public void bufferConstructor() throws Exception { + final String html + = "<html><head><title>foo</title><script>\n" + + "function test() {\n" + + " try {\n" + + " var array = new Int8Array([17, -45.3, 52, 123]);\n" + + " var array2 = new Int8Array(array.buffer, 1, 2);\n" + + " alert(array2.length);\n" + + " for (var i = 0; i < array2.length; i++)\n" + + " alert(array2[i]);\n" + + " } catch(e) {\n" + + " alert('exception');\n" + + " }\n" + + "}\n" + + "</script></head><body onload='test()'>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if the test fails + */ + @Test @Alerts(IE = "exception", FF3_6 = "exception", DEFAULT = "1") public void constant() throws Exception { final String html |