summaryrefslogtreecommitdiffstats
path: root/js/src/tests/non262/JSON/stringify-replacer-array-edgecase-jsid-elements.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
commit26a029d407be480d791972afb5975cf62c9360a6 (patch)
treef435a8308119effd964b339f76abb83a57c29483 /js/src/tests/non262/JSON/stringify-replacer-array-edgecase-jsid-elements.js
parentInitial commit. (diff)
downloadfirefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz
firefox-26a029d407be480d791972afb5975cf62c9360a6.zip
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/tests/non262/JSON/stringify-replacer-array-edgecase-jsid-elements.js')
-rw-r--r--js/src/tests/non262/JSON/stringify-replacer-array-edgecase-jsid-elements.js77
1 files changed, 77 insertions, 0 deletions
diff --git a/js/src/tests/non262/JSON/stringify-replacer-array-edgecase-jsid-elements.js b/js/src/tests/non262/JSON/stringify-replacer-array-edgecase-jsid-elements.js
new file mode 100644
index 0000000000..e7be4c6e11
--- /dev/null
+++ b/js/src/tests/non262/JSON/stringify-replacer-array-edgecase-jsid-elements.js
@@ -0,0 +1,77 @@
+// Any copyright is dedicated to the Public Domain.
+// http://creativecommons.org/licenses/publicdomain/
+
+var gTestfile = 'stringify-replacer-array-edgecase-jsid-elements.js';
+//-----------------------------------------------------------------------------
+var BUGNUMBER = 648471;
+var summary =
+ "Better/more correct handling for replacer arrays with getter array index " +
+ "properties";
+
+print(BUGNUMBER + ": " + summary);
+
+/**************
+ * BEGIN TEST *
+ **************/
+
+/* JSID_INT_MIN/MAX copied from jsapi.h. */
+
+var obj =
+ {
+ /* [JSID_INT_MIN - 1, JSID_INT_MIN + 1] */
+ "-1073741825": -1073741825,
+ "-1073741824": -1073741824,
+ "-1073741823": -1073741823,
+
+ "-2.5": -2.5,
+ "-1": -1,
+
+ 0: 0,
+
+ 1: 1,
+ 2.5: 2.5,
+
+ /* [JSID_INT_MAX - 1, JSID_INT_MAX + 1] */
+ 1073741822: 1073741822,
+ 1073741823: 1073741823,
+ 1073741824: 1073741824,
+ };
+
+for (var s in obj)
+{
+ var n = obj[s];
+ assertEq(+s, n);
+ assertEq(JSON.stringify(obj, [n]),
+ '{"' + s + '":' + n + '}',
+ "Failed to stringify numeric property " + n + "correctly");
+ assertEq(JSON.stringify(obj, [s]),
+ '{"' + s + '":' + n + '}',
+ "Failed to stringify string property " + n + "correctly");
+ assertEq(JSON.stringify(obj, [s, ]),
+ '{"' + s + '":' + n + '}',
+ "Failed to stringify string then number properties ('" + s + "', " + n + ") correctly");
+ assertEq(JSON.stringify(obj, [n, s]),
+ '{"' + s + '":' + n + '}',
+ "Failed to stringify number then string properties (" + n + ", '" + s + "') correctly");
+}
+
+// -0 is tricky, because ToString(-0) === "0", so test it specially.
+assertEq(JSON.stringify({ "-0": 17, 0: 42 }, [-0]),
+ '{"0":42}',
+ "Failed to stringify numeric property -0 correctly");
+assertEq(JSON.stringify({ "-0": 17, 0: 42 }, ["-0"]),
+ '{"-0":17}',
+ "Failed to stringify string property -0 correctly");
+assertEq(JSON.stringify({ "-0": 17, 0: 42 }, ["-0", -0]),
+ '{"-0":17,"0":42}',
+ "Failed to stringify string then number properties ('-0', -0) correctly");
+assertEq(JSON.stringify({ "-0": 17, 0: 42 }, [-0, "-0"]),
+ '{"0":42,"-0":17}',
+ "Failed to stringify number then string properties (-0, '-0) correctly");
+
+/******************************************************************************/
+
+if (typeof reportCompare === "function")
+ reportCompare(true, true);
+
+print("Tests complete");