Bug 667527 - Remove the array-length limitation from the method used in certain cases to append values to newborn arrays. r=dmandelin, a=johnath
authorJeff Walden <jwalden@mit.edu>
Tue, 28 Jun 2011 13:33:30 -0700
changeset 70368 da6f57193888
parent 70367 f98d15cfa9a5
child 70370 130934a607ae
push id199
push userjwalden@mit.edu
push date2011-06-30 22:21 +0000
treeherdermozilla-aurora@da6f57193888 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdmandelin, johnath
bugs667527
milestone6.0a2
Bug 667527 - Remove the array-length limitation from the method used in certain cases to append values to newborn arrays. r=dmandelin, a=johnath
js/src/jsarray.cpp
js/src/tests/ecma_5/JSON/jstests.list
js/src/tests/ecma_5/JSON/parse-mega-huge-array.js
js/src/tests/js1_8_5/regress/jstests.list
js/src/tests/js1_8_5/regress/no-array-comprehension-length-limit.js
--- a/js/src/jsarray.cpp
+++ b/js/src/jsarray.cpp
@@ -2113,22 +2113,16 @@ ArrayCompPushImpl(JSContext *cx, JSObjec
         return IndexToId(cx, length, &id) &&
                js_DefineProperty(cx, obj, id, &v, NULL, NULL, JSPROP_ENUMERATE);
     }
 
     JS_ASSERT(obj->isDenseArray());
     JS_ASSERT(length <= obj->getDenseArrayCapacity());
 
     if (length == obj->getDenseArrayCapacity()) {
-        if (length > JS_ARGS_LENGTH_MAX) {
-            JS_ReportErrorNumberUC(cx, js_GetErrorMessage, NULL,
-                                   JSMSG_ARRAY_INIT_TOO_BIG);
-            return false;
-        }
-
         /*
          * An array comprehension cannot add holes to the array. So we can use
          * ensureSlots instead of ensureDenseArrayElements.
          */
         if (!obj->ensureSlots(cx, length + 1))
             return false;
     }
     obj->setArrayLength(length + 1);
--- a/js/src/tests/ecma_5/JSON/jstests.list
+++ b/js/src/tests/ecma_5/JSON/jstests.list
@@ -1,14 +1,15 @@
 url-prefix ../../jsreftest.html?test=ecma_5/JSON/
 script cyclic-stringify.js
 script small-codepoints.js
 script parse.js
 script parse-arguments.js
 script parse-crockford-01.js
+script parse-mega-huge-array.js
 script parse-number-syntax.js
 script parse-octal-syntax-error.js
 script parse-primitives.js
 script parse-reviver.js
 script parse-reviver-array-delete.js
 script parse-syntax-errors-01.js
 script parse-syntax-errors-02.js
 script parse-syntax-errors-03.js
new file mode 100644
--- /dev/null
+++ b/js/src/tests/ecma_5/JSON/parse-mega-huge-array.js
@@ -0,0 +1,28 @@
+// Any copyright is dedicated to the Public Domain.
+// http://creativecommons.org/licenses/publicdomain/
+
+var gTestfile = 'parse-mega-huge-array.js';
+//-----------------------------------------------------------------------------
+var BUGNUMBER = 667527;
+var summary = "JSON.parse should parse arrays of essentially unlimited size";
+
+print(BUGNUMBER + ": " + summary);
+
+/**************
+ * BEGIN TEST *
+ **************/
+
+var str = '[';
+for (var i = 0, sz = Math.pow(2, 21); i < sz; i++)
+  str += '0,';
+str += '0]';
+
+var arr = JSON.parse(str);
+assertEq(arr.length, Math.pow(2, 21) + 1);
+
+/******************************************************************************/
+
+if (typeof reportCompare === "function")
+  reportCompare(true, true);
+
+print("Tests complete");
--- a/js/src/tests/js1_8_5/regress/jstests.list
+++ b/js/src/tests/js1_8_5/regress/jstests.list
@@ -1,9 +1,10 @@
 url-prefix ../../jsreftest.html?test=js1_8_5/regress/
+script no-array-comprehension-length-limit.js
 script regress-500528.js
 script regress-533876.js
 script regress-541255-0.js
 script regress-541255-1.js
 script regress-541255-2.js
 script regress-541255-3.js
 script regress-541255-4.js
 script regress-541455.js
new file mode 100644
--- /dev/null
+++ b/js/src/tests/js1_8_5/regress/no-array-comprehension-length-limit.js
@@ -0,0 +1,14 @@
+/*
+ * Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/licenses/publicdomain/
+ */
+function range(n)
+{
+  var i = 0;
+  while (i < n)
+    yield i++;
+}
+
+[0 for (_ in range(Math.pow(2, 20)))];
+
+reportCompare(true, true);