OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
2 // Copyright (C) 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. | 2 // Copyright (C) 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. |
3 // | 3 // |
4 // Redistribution and use in source and binary forms, with or without | 4 // Redistribution and use in source and binary forms, with or without |
5 // modification, are permitted provided that the following conditions | 5 // modification, are permitted provided that the following conditions |
6 // are met: | 6 // are met: |
7 // 1. Redistributions of source code must retain the above copyright | 7 // 1. Redistributions of source code must retain the above copyright |
8 // notice, this list of conditions and the following disclaimer. | 8 // notice, this list of conditions and the following disclaimer. |
9 // 2. Redistributions in binary form must reproduce the above copyright | 9 // 2. Redistributions in binary form must reproduce the above copyright |
10 // notice, this list of conditions and the following disclaimer in the | 10 // notice, this list of conditions and the following disclaimer in the |
(...skipping 23 matching lines...) Expand all Loading... |
34 complexArrayWithProto.__proto__ = simpleObjectWithProto; | 34 complexArrayWithProto.__proto__ = simpleObjectWithProto; |
35 var complexObjectWithProto = {d:"4", e:"5", f:"6", g:undefined, h:null, "":1
2, get i(){ return simpleArrayWithProto; }, array2: complexArrayWithProto, __pro
to__:complexObject}; | 35 var complexObjectWithProto = {d:"4", e:"5", f:"6", g:undefined, h:null, "":1
2, get i(){ return simpleArrayWithProto; }, array2: complexArrayWithProto, __pro
to__:complexObject}; |
36 var objectWithSideEffectGetter = {get b() {this.foo=1;}}; | 36 var objectWithSideEffectGetter = {get b() {this.foo=1;}}; |
37 var objectWithSideEffectGetterAndProto = {__proto__:{foo:"bar"}, get b() {th
is.foo=1;}}; | 37 var objectWithSideEffectGetterAndProto = {__proto__:{foo:"bar"}, get b() {th
is.foo=1;}}; |
38 var arrayWithSideEffectGetter = []; | 38 var arrayWithSideEffectGetter = []; |
39 arrayWithSideEffectGetter.__defineGetter__("b", function(){this.foo=1;}); | 39 arrayWithSideEffectGetter.__defineGetter__("b", function(){this.foo=1;}); |
40 var arrayWithSideEffectGetterAndProto = []; | 40 var arrayWithSideEffectGetterAndProto = []; |
41 arrayWithSideEffectGetterAndProto.__defineGetter__("b", function(){this.foo=
1;}); | 41 arrayWithSideEffectGetterAndProto.__defineGetter__("b", function(){this.foo=
1;}); |
42 arrayWithSideEffectGetterAndProto.__proto__ = {foo:"bar"}; | 42 arrayWithSideEffectGetterAndProto.__proto__ = {foo:"bar"}; |
43 var result = []; | 43 var result = []; |
44 result.push(function(jsonObject){ | 44 result.push(function (jsonObject){ |
45 return jsonObject.stringify(1); | 45 return jsonObject.stringify(1); |
46 }); | 46 }); |
47 result.push(function(jsonObject){ | 47 result.push(function (jsonObject){ |
48 return jsonObject.stringify(1.5); | 48 return jsonObject.stringify(1.5); |
49 }); | 49 }); |
50 result.push(function(jsonObject){ | 50 result.push(function (jsonObject){ |
51 return jsonObject.stringify(-1); | 51 return jsonObject.stringify(-1); |
52 }); | 52 }); |
53 result.push(function(jsonObject){ | 53 result.push(function (jsonObject){ |
54 return jsonObject.stringify(-1.5); | 54 return jsonObject.stringify(-1.5); |
55 }); | 55 }); |
56 result.push(function(jsonObject){ | 56 result.push(function (jsonObject){ |
57 return jsonObject.stringify(null); | 57 return jsonObject.stringify(null); |
58 }); | 58 }); |
59 result.push(function(jsonObject){ | 59 result.push(function (jsonObject){ |
60 return jsonObject.stringify("string"); | 60 return jsonObject.stringify("string"); |
61 }); | 61 }); |
62 result.push(function(jsonObject){ | 62 result.push(function (jsonObject){ |
63 return jsonObject.stringify(new Number(0)); | 63 return jsonObject.stringify(new Number(0)); |
64 }); | 64 }); |
65 result.push(function(jsonObject){ | 65 result.push(function (jsonObject){ |
66 return jsonObject.stringify(new Number(1)); | 66 return jsonObject.stringify(new Number(1)); |
67 }); | 67 }); |
68 result.push(function(jsonObject){ | 68 result.push(function (jsonObject){ |
69 return jsonObject.stringify(new Number(1.5)); | 69 return jsonObject.stringify(new Number(1.5)); |
70 }); | 70 }); |
71 result.push(function(jsonObject){ | 71 result.push(function (jsonObject){ |
72 return jsonObject.stringify(new Number(-1)); | 72 return jsonObject.stringify(new Number(-1)); |
73 }); | 73 }); |
74 result.push(function(jsonObject){ | 74 result.push(function (jsonObject){ |
75 return jsonObject.stringify(new Number(-1.5)); | 75 return jsonObject.stringify(new Number(-1.5)); |
76 }); | 76 }); |
77 result.push(function(jsonObject){ | 77 result.push(function (jsonObject){ |
78 return jsonObject.stringify(new String("a string object")); | 78 return jsonObject.stringify(new String("a string object")); |
79 }); | 79 }); |
80 result.push(function(jsonObject){ | 80 result.push(function (jsonObject){ |
81 return jsonObject.stringify(new Boolean(true)); | 81 return jsonObject.stringify(new Boolean(true)); |
82 }); | 82 }); |
83 result.push(function(jsonObject){ | 83 result.push(function (jsonObject){ |
84 var value = new Number(1); | 84 var value = new Number(1); |
85 value.valueOf = function() { return 2; } | 85 value.valueOf = function() { return 2; } |
86 return jsonObject.stringify(value); | 86 return jsonObject.stringify(value); |
87 }); | 87 }); |
88 result[result.length - 1].expected = '2'; | 88 result[result.length - 1].expected = '2'; |
89 result.push(function(jsonObject){ | 89 result.push(function (jsonObject){ |
90 var value = new Boolean(true); | 90 var value = new Boolean(true); |
91 value.valueOf = function() { return 2; } | 91 value.valueOf = function() { return 2; } |
92 return jsonObject.stringify(value); | 92 return jsonObject.stringify(value); |
93 }); | 93 }); |
94 result[result.length - 1].expected = '2'; | 94 result[result.length - 1].expected = '2'; |
95 result.push(function(jsonObject){ | 95 result.push(function (jsonObject){ |
96 var value = new String("fail"); | 96 var value = new String("fail"); |
97 value.toString = function() { return "converted string"; } | 97 value.toString = function() { return "converted string"; } |
98 return jsonObject.stringify(value); | 98 return jsonObject.stringify(value); |
99 }); | 99 }); |
100 result[result.length - 1].expected = '"converted string"'; | 100 result[result.length - 1].expected = '"converted string"'; |
101 result.push(function(jsonObject){ | 101 result.push(function (jsonObject){ |
102 return jsonObject.stringify(true); | 102 return jsonObject.stringify(true); |
103 }); | 103 }); |
104 result.push(function(jsonObject){ | 104 result.push(function (jsonObject){ |
105 return jsonObject.stringify(false); | 105 return jsonObject.stringify(false); |
106 }); | 106 }); |
107 result.push(function(jsonObject){ | 107 result.push(function (jsonObject){ |
108 return jsonObject.stringify(new Date(0)); | 108 return jsonObject.stringify(new Date(0)); |
109 }); | 109 }); |
110 result.push(function(jsonObject){ | 110 result.push(function (jsonObject){ |
111 return jsonObject.stringify({toJSON: Date.prototype.toJSON}); | 111 return jsonObject.stringify({toJSON: Date.prototype.toJSON}); |
112 }); | 112 }); |
113 result[result.length - 1].throws = true; | 113 result[result.length - 1].throws = true; |
114 result.push(function(jsonObject){ | 114 result.push(function (jsonObject){ |
115 return jsonObject.stringify({toJSON: Date.prototype.toJSON, toISOString:
function(){ return "custom toISOString"; }}); | 115 return jsonObject.stringify({toJSON: Date.prototype.toJSON, toISOString:
function(){ return "custom toISOString"; }}); |
116 }); | 116 }); |
117 result.push(function(jsonObject){ | 117 result.push(function (jsonObject){ |
118 return jsonObject.stringify({toJSON: Date.prototype.toJSON, toISOString:
function(){ return {}; }}); | 118 return jsonObject.stringify({toJSON: Date.prototype.toJSON, toISOString:
function(){ return {}; }}); |
119 }); | 119 }); |
120 result[result.length - 1].throws = true; | 120 result[result.length - 1].throws = true; |
121 result.push(function(jsonObject){ | 121 result.push(function (jsonObject){ |
122 return jsonObject.stringify({toJSON: Date.prototype.toJSON, toISOString:
function(){ throw "An exception"; }}); | 122 return jsonObject.stringify({toJSON: Date.prototype.toJSON, toISOString:
function(){ throw "An exception"; }}); |
123 }); | 123 }); |
124 result[result.length - 1].throws = true; | 124 result[result.length - 1].throws = true; |
125 result.push(function(jsonObject){ | 125 result.push(function (jsonObject){ |
126 var d = new Date(0); | 126 var d = new Date(0); |
127 d.toISOString = null; | 127 d.toISOString = null; |
128 return jsonObject.stringify(d); | 128 return jsonObject.stringify(d); |
129 }); | 129 }); |
130 result[result.length - 1].throws = true; | 130 result[result.length - 1].throws = true; |
131 result.push(function(jsonObject){ | 131 result.push(function (jsonObject){ |
132 var d = new Date(0); | 132 var d = new Date(0); |
133 d.toJSON = undefined; | 133 d.toJSON = undefined; |
134 return jsonObject.stringify(d); | 134 return jsonObject.stringify(d); |
135 }); | 135 }); |
136 result.push(function(jsonObject){ | 136 result.push(function (jsonObject){ |
137 return jsonObject.stringify({get Foo() { return "bar"; }}); | 137 return jsonObject.stringify({get Foo() { return "bar"; }}); |
138 }); | 138 }); |
139 result.push(function(jsonObject){ | 139 result.push(function (jsonObject){ |
140 return jsonObject.stringify({get Foo() { this.foo="wibble"; return "bar"
; }}); | 140 return jsonObject.stringify({get Foo() { this.foo="wibble"; return "bar"
; }}); |
141 }); | 141 }); |
142 result.push(function(jsonObject){ | 142 result.push(function (jsonObject){ |
143 var count = 0; | 143 var count = 0; |
144 jsonObject.stringify({get Foo() { count++; return "bar"; }}); | 144 jsonObject.stringify({get Foo() { count++; return "bar"; }}); |
145 return count; | 145 return count; |
146 }); | 146 }); |
147 result.push(function(jsonObject){ | 147 result.push(function (jsonObject){ |
148 var count = 0; | 148 var count = 0; |
149 return jsonObject.stringify({get Foo() { count++; delete this.bar; retur
n "bar"; }, bar: "wibble"}); | 149 return jsonObject.stringify({get Foo() { count++; delete this.bar; retur
n "bar"; }, bar: "wibble"}); |
150 }); | 150 }); |
151 result.push(function(jsonObject){ | 151 result.push(function (jsonObject){ |
152 var count = 0; | 152 var count = 0; |
153 return jsonObject.stringify({a:"1", b:"2", c:"3", 5:4, 4:5, 2:6, 1:7}); | 153 return jsonObject.stringify({a:"1", b:"2", c:"3", 5:4, 4:5, 2:6, 1:7}); |
154 }); | 154 }); |
155 result.push(function(jsonObject){ | 155 result.push(function (jsonObject){ |
156 var allString = true; | 156 var allString = true; |
157 jsonObject.stringify({a:"1", b:"2", c:"3", 5:4, 4:5, 2:6, 1:7}, function
(k,v){allString = allString && (typeof k == "string"); return v}); | 157 jsonObject.stringify({a:"1", b:"2", c:"3", 5:4, 4:5, 2:6, 1:7}, function
(k,v){allString = allString && (typeof k == "string"); return v}); |
158 return allString; | 158 return allString; |
159 }); | 159 }); |
160 result.push(function(jsonObject){ | 160 result.push(function (jsonObject){ |
161 var allString = true; | 161 var allString = true; |
162 jsonObject.stringify([1,2,3,4,5], function(k,v){allString = allString &&
(typeof k == "string"); return v}); | 162 jsonObject.stringify([1,2,3,4,5], function(k,v){allString = allString &&
(typeof k == "string"); return v}); |
163 return allString; | 163 return allString; |
164 }); | 164 }); |
165 result.push(function(jsonObject){ | 165 result.push(function (jsonObject){ |
166 var allString = true; | 166 var allString = true; |
167 var array = []; | 167 var array = []; |
168 return jsonObject.stringify({a:"1", b:"2", c:"3", 5:4, 4:5, 2:6, 1:7}, a
rray); | 168 return jsonObject.stringify({a:"1", b:"2", c:"3", 5:4, 4:5, 2:6, 1:7}, a
rray); |
169 }); | 169 }); |
170 result.push(function(jsonObject){ | 170 result.push(function (jsonObject){ |
171 var allString = true; | 171 var allString = true; |
172 var array = ["a"]; | 172 var array = ["a"]; |
173 return jsonObject.stringify({get a(){return 1;array[1]="b";array[2]="c"}
, b:"2", c:"3"}, array); | 173 return jsonObject.stringify({get a(){return 1;array[1]="b";array[2]="c"}
, b:"2", c:"3"}, array); |
174 }); | 174 }); |
175 result.push(function(jsonObject){ | 175 result.push(function (jsonObject){ |
176 var allString = true; | 176 var allString = true; |
177 var array = [{toString:function(){array[0]='a'; array[1]='c'; array[2]='
b'; return 'a'}}]; | 177 var array = [{toString:function(){array[0]='a'; array[1]='c'; array[2]='
b'; return 'a'}}]; |
178 return jsonObject.stringify(simpleObject, array); | 178 return jsonObject.stringify(simpleObject, array); |
179 }); | 179 }); |
180 result.push(function(jsonObject){ | 180 result.push(function (jsonObject){ |
181 var allString = true; | 181 var allString = true; |
182 var array = [{toString:function(){array[0]='a'; array[1]='c'; array[2]='
b'; return 'a'}}]; | 182 var array = [{toString:function(){array[0]='a'; array[1]='c'; array[2]='
b'; return 'a'}}]; |
183 return jsonObject.stringify(simpleObjectWithProto, array); | 183 return jsonObject.stringify(simpleObjectWithProto, array); |
184 }); | 184 }); |
185 result.push(function(jsonObject){ | 185 result.push(function (jsonObject){ |
186 var allString = true; | 186 var allString = true; |
187 var array = [1, new Number(2), NaN, Infinity, -Infinity, new String("str
")]; | 187 var array = [1, new Number(2), NaN, Infinity, -Infinity, new String("str
")]; |
188 return jsonObject.stringify({"1":"1","2":"2","NaN":"NaN","Infinity":"Inf
inity","-Infinity":"-Infinity","str":"str"}, array); | 188 return jsonObject.stringify({"1":"1","2":"2","NaN":"NaN","Infinity":"Inf
inity","-Infinity":"-Infinity","str":"str"}, array); |
189 }); | 189 }); |
190 result[result.length - 1].expected = '{"1":"1","2":"2","NaN":"NaN","Infinity
":"Infinity","-Infinity":"-Infinity","str":"str"}'; | 190 result[result.length - 1].expected = '{"1":"1","2":"2","NaN":"NaN","Infinity
":"Infinity","-Infinity":"-Infinity","str":"str"}'; |
191 result.push(function(jsonObject){ | 191 result.push(function (jsonObject){ |
192 var allString = true; | 192 var allString = true; |
193 var array = ["1","2","3"]; | 193 var array = ["1","2","3"]; |
194 return jsonObject.stringify({1:'a', 2:'b', 3:'c'}, array); | 194 return jsonObject.stringify({1:'a', 2:'b', 3:'c'}, array); |
195 }); | 195 }); |
196 result.push(function(jsonObject){ | 196 result.push(function (jsonObject){ |
197 var allString = true; | 197 var allString = true; |
198 var array = ["1","2","3"]; | 198 var array = ["1","2","3"]; |
199 return jsonObject.stringify(simpleArray, array); | 199 return jsonObject.stringify(simpleArray, array); |
200 }); | 200 }); |
201 result.push(function(jsonObject){ | 201 result.push(function (jsonObject){ |
202 return jsonObject.stringify(simpleArray, null, " "); | 202 return jsonObject.stringify(simpleArray, null, " "); |
203 }); | 203 }); |
204 result.push(function(jsonObject){ | 204 result.push(function (jsonObject){ |
205 return jsonObject.stringify(simpleArray, null, 4); | 205 return jsonObject.stringify(simpleArray, null, 4); |
206 }); | 206 }); |
207 result.push(function(jsonObject){ | 207 result.push(function (jsonObject){ |
208 return jsonObject.stringify(simpleArray, null, "ab"); | 208 return jsonObject.stringify(simpleArray, null, "ab"); |
209 }); | 209 }); |
210 result.push(function(jsonObject){ | 210 result.push(function (jsonObject){ |
211 return jsonObject.stringify(simpleArray, null, 4); | 211 return jsonObject.stringify(simpleArray, null, 4); |
212 }); | 212 }); |
213 result.push(function(jsonObject){ | 213 result.push(function (jsonObject){ |
214 return jsonObject.stringify(simpleObject, null, " "); | 214 return jsonObject.stringify(simpleObject, null, " "); |
215 }); | 215 }); |
216 result.push(function(jsonObject){ | 216 result.push(function (jsonObject){ |
217 return jsonObject.stringify(simpleObject, null, 4); | 217 return jsonObject.stringify(simpleObject, null, 4); |
218 }); | 218 }); |
219 result.push(function(jsonObject){ | 219 result.push(function (jsonObject){ |
220 return jsonObject.stringify(simpleObject, null, "ab"); | 220 return jsonObject.stringify(simpleObject, null, "ab"); |
221 }); | 221 }); |
222 result.push(function(jsonObject){ | 222 result.push(function (jsonObject){ |
223 return jsonObject.stringify(simpleObject, null, 4); | 223 return jsonObject.stringify(simpleObject, null, 4); |
224 }); | 224 }); |
225 result.push(function(jsonObject){ | 225 result.push(function (jsonObject){ |
226 return jsonObject.stringify(simpleObject, null, 10); | 226 return jsonObject.stringify(simpleObject, null, 10); |
227 }); | 227 }); |
228 result.push(function(jsonObject){ | 228 result.push(function (jsonObject){ |
229 return jsonObject.stringify(simpleObject, null, 11); | 229 return jsonObject.stringify(simpleObject, null, 11); |
230 }); | 230 }); |
231 result[result.length - 1].expected = JSON.stringify(simpleObject, null, 10); | 231 result[result.length - 1].expected = JSON.stringify(simpleObject, null, 10); |
232 result.push(function(jsonObject){ | 232 result.push(function (jsonObject){ |
233 return jsonObject.stringify(simpleObject, null, " "); | 233 return jsonObject.stringify(simpleObject, null, " "); |
234 }); | 234 }); |
235 result[result.length - 1].expected = JSON.stringify(simpleObject, null, 10); | 235 result[result.length - 1].expected = JSON.stringify(simpleObject, null, 10); |
236 result.push(function(jsonObject){ | 236 result.push(function (jsonObject){ |
237 return jsonObject.stringify(simpleObject, null, " "); | 237 return jsonObject.stringify(simpleObject, null, " "); |
238 }); | 238 }); |
239 result[result.length - 1].expected = JSON.stringify(simpleObject, null, 10); | 239 result[result.length - 1].expected = JSON.stringify(simpleObject, null, 10); |
240 result.push(function(jsonObject){ | 240 result.push(function (jsonObject){ |
241 return jsonObject.stringify(complexArray, null, " "); | 241 return jsonObject.stringify(complexArray, null, " "); |
242 }); | 242 }); |
243 result.push(function(jsonObject){ | 243 result.push(function (jsonObject){ |
244 return jsonObject.stringify(complexArray, null, 4); | 244 return jsonObject.stringify(complexArray, null, 4); |
245 }); | 245 }); |
246 result.push(function(jsonObject){ | 246 result.push(function (jsonObject){ |
247 return jsonObject.stringify(complexArray, null, "ab"); | 247 return jsonObject.stringify(complexArray, null, "ab"); |
248 }); | 248 }); |
249 result.push(function(jsonObject){ | 249 result.push(function (jsonObject){ |
250 return jsonObject.stringify(complexArray, null, 4); | 250 return jsonObject.stringify(complexArray, null, 4); |
251 }); | 251 }); |
252 result.push(function(jsonObject){ | 252 result.push(function (jsonObject){ |
253 return jsonObject.stringify(complexObject, null, " "); | 253 return jsonObject.stringify(complexObject, null, " "); |
254 }); | 254 }); |
255 result.push(function(jsonObject){ | 255 result.push(function (jsonObject){ |
256 return jsonObject.stringify(complexObject, null, 4); | 256 return jsonObject.stringify(complexObject, null, 4); |
257 }); | 257 }); |
258 result.push(function(jsonObject){ | 258 result.push(function (jsonObject){ |
259 return jsonObject.stringify(complexObject, null, "ab"); | 259 return jsonObject.stringify(complexObject, null, "ab"); |
260 }); | 260 }); |
261 result.push(function(jsonObject){ | 261 result.push(function (jsonObject){ |
262 return jsonObject.stringify(complexObject, null, 4); | 262 return jsonObject.stringify(complexObject, null, 4); |
263 }); | 263 }); |
264 result.push(function(jsonObject){ | 264 result.push(function (jsonObject){ |
265 var allString = true; | 265 var allString = true; |
266 var array = ["1","2","3"]; | 266 var array = ["1","2","3"]; |
267 return jsonObject.stringify(simpleArrayWithProto, array); | 267 return jsonObject.stringify(simpleArrayWithProto, array); |
268 }); | 268 }); |
269 result.push(function(jsonObject){ | 269 result.push(function (jsonObject){ |
270 return jsonObject.stringify(simpleArrayWithProto, null, " "); | 270 return jsonObject.stringify(simpleArrayWithProto, null, " "); |
271 }); | 271 }); |
272 result.push(function(jsonObject){ | 272 result.push(function (jsonObject){ |
273 return jsonObject.stringify(simpleArrayWithProto, null, 4); | 273 return jsonObject.stringify(simpleArrayWithProto, null, 4); |
274 }); | 274 }); |
275 result.push(function(jsonObject){ | 275 result.push(function (jsonObject){ |
276 return jsonObject.stringify(simpleArrayWithProto, null, "ab"); | 276 return jsonObject.stringify(simpleArrayWithProto, null, "ab"); |
277 }); | 277 }); |
278 result.push(function(jsonObject){ | 278 result.push(function (jsonObject){ |
279 return jsonObject.stringify(simpleArrayWithProto, null, 4); | 279 return jsonObject.stringify(simpleArrayWithProto, null, 4); |
280 }); | 280 }); |
281 result.push(function(jsonObject){ | 281 result.push(function (jsonObject){ |
282 return jsonObject.stringify(simpleObjectWithProto, null, " "); | 282 return jsonObject.stringify(simpleObjectWithProto, null, " "); |
283 }); | 283 }); |
284 result.push(function(jsonObject){ | 284 result.push(function (jsonObject){ |
285 return jsonObject.stringify(simpleObjectWithProto, null, 4); | 285 return jsonObject.stringify(simpleObjectWithProto, null, 4); |
286 }); | 286 }); |
287 result.push(function(jsonObject){ | 287 result.push(function (jsonObject){ |
288 return jsonObject.stringify(simpleObjectWithProto, null, "ab"); | 288 return jsonObject.stringify(simpleObjectWithProto, null, "ab"); |
289 }); | 289 }); |
290 result.push(function(jsonObject){ | 290 result.push(function (jsonObject){ |
291 return jsonObject.stringify(simpleObjectWithProto, null, 4); | 291 return jsonObject.stringify(simpleObjectWithProto, null, 4); |
292 }); | 292 }); |
293 result.push(function(jsonObject){ | 293 result.push(function (jsonObject){ |
294 return jsonObject.stringify(simpleObjectWithProto, null, 10); | 294 return jsonObject.stringify(simpleObjectWithProto, null, 10); |
295 }); | 295 }); |
296 result.push(function(jsonObject){ | 296 result.push(function (jsonObject){ |
297 return jsonObject.stringify(simpleObjectWithProto, null, 11); | 297 return jsonObject.stringify(simpleObjectWithProto, null, 11); |
298 }); | 298 }); |
299 result[result.length - 1].expected = JSON.stringify(simpleObjectWithProto, n
ull, 10); | 299 result[result.length - 1].expected = JSON.stringify(simpleObjectWithProto, n
ull, 10); |
300 result.push(function(jsonObject){ | 300 result.push(function (jsonObject){ |
301 return jsonObject.stringify(simpleObjectWithProto, null, " "); | 301 return jsonObject.stringify(simpleObjectWithProto, null, " "); |
302 }); | 302 }); |
303 result[result.length - 1].expected = JSON.stringify(simpleObjectWithProto, n
ull, 10); | 303 result[result.length - 1].expected = JSON.stringify(simpleObjectWithProto, n
ull, 10); |
304 result.push(function(jsonObject){ | 304 result.push(function (jsonObject){ |
305 return jsonObject.stringify(simpleObjectWithProto, null, " "); | 305 return jsonObject.stringify(simpleObjectWithProto, null, " "); |
306 }); | 306 }); |
307 result[result.length - 1].expected = JSON.stringify(simpleObjectWithProto, n
ull, 10); | 307 result[result.length - 1].expected = JSON.stringify(simpleObjectWithProto, n
ull, 10); |
308 result.push(function(jsonObject){ | 308 result.push(function (jsonObject){ |
309 return jsonObject.stringify(complexArrayWithProto, null, " "); | 309 return jsonObject.stringify(complexArrayWithProto, null, " "); |
310 }); | 310 }); |
311 result.push(function(jsonObject){ | 311 result.push(function (jsonObject){ |
312 return jsonObject.stringify(complexArrayWithProto, null, 4); | 312 return jsonObject.stringify(complexArrayWithProto, null, 4); |
313 }); | 313 }); |
314 result.push(function(jsonObject){ | 314 result.push(function (jsonObject){ |
315 return jsonObject.stringify(complexArrayWithProto, null, "ab"); | 315 return jsonObject.stringify(complexArrayWithProto, null, "ab"); |
316 }); | 316 }); |
317 result.push(function(jsonObject){ | 317 result.push(function (jsonObject){ |
318 return jsonObject.stringify(complexArrayWithProto, null, 4); | 318 return jsonObject.stringify(complexArrayWithProto, null, 4); |
319 }); | 319 }); |
320 result.push(function(jsonObject){ | 320 result.push(function (jsonObject){ |
321 return jsonObject.stringify(complexObjectWithProto, null, " "); | 321 return jsonObject.stringify(complexObjectWithProto, null, " "); |
322 }); | 322 }); |
323 result.push(function(jsonObject){ | 323 result.push(function (jsonObject){ |
324 return jsonObject.stringify(complexObjectWithProto, null, 4); | 324 return jsonObject.stringify(complexObjectWithProto, null, 4); |
325 }); | 325 }); |
326 result.push(function(jsonObject){ | 326 result.push(function (jsonObject){ |
327 return jsonObject.stringify(complexObjectWithProto, null, "ab"); | 327 return jsonObject.stringify(complexObjectWithProto, null, "ab"); |
328 }); | 328 }); |
329 result.push(function(jsonObject){ | 329 result.push(function (jsonObject){ |
330 return jsonObject.stringify(complexObjectWithProto, null, 4); | 330 return jsonObject.stringify(complexObjectWithProto, null, 4); |
331 }); | 331 }); |
332 result.push(function(jsonObject){ | 332 result.push(function (jsonObject){ |
333 return jsonObject.stringify(objectWithSideEffectGetter); | 333 return jsonObject.stringify(objectWithSideEffectGetter); |
334 }); | 334 }); |
335 result.push(function(jsonObject){ | 335 result.push(function (jsonObject){ |
336 return jsonObject.stringify(objectWithSideEffectGetterAndProto); | 336 return jsonObject.stringify(objectWithSideEffectGetterAndProto); |
337 }); | 337 }); |
338 result.push(function(jsonObject){ | 338 result.push(function (jsonObject){ |
339 return jsonObject.stringify(arrayWithSideEffectGetter); | 339 return jsonObject.stringify(arrayWithSideEffectGetter); |
340 }); | 340 }); |
341 result.push(function(jsonObject){ | 341 result.push(function (jsonObject){ |
342 return jsonObject.stringify(arrayWithSideEffectGetterAndProto); | 342 return jsonObject.stringify(arrayWithSideEffectGetterAndProto); |
343 }); | 343 }); |
344 var replaceTracker; | 344 var replaceTracker; |
345 function replaceFunc(key, value) { | 345 function replaceFunc(key, value) { |
346 replaceTracker += key + "("+(typeof key)+")" + JSON.stringify(value) + "
;"; | 346 replaceTracker += key + "("+(typeof key)+")" + JSON.stringify(value) + "
;"; |
347 return value; | 347 return value; |
348 } | 348 } |
349 result.push(function(jsonObject){ | 349 result.push(function (jsonObject){ |
350 replaceTracker = ""; | 350 replaceTracker = ""; |
351 jsonObject.stringify([1,2,3,,,,4,5,6], replaceFunc); | 351 jsonObject.stringify([1,2,3,,,,4,5,6], replaceFunc); |
352 return replaceTracker; | 352 return replaceTracker; |
353 }); | 353 }); |
354 result[result.length - 1].expected = '(string)[1,2,3,null,null,null,4,5,6];0
(number)1;1(number)2;2(number)3;3(number)undefined;4(number)undefined;5(number)u
ndefined;6(number)4;7(number)5;8(number)6;' | 354 result[result.length - 1].expected = '(string)[1,2,3,null,null,null,4,5,6];0
(number)1;1(number)2;2(number)3;3(number)undefined;4(number)undefined;5(number)u
ndefined;6(number)4;7(number)5;8(number)6;' |
355 result.push(function(jsonObject){ | 355 result.push(function (jsonObject){ |
356 replaceTracker = ""; | 356 replaceTracker = ""; |
357 jsonObject.stringify({a:"a", b:"b", c:"c", 3: "d", 2: "e", 1: "f"}, repl
aceFunc); | 357 jsonObject.stringify({a:"a", b:"b", c:"c", 3: "d", 2: "e", 1: "f"}, repl
aceFunc); |
358 return replaceTracker; | 358 return replaceTracker; |
359 }); | 359 }); |
360 result[result.length - 1].expected = '(string){"1":"f","2":"e","3":"d","a":"
a","b":"b","c":"c"};1(string)"f";2(string)"e";3(string)"d";a(string)"a";b(string
)"b";c(string)"c";'; | 360 result[result.length - 1].expected = '(string){"1":"f","2":"e","3":"d","a":"
a","b":"b","c":"c"};1(string)"f";2(string)"e";3(string)"d";a(string)"a";b(string
)"b";c(string)"c";'; |
361 result.push(function(jsonObject){ | 361 result.push(function (jsonObject){ |
362 var count = 0; | 362 var count = 0; |
363 var array = [{toString:function(){count++; array[0]='a'; array[1]='c'; a
rray[2]='b'; return 'a'}}]; | 363 var array = [{toString:function(){count++; array[0]='a'; array[1]='c'; a
rray[2]='b'; return 'a'}}]; |
364 jsonObject.stringify(simpleObject, array); | 364 jsonObject.stringify(simpleObject, array); |
365 return count; | 365 return count; |
366 }); | 366 }); |
367 result.push(function(jsonObject){ | 367 result.push(function (jsonObject){ |
368 var allString = true; | 368 var allString = true; |
369 var array = [{toString:function(){array[0]='a'; array[1]='c'; array[2]='
b'; return 'a'}}, 'b', 'c']; | 369 var array = [{toString:function(){array[0]='a'; array[1]='c'; array[2]='
b'; return 'a'}}, 'b', 'c']; |
370 return jsonObject.stringify(simpleObject, array); | 370 return jsonObject.stringify(simpleObject, array); |
371 }); | 371 }); |
372 result.push(function(jsonObject){ | 372 result.push(function (jsonObject){ |
373 var count = 0; | 373 var count = 0; |
374 var array = [{toString:function(){count++; array[0]='a'; array[1]='c'; a
rray[2]='b'; return 'a'}}, 'b', 'c']; | 374 var array = [{toString:function(){count++; array[0]='a'; array[1]='c'; a
rray[2]='b'; return 'a'}}, 'b', 'c']; |
375 jsonObject.stringify(simpleObject, array); | 375 jsonObject.stringify(simpleObject, array); |
376 return count; | 376 return count; |
377 }); | 377 }); |
378 result.push(function(jsonObject){ | 378 result.push(function (jsonObject){ |
379 return jsonObject.stringify({a:"1", get b() { this.a="foo"; return "gett
er"; }, c:"3"}); | 379 return jsonObject.stringify({a:"1", get b() { this.a="foo"; return "gett
er"; }, c:"3"}); |
380 }); | 380 }); |
381 result.push(function(jsonObject){ | 381 result.push(function (jsonObject){ |
382 return jsonObject.stringify({a:"1", get b() { this.c="foo"; return "gett
er"; }, c:"3"}); | 382 return jsonObject.stringify({a:"1", get b() { this.c="foo"; return "gett
er"; }, c:"3"}); |
383 }); | 383 }); |
384 result.push(function(jsonObject){ | 384 result.push(function (jsonObject){ |
385 var setterCalled = false; | 385 var setterCalled = false; |
386 jsonObject.stringify({a:"1", set b(s) { setterCalled = true; return "set
ter"; }, c:"3"}); | 386 jsonObject.stringify({a:"1", set b(s) { setterCalled = true; return "set
ter"; }, c:"3"}); |
387 return setterCalled; | 387 return setterCalled; |
388 }); | 388 }); |
389 result.push(function(jsonObject){ | 389 result.push(function (jsonObject){ |
390 return jsonObject.stringify({a:"1", get b(){ return "getter"; }, set b(s
) { return "setter"; }, c:"3"}); | 390 return jsonObject.stringify({a:"1", get b(){ return "getter"; }, set b(s
) { return "setter"; }, c:"3"}); |
391 }); | 391 }); |
392 result.push(function(jsonObject){ | 392 result.push(function (jsonObject){ |
393 return jsonObject.stringify(new Array(10)); | 393 return jsonObject.stringify(new Array(10)); |
394 }); | 394 }); |
395 result.push(function(jsonObject){ | 395 result.push(function (jsonObject){ |
396 return jsonObject.stringify([undefined,,null,0,false]); | 396 return jsonObject.stringify([undefined,,null,0,false]); |
397 }); | 397 }); |
398 result.push(function(jsonObject){ | 398 result.push(function (jsonObject){ |
399 return jsonObject.stringify({p1:undefined,p2:null,p3:0,p4:false}); | 399 return jsonObject.stringify({p1:undefined,p2:null,p3:0,p4:false}); |
400 }); | 400 }); |
401 var cycleTracker = ""; | 401 var cycleTracker = ""; |
402 var cyclicObject = { get preSelf1() { cycleTracker+="preSelf1,"; return "pre
Self1"; }, | 402 var cyclicObject = { get preSelf1() { cycleTracker+="preSelf1,"; return "pre
Self1"; }, |
403 preSelf2: {toJSON:function(){cycleTracker+="preSelf
2,"; return "preSelf2"}}, | 403 preSelf2: {toJSON:function(){cycleTracker+="preSelf
2,"; return "preSelf2"}}, |
404 self: [], | 404 self: [], |
405 get postSelf1() { cycleTracker+="postSelf1,"; return "p
ostSelf1" }, | 405 get postSelf1() { cycleTracker+="postSelf1,"; return "p
ostSelf1" }, |
406 postSelf2: {toJSON:function(){cycleTracker+="postSe
lf2,"; return "postSelf2"}}, | 406 postSelf2: {toJSON:function(){cycleTracker+="postSe
lf2,"; return "postSelf2"}}, |
407 toJSON : function(key) { cycleTracker += key + "("+
(typeof key)+"):" + this; return this; } | 407 toJSON : function(key) { cycleTracker += key + "("+
(typeof key)+"):" + this; return this; } |
408 }; | 408 }; |
409 cyclicObject.self = cyclicObject; | 409 cyclicObject.self = cyclicObject; |
410 result.push(function(jsonObject){ | 410 result.push(function (jsonObject){ |
411 cycleTracker = ""; | 411 cycleTracker = ""; |
412 return jsonObject.stringify(cyclicObject); | 412 return jsonObject.stringify(cyclicObject); |
413 }); | 413 }); |
414 result[result.length - 1].throws = true; | 414 result[result.length - 1].throws = true; |
415 result.push(function(jsonObject){ | 415 result.push(function (jsonObject){ |
416 cycleTracker = ""; | 416 cycleTracker = ""; |
417 try { jsonObject.stringify(cyclicObject); } catch(e) { cycleTracker += "
-> exception" } | 417 try { jsonObject.stringify(cyclicObject); } catch(e) { cycleTracker += "
-> exception" } |
418 return cycleTracker; | 418 return cycleTracker; |
419 }); | 419 }); |
420 result[result.length - 1].expected = "(string):[object Object]preSelf1,preSe
lf2,self(string):[object Object] -> exception" | 420 result[result.length - 1].expected = "(string):[object Object]preSelf1,preSe
lf2,self(string):[object Object] -> exception" |
421 var cyclicArray = [{toJSON : function(key,value) { cycleTracker += key + "("
+(typeof key)+"):" + this; cycleTracker += "first,"; return this; }}, | 421 var cyclicArray = [{toJSON : function(key,value) { cycleTracker += key + "("
+(typeof key)+"):" + this; cycleTracker += "first,"; return this; }}, |
422 cyclicArray, | 422 cyclicArray, |
423 {toJSON : function(key,value) { cycleTracker += key + "("
+(typeof key)+"):" + this; cycleTracker += "second,"; return this; }}]; | 423 {toJSON : function(key,value) { cycleTracker += key + "("
+(typeof key)+"):" + this; cycleTracker += "second,"; return this; }}]; |
424 cyclicArray[1] = cyclicArray; | 424 cyclicArray[1] = cyclicArray; |
425 result.push(function(jsonObject){ | 425 result.push(function (jsonObject){ |
426 cycleTracker = ""; | 426 cycleTracker = ""; |
427 return jsonObject.stringify(cyclicArray); | 427 return jsonObject.stringify(cyclicArray); |
428 }); | 428 }); |
429 result[result.length - 1].throws = true; | 429 result[result.length - 1].throws = true; |
430 result.push(function(jsonObject){ | 430 result.push(function (jsonObject){ |
431 cycleTracker = ""; | 431 cycleTracker = ""; |
432 try { jsonObject.stringify(cyclicArray); } catch(e) { cycleTracker += "
-> exception" } | 432 try { jsonObject.stringify(cyclicArray); } catch(e) { cycleTracker += "
-> exception" } |
433 return cycleTracker; | 433 return cycleTracker; |
434 }); | 434 }); |
435 result[result.length - 1].expected = "0(number):[object Object]first, -> exc
eption"; | 435 result[result.length - 1].expected = "0(number):[object Object]first, -> exc
eption"; |
436 function createArray(len, o) { var r = []; for (var i = 0; i < len; i++) r[i
] = o; return r; } | 436 function createArray(len, o) { var r = []; for (var i = 0; i < len; i++) r[i
] = o; return r; } |
437 var getterCalls; | 437 var getterCalls; |
438 var magicObject = createArray(10, {abcdefg: [1,2,5,"ab", null, undefined, tr
ue, false,,], | 438 var magicObject = createArray(10, {abcdefg: [1,2,5,"ab", null, undefined, tr
ue, false,,], |
439 get calls() {return ++getterCalls; }, | 439 get calls() {return ++getterCalls; }, |
440 "123":createArray(15, "foo"), | 440 "123":createArray(15, "foo"), |
441 "":{a:"b"}}); | 441 "":{a:"b"}}); |
442 result.push(function(jsonObject){ | 442 result.push(function (jsonObject){ |
443 getterCalls = 0; | 443 getterCalls = 0; |
444 return jsonObject.stringify(magicObject) + " :: getter calls = " + gette
rCalls; | 444 return jsonObject.stringify(magicObject) + " :: getter calls = " + gette
rCalls; |
445 }); | 445 }); |
446 result.push(function(jsonObject){ | 446 result.push(function (jsonObject){ |
447 return jsonObject.stringify(undefined); | 447 return jsonObject.stringify(undefined); |
448 }); | 448 }); |
449 result.push(function(jsonObject){ | 449 result.push(function (jsonObject){ |
450 return jsonObject.stringify(null); | 450 return jsonObject.stringify(null); |
451 }); | 451 }); |
452 result.push(function(jsonObject){ | 452 result.push(function (jsonObject){ |
453 return jsonObject.stringify({toJSON:function(){ return undefined; }}); | 453 return jsonObject.stringify({toJSON:function(){ return undefined; }}); |
454 }); | 454 }); |
455 result.push(function(jsonObject){ | 455 result.push(function (jsonObject){ |
456 return jsonObject.stringify({toJSON:function(){ return null; }}); | 456 return jsonObject.stringify({toJSON:function(){ return null; }}); |
457 }); | 457 }); |
458 result.push(function(jsonObject){ | 458 result.push(function (jsonObject){ |
459 return jsonObject.stringify([{toJSON:function(){ return undefined; }}]); | 459 return jsonObject.stringify([{toJSON:function(){ return undefined; }}]); |
460 }); | 460 }); |
461 result.push(function(jsonObject){ | 461 result.push(function (jsonObject){ |
462 return jsonObject.stringify([{toJSON:function(){ return null; }}]); | 462 return jsonObject.stringify([{toJSON:function(){ return null; }}]); |
463 }); | 463 }); |
464 result.push(function(jsonObject){ | 464 result.push(function (jsonObject){ |
465 return jsonObject.stringify({a:{toJSON:function(){ return undefined; }}}
); | 465 return jsonObject.stringify({a:{toJSON:function(){ return undefined; }}}
); |
466 }); | 466 }); |
467 result.push(function(jsonObject){ | 467 result.push(function (jsonObject){ |
468 return jsonObject.stringify({a:{toJSON:function(){ return null; }}}); | 468 return jsonObject.stringify({a:{toJSON:function(){ return null; }}}); |
469 }); | 469 }); |
470 result.push(function(jsonObject){ | 470 result.push(function (jsonObject){ |
471 return jsonObject.stringify({a:{toJSON:function(){ return function(){};
}}}); | 471 return jsonObject.stringify({a:{toJSON:function(){ return function(){};
}}}); |
472 }); | 472 }); |
473 result.push(function(jsonObject){ | 473 result.push(function (jsonObject){ |
474 return jsonObject.stringify({a:function(){}}); | 474 return jsonObject.stringify({a:function(){}}); |
475 }); | 475 }); |
476 result.push(function(jsonObject){ | 476 result.push(function (jsonObject){ |
477 var deepObject = {}; | 477 var deepObject = {}; |
478 for (var i = 0; i < 1024; i++) | 478 for (var i = 0; i < 1024; i++) |
479 deepObject = {next:deepObject}; | 479 deepObject = {next:deepObject}; |
480 return jsonObject.stringify(deepObject); | 480 return jsonObject.stringify(deepObject); |
481 }); | 481 }); |
482 result.push(function(jsonObject){ | 482 result.push(function (jsonObject){ |
483 var deepArray = []; | 483 var deepArray = []; |
484 for (var i = 0; i < 1024; i++) | 484 for (var i = 0; i < 1024; i++) |
485 deepArray = [deepArray]; | 485 deepArray = [deepArray]; |
486 return jsonObject.stringify(deepArray); | 486 return jsonObject.stringify(deepArray); |
487 }); | 487 }); |
488 result.push(function(jsonObject){ | 488 result.push(function (jsonObject){ |
489 var depth = 0; | 489 var depth = 0; |
490 function toDeepVirtualJSONObject() { | 490 function toDeepVirtualJSONObject() { |
491 if (++depth >= 1024) | 491 if (++depth >= 1024) |
492 return {}; | 492 return {}; |
493 var r = {}; | 493 var r = {}; |
494 r.toJSON = toDeepVirtualJSONObject; | 494 r.toJSON = toDeepVirtualJSONObject; |
495 return {recurse: r}; | 495 return {recurse: r}; |
496 } | 496 } |
497 return jsonObject.stringify(toDeepVirtualJSONObject()); | 497 return jsonObject.stringify(toDeepVirtualJSONObject()); |
498 }); | 498 }); |
499 result.push(function(jsonObject){ | 499 result.push(function (jsonObject){ |
500 var depth = 0; | 500 var depth = 0; |
501 function toDeepVirtualJSONArray() { | 501 function toDeepVirtualJSONArray() { |
502 if (++depth >= 1024) | 502 if (++depth >= 1024) |
503 return []; | 503 return []; |
504 var r = []; | 504 var r = []; |
505 r.toJSON = toDeepJSONArray; | 505 r.toJSON = toDeepJSONArray; |
506 return [r]; | 506 return [r]; |
507 } | 507 } |
508 return jsonObject.stringify(toDeepVirtualJSONArray()); | 508 return jsonObject.stringify(toDeepVirtualJSONArray()); |
509 }); | 509 }); |
510 var fullCharsetString = ""; | 510 var fullCharsetString = ""; |
511 for (var i = 0; i < 65536; i++) | 511 for (var i = 0; i < 65536; i++) |
512 fullCharsetString += String.fromCharCode(i); | 512 fullCharsetString += String.fromCharCode(i); |
513 result.push(function(jsonObject){ | 513 result.push(function (jsonObject){ |
514 return jsonObject.stringify(fullCharsetString); | 514 return jsonObject.stringify(fullCharsetString); |
515 }); | 515 }); |
516 return result; | 516 return result; |
517 } | 517 } |
518 var tests = createTests(); | 518 var tests = createTests(); |
519 for (var i = 0; i < tests.length; i++) { | 519 for (var i = 0; i < tests.length; i++) { |
520 try { | 520 try { |
521 debug(tests[i]); | 521 debug(tests[i]); |
522 if (tests[i].throws) | 522 if (tests[i].throws) |
523 shouldThrow('tests[i](nativeJSON)'); | 523 shouldThrow('tests[i](nativeJSON)'); |
524 else if (tests[i].expected) | 524 else if (tests[i].expected) |
525 shouldBe('tests[i](nativeJSON)', "tests[i].expected"); | 525 shouldBe('tests[i](nativeJSON)', "tests[i].expected"); |
526 else | 526 else |
527 shouldBe('tests[i](nativeJSON)', "tests[i](JSON)"); | 527 shouldBe('tests[i](nativeJSON)', "tests[i](JSON)"); |
528 }catch(e){} | 528 }catch(e){} |
529 } | 529 } |
OLD | NEW |