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 --- .../non262/JSON/parse-reviver-array-delete.js | 89 ++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 js/src/tests/non262/JSON/parse-reviver-array-delete.js (limited to 'js/src/tests/non262/JSON/parse-reviver-array-delete.js') 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"); -- cgit v1.2.3