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