summaryrefslogtreecommitdiffstats
path: root/js/src/tests/non262/JSON/parse-reviver-array-delete.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
commit6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch)
treea68f146d7fa01f0134297619fbe7e33db084e0aa /js/src/tests/non262/JSON/parse-reviver-array-delete.js
parentInitial commit. (diff)
downloadthunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.tar.xz
thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.zip
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/tests/non262/JSON/parse-reviver-array-delete.js')
-rw-r--r--js/src/tests/non262/JSON/parse-reviver-array-delete.js89
1 files changed, 89 insertions, 0 deletions
diff --git a/js/src/tests/non262/JSON/parse-reviver-array-delete.js b/js/src/tests/non262/JSON/parse-reviver-array-delete.js
new file mode 100644
index 0000000000..c343058785
--- /dev/null
+++ b/js/src/tests/non262/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");