|
1 // Any copyright is dedicated to the Public Domain. |
|
2 // http://creativecommons.org/licenses/publicdomain/ |
|
3 |
|
4 var gTestfile = 'stringify-replacer-array-edgecase-jsid-elements.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 /* JSID_INT_MIN/MAX copied from jsapi.h. */ |
|
18 |
|
19 var obj = |
|
20 { |
|
21 /* [JSID_INT_MIN - 1, JSID_INT_MIN + 1] */ |
|
22 "-1073741825": -1073741825, |
|
23 "-1073741824": -1073741824, |
|
24 "-1073741823": -1073741823, |
|
25 |
|
26 "-2.5": -2.5, |
|
27 "-1": -1, |
|
28 |
|
29 0: 0, |
|
30 |
|
31 1: 1, |
|
32 2.5: 2.5, |
|
33 |
|
34 /* [JSID_INT_MAX - 1, JSID_INT_MAX + 1] */ |
|
35 1073741822: 1073741822, |
|
36 1073741823: 1073741823, |
|
37 1073741824: 1073741824, |
|
38 }; |
|
39 |
|
40 for (var s in obj) |
|
41 { |
|
42 var n = obj[s]; |
|
43 assertEq(+s, n); |
|
44 assertEq(JSON.stringify(obj, [n]), |
|
45 '{"' + s + '":' + n + '}', |
|
46 "Failed to stringify numeric property " + n + "correctly"); |
|
47 assertEq(JSON.stringify(obj, [s]), |
|
48 '{"' + s + '":' + n + '}', |
|
49 "Failed to stringify string property " + n + "correctly"); |
|
50 assertEq(JSON.stringify(obj, [s, ]), |
|
51 '{"' + s + '":' + n + '}', |
|
52 "Failed to stringify string then number properties ('" + s + "', " + n + ") correctly"); |
|
53 assertEq(JSON.stringify(obj, [n, s]), |
|
54 '{"' + s + '":' + n + '}', |
|
55 "Failed to stringify number then string properties (" + n + ", '" + s + "') correctly"); |
|
56 } |
|
57 |
|
58 // -0 is tricky, because ToString(-0) === "0", so test it specially. |
|
59 assertEq(JSON.stringify({ "-0": 17, 0: 42 }, [-0]), |
|
60 '{"0":42}', |
|
61 "Failed to stringify numeric property -0 correctly"); |
|
62 assertEq(JSON.stringify({ "-0": 17, 0: 42 }, ["-0"]), |
|
63 '{"-0":17}', |
|
64 "Failed to stringify string property -0 correctly"); |
|
65 assertEq(JSON.stringify({ "-0": 17, 0: 42 }, ["-0", -0]), |
|
66 '{"-0":17,"0":42}', |
|
67 "Failed to stringify string then number properties ('-0', -0) correctly"); |
|
68 assertEq(JSON.stringify({ "-0": 17, 0: 42 }, [-0, "-0"]), |
|
69 '{"0":42,"-0":17}', |
|
70 "Failed to stringify number then string properties (-0, '-0) correctly"); |
|
71 |
|
72 /******************************************************************************/ |
|
73 |
|
74 if (typeof reportCompare === "function") |
|
75 reportCompare(true, true); |
|
76 |
|
77 print("Tests complete"); |