js/src/tests/ecma_5/JSON/parse-reviver-array-delete.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 // Any copyright is dedicated to the Public Domain.
michael@0 2 // http://creativecommons.org/licenses/publicdomain/
michael@0 3
michael@0 4 var gTestfile = 'parse-reviver-array-delete.js';
michael@0 5 //-----------------------------------------------------------------------------
michael@0 6 var BUGNUMBER = 999999;
michael@0 7 var summary = "JSON.parse with a reviver which elides array elements";
michael@0 8
michael@0 9 print(BUGNUMBER + ": " + summary);
michael@0 10
michael@0 11 /**************
michael@0 12 * BEGIN TEST *
michael@0 13 **************/
michael@0 14
michael@0 15 /*
michael@0 16 * The reviver deletes all properties from the to-be-returned array. Thus
michael@0 17 * stringification reveals properties on the prototype chain -- but there are
michael@0 18 * none, so this result is unsurprising.
michael@0 19 */
michael@0 20 assertEq(JSON.parse('[1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0]',
michael@0 21 function revive(k, v)
michael@0 22 {
michael@0 23 if (k === "")
michael@0 24 return v;
michael@0 25 return undefined;
michael@0 26 }) + "",
michael@0 27 ",,,,,,,,,,,,,,,,,,,");
michael@0 28
michael@0 29 /*
michael@0 30 * Now let's try a reviver that deletes every property but a mega-huge one.
michael@0 31 */
michael@0 32 var str = "[";
michael@0 33 var expected = "";
michael@0 34 var expected2 = "";
michael@0 35 for (var i = 0; i < 2048; i++)
michael@0 36 {
michael@0 37 str += "1,";
michael@0 38 if (i === 2047)
michael@0 39 {
michael@0 40 expected += "1";
michael@0 41 expected2 += "1";
michael@0 42 }
michael@0 43 if (i === 3)
michael@0 44 expected2 += "17";
michael@0 45 expected += ",";
michael@0 46 expected2 += ",";
michael@0 47 }
michael@0 48 str += "1]";
michael@0 49
michael@0 50 assertEq(JSON.parse(str,
michael@0 51 function reviver(k, v)
michael@0 52 {
michael@0 53 if (k === "" || k === "2047")
michael@0 54 return v;
michael@0 55 return undefined;
michael@0 56 }) + "",
michael@0 57 expected);
michael@0 58
michael@0 59
michael@0 60 Array.prototype[3] = 17;
michael@0 61
michael@0 62 /* Now, with a property on the prototype chain, it'll show through. */
michael@0 63 assertEq(JSON.parse('[1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0]',
michael@0 64 function revive(k, v)
michael@0 65 {
michael@0 66 if (k === "")
michael@0 67 return v;
michael@0 68 return undefined;
michael@0 69 }) + "",
michael@0 70 ",,,17,,,,,,,,,,,,,,,,");
michael@0 71
michael@0 72
michael@0 73 /* And here too. */
michael@0 74 assertEq(JSON.parse(str,
michael@0 75 function reviver(k, v)
michael@0 76 {
michael@0 77 if (k === "" || k === "2047")
michael@0 78 return v;
michael@0 79 return undefined;
michael@0 80 }) + "",
michael@0 81 expected2);
michael@0 82
michael@0 83
michael@0 84 /******************************************************************************/
michael@0 85
michael@0 86 if (typeof reportCompare === "function")
michael@0 87 reportCompare(true, true);
michael@0 88
michael@0 89 print("Tests complete");

mercurial