Bug 1133377 - Make DataView constructor correctly handle undefined byteLength argument r=sfink
authorJon Coppeard <jcoppeard@mozilla.com>
Mon, 02 Mar 2015 13:30:34 +0000
changeset 231313 dc1374ca30343ae64429ea0a114da5318102d633
parent 231312 5f0c649d2d47af7913c2aea1b3684e77ac1445e2
child 231314 4fe43cd0ac7defaf5e57ec1dd1287bbdcf653052
push id28348
push userkwierso@gmail.com
push dateMon, 02 Mar 2015 20:13:43 +0000
treeherdermozilla-central@abb7f0d180da [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssfink
bugs1133377
milestone39.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1133377 - Make DataView constructor correctly handle undefined byteLength argument r=sfink
js/src/jit-test/tests/basic/bug-1133377.js
js/src/vm/TypedArrayObject.cpp
new file mode 100644
--- /dev/null
+++ b/js/src/jit-test/tests/basic/bug-1133377.js
@@ -0,0 +1,11 @@
+var buffer = new ArrayBuffer(100);
+
+view = new DataView(buffer, undefined, undefined);
+assertEq(view.buffer, buffer);
+assertEq(view.byteOffset, 0);
+assertEq(view.byteLength, 100);
+
+view = new DataView(buffer, 20, undefined);
+assertEq(view.buffer, buffer);
+assertEq(view.byteOffset, 20);
+assertEq(view.byteLength, 80);
--- a/js/src/vm/TypedArrayObject.cpp
+++ b/js/src/vm/TypedArrayObject.cpp
@@ -1057,17 +1057,17 @@ DataViewObject::construct(JSContext *cx,
         if (!ToUint32(cx, args[1], &byteOffset))
             return false;
         if (byteOffset > INT32_MAX) {
             JS_ReportErrorNumber(cx, GetErrorMessage, nullptr,
                                  JSMSG_ARG_INDEX_OUT_OF_RANGE, "1");
             return false;
         }
 
-        if (args.length() > 2) {
+        if (!args.get(2).isUndefined()) {
             if (!ToUint32(cx, args[2], &byteLength))
                 return false;
             if (byteLength > INT32_MAX) {
                 JS_ReportErrorNumber(cx, GetErrorMessage, nullptr,
                                      JSMSG_ARG_INDEX_OUT_OF_RANGE, "2");
                 return false;
             }
         } else {