From 36d22d82aa202bb199967e9512281e9a53db42c9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 21:33:14 +0200 Subject: Adding upstream version 115.7.0esr. Signed-off-by: Daniel Baumann --- ...ingify-replacer-array-edgecase-jsid-elements.js | 77 ++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 js/src/tests/non262/JSON/stringify-replacer-array-edgecase-jsid-elements.js (limited to 'js/src/tests/non262/JSON/stringify-replacer-array-edgecase-jsid-elements.js') 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"); -- cgit v1.2.3