summaryrefslogtreecommitdiffstats
path: root/js/src/tests/ecma_5/JSON/parse-reviver-array-delete.js
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /js/src/tests/ecma_5/JSON/parse-reviver-array-delete.js
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'js/src/tests/ecma_5/JSON/parse-reviver-array-delete.js')
-rw-r--r--js/src/tests/ecma_5/JSON/parse-reviver-array-delete.js89
1 files changed, 89 insertions, 0 deletions
diff --git a/js/src/tests/ecma_5/JSON/parse-reviver-array-delete.js b/js/src/tests/ecma_5/JSON/parse-reviver-array-delete.js
new file mode 100644
index 000000000..c34305878
--- /dev/null
+++ b/js/src/tests/ecma_5/JSON/parse-reviver-array-delete.js
@@ -0,0 +1,89 @@
+// Any copyright is dedicated to the Public Domain.
+// http://creativecommons.org/licenses/publicdomain/
+
+var gTestfile = 'parse-reviver-array-delete.js';
+//-----------------------------------------------------------------------------
+var BUGNUMBER = 999999;
+var summary = "JSON.parse with a reviver which elides array elements";
+
+print(BUGNUMBER + ": " + summary);
+
+/**************
+ * BEGIN TEST *
+ **************/
+
+/*
+ * The reviver deletes all properties from the to-be-returned array. Thus
+ * stringification reveals properties on the prototype chain -- but there are
+ * none, so this result is unsurprising.
+ */
+assertEq(JSON.parse('[1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0]',
+ function revive(k, v)
+ {
+ if (k === "")
+ return v;
+ return undefined;
+ }) + "",
+ ",,,,,,,,,,,,,,,,,,,");
+
+/*
+ * Now let's try a reviver that deletes every property but a mega-huge one.
+ */
+var str = "[";
+var expected = "";
+var expected2 = "";
+for (var i = 0; i < 2048; i++)
+{
+ str += "1,";
+ if (i === 2047)
+ {
+ expected += "1";
+ expected2 += "1";
+ }
+ if (i === 3)
+ expected2 += "17";
+ expected += ",";
+ expected2 += ",";
+}
+str += "1]";
+
+assertEq(JSON.parse(str,
+ function reviver(k, v)
+ {
+ if (k === "" || k === "2047")
+ return v;
+ return undefined;
+ }) + "",
+ expected);
+
+
+Array.prototype[3] = 17;
+
+/* Now, with a property on the prototype chain, it'll show through. */
+assertEq(JSON.parse('[1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0]',
+ function revive(k, v)
+ {
+ if (k === "")
+ return v;
+ return undefined;
+ }) + "",
+ ",,,17,,,,,,,,,,,,,,,,");
+
+
+/* And here too. */
+assertEq(JSON.parse(str,
+ function reviver(k, v)
+ {
+ if (k === "" || k === "2047")
+ return v;
+ return undefined;
+ }) + "",
+ expected2);
+
+
+/******************************************************************************/
+
+if (typeof reportCompare === "function")
+ reportCompare(true, true);
+
+print("Tests complete");