|
1 // Any copyright is dedicated to the Public Domain. |
|
2 // http://creativecommons.org/licenses/publicdomain/ |
|
3 |
|
4 var gTestfile = 'stringify-replacer-with-array-indexes.js'; |
|
5 //----------------------------------------------------------------------------- |
|
6 var BUGNUMBER = 584909; |
|
7 var summary = |
|
8 "Call the replacer function for array elements with stringified indexes"; |
|
9 |
|
10 print(BUGNUMBER + ": " + summary); |
|
11 |
|
12 /************** |
|
13 * BEGIN TEST * |
|
14 **************/ |
|
15 |
|
16 var arr = [0, 1, 2, 3, 4]; |
|
17 |
|
18 var seenTopmost = false; |
|
19 var index = 0; |
|
20 function replacer() |
|
21 { |
|
22 assertEq(arguments.length, 2); |
|
23 |
|
24 var key = arguments[0], value = arguments[1]; |
|
25 |
|
26 // Topmost array: ignore replacer call. |
|
27 if (key === "") |
|
28 { |
|
29 assertEq(seenTopmost, false); |
|
30 seenTopmost = true; |
|
31 return value; |
|
32 } |
|
33 |
|
34 assertEq(seenTopmost, true); |
|
35 |
|
36 assertEq(typeof key, "string"); |
|
37 assertEq(key === index, false); |
|
38 assertEq(key === index + "", true); |
|
39 |
|
40 assertEq(value, index); |
|
41 |
|
42 index++; |
|
43 |
|
44 assertEq(this, arr); |
|
45 |
|
46 return value; |
|
47 } |
|
48 |
|
49 assertEq(JSON.stringify(arr, replacer), '[0,1,2,3,4]'); |
|
50 |
|
51 /******************************************************************************/ |
|
52 |
|
53 if (typeof reportCompare === "function") |
|
54 reportCompare(true, true); |
|
55 |
|
56 print("Tests complete"); |