js/src/tests/ecma_5/JSON/stringify-replacer-array-hijinks.js

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

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 = 'stringify-replacer-array-hijinks.js';
michael@0 5 //-----------------------------------------------------------------------------
michael@0 6 var BUGNUMBER = 648471;
michael@0 7 var summary =
michael@0 8 "Better/more correct handling for replacer arrays with getter array index " +
michael@0 9 "properties";
michael@0 10
michael@0 11 print(BUGNUMBER + ": " + summary);
michael@0 12
michael@0 13 /**************
michael@0 14 * BEGIN TEST *
michael@0 15 **************/
michael@0 16
michael@0 17 var replacer = [0, 1, 2, 3];
michael@0 18 Object.prototype[3] = 3;
michael@0 19 Object.defineProperty(replacer, 1, {
michael@0 20 get: function()
michael@0 21 {
michael@0 22 Object.defineProperty(replacer, 4, { value: 4 });
michael@0 23 delete replacer[2];
michael@0 24 delete replacer[3];
michael@0 25 replacer[5] = 5;
michael@0 26 return 1;
michael@0 27 }
michael@0 28 });
michael@0 29
michael@0 30 var s =
michael@0 31 JSON.stringify({0: { 1: { 3: { 4: { 5: { 2: "omitted" } } } } } }, replacer);
michael@0 32
michael@0 33 // The replacer array's length is as seen on first query, so property names are
michael@0 34 // accumulated for indexes i ∈ {0, 1, 2, 3}, but index 1 deletes 2 and 3, so 2
michael@0 35 // isn't seen but 3 is seen as Object.prototype[3].
michael@0 36 assertEq('{"0":{"1":{"3":{"3":3}},"3":3},"3":3}', s);
michael@0 37
michael@0 38
michael@0 39 var replacer = [0, 1, 2, 3];
michael@0 40 Object.defineProperty(replacer, 0, {
michael@0 41 get: function()
michael@0 42 {
michael@0 43 replacer.length = 0;
michael@0 44 return {};
michael@0 45 }
michael@0 46 });
michael@0 47
michael@0 48 // The replacer.length truncation means only properties on the prototype chain
michael@0 49 // shine through, but it doesn't affect the original bounds of the iteration
michael@0 50 // used to determine property names which will be included in the final string.
michael@0 51 assertEq(JSON.stringify({ 0: 0, 1: 1, 2: 2, 3: 3 }, replacer),
michael@0 52 '{"3":3}');
michael@0 53
michael@0 54 /******************************************************************************/
michael@0 55
michael@0 56 if (typeof reportCompare === "function")
michael@0 57 reportCompare(true, true);
michael@0 58
michael@0 59 print("Tests complete");

mercurial