2 return jsonObject.stringify(1);
4 PASS tests[i](nativeJSON) is tests[i](JSON)
6 return jsonObject.stringify(1.5);
8 PASS tests[i](nativeJSON) is tests[i](JSON)
10 return jsonObject.stringify(-1);
12 PASS tests[i](nativeJSON) is tests[i](JSON)
13 function (jsonObject){
14 return jsonObject.stringify(-1.5);
16 PASS tests[i](nativeJSON) is tests[i](JSON)
17 function (jsonObject){
18 return jsonObject.stringify(null);
20 PASS tests[i](nativeJSON) is tests[i](JSON)
21 function (jsonObject){
22 return jsonObject.stringify("string");
24 PASS tests[i](nativeJSON) is tests[i](JSON)
25 function (jsonObject){
26 return jsonObject.stringify(new Number(0));
28 PASS tests[i](nativeJSON) is tests[i](JSON)
29 function (jsonObject){
30 return jsonObject.stringify(new Number(1));
32 PASS tests[i](nativeJSON) is tests[i](JSON)
33 function (jsonObject){
34 return jsonObject.stringify(new Number(1.5));
36 PASS tests[i](nativeJSON) is tests[i](JSON)
37 function (jsonObject){
38 return jsonObject.stringify(new Number(-1));
40 PASS tests[i](nativeJSON) is tests[i](JSON)
41 function (jsonObject){
42 return jsonObject.stringify(new Number(-1.5));
44 PASS tests[i](nativeJSON) is tests[i](JSON)
45 function (jsonObject){
46 return jsonObject.stringify(new String("a string object"));
48 PASS tests[i](nativeJSON) is tests[i](JSON)
49 function (jsonObject){
50 return jsonObject.stringify(new Boolean(true));
52 PASS tests[i](nativeJSON) is tests[i](JSON)
53 function (jsonObject){
54 var value = new Number(1);
55 value.valueOf = function() { return 2; }
56 return jsonObject.stringify(value);
58 PASS tests[i](nativeJSON) is tests[i].expected
59 function (jsonObject){
60 var value = new Boolean(true);
61 value.valueOf = function() { return 2; }
62 return jsonObject.stringify(value);
64 FAIL tests[i](nativeJSON) should be 2. Was true.
65 function (jsonObject){
66 var value = new String("fail");
67 value.toString = function() { return "converted string"; }
68 return jsonObject.stringify(value);
70 PASS tests[i](nativeJSON) is tests[i].expected
71 function (jsonObject){
72 return jsonObject.stringify(true);
74 PASS tests[i](nativeJSON) is tests[i](JSON)
75 function (jsonObject){
76 return jsonObject.stringify(false);
78 PASS tests[i](nativeJSON) is tests[i](JSON)
79 function (jsonObject){
80 return jsonObject.stringify(new Date(0));
82 PASS tests[i](nativeJSON) is tests[i](JSON)
83 function (jsonObject){
84 return jsonObject.stringify({toJSON: Date.prototype.toJSON});
86 PASS tests[i](nativeJSON) threw exception TypeError: undefined is not a function.
87 function (jsonObject){
88 return jsonObject.stringify({toJSON: Date.prototype.toJSON, toISOString: function(){ return "custom toISOString"; }});
90 PASS tests[i](nativeJSON) is tests[i](JSON)
91 function (jsonObject){
92 return jsonObject.stringify({toJSON: Date.prototype.toJSON, toISOString: function(){ return {}; }});
94 FAIL tests[i](nativeJSON) should throw an exception. Was {}.
95 function (jsonObject){
96 return jsonObject.stringify({toJSON: Date.prototype.toJSON, toISOString: function(){ throw "An exception"; }});
98 PASS tests[i](nativeJSON) threw exception An exception.
99 function (jsonObject){
101 d.toISOString = null;
102 return jsonObject.stringify(d);
104 PASS tests[i](nativeJSON) threw exception TypeError: object is not a function.
105 function (jsonObject){
107 d.toJSON = undefined;
108 return jsonObject.stringify(d);
110 PASS tests[i](nativeJSON) is tests[i](JSON)
111 function (jsonObject){
112 return jsonObject.stringify({get Foo() { return "bar"; }});
114 PASS tests[i](nativeJSON) is tests[i](JSON)
115 function (jsonObject){
116 return jsonObject.stringify({get Foo() { this.foo="wibble"; return "bar"; }});
118 PASS tests[i](nativeJSON) is tests[i](JSON)
119 function (jsonObject){
121 jsonObject.stringify({get Foo() { count++; return "bar"; }});
124 PASS tests[i](nativeJSON) is tests[i](JSON)
125 function (jsonObject){
127 return jsonObject.stringify({get Foo() { count++; delete this.bar; return "bar"; }, bar: "wibble"});
129 PASS tests[i](nativeJSON) is tests[i](JSON)
130 function (jsonObject){
132 return jsonObject.stringify({a:"1", b:"2", c:"3", 5:4, 4:5, 2:6, 1:7});
134 PASS tests[i](nativeJSON) is tests[i](JSON)
135 function (jsonObject){
136 var allString = true;
137 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});
140 PASS tests[i](nativeJSON) is tests[i](JSON)
141 function (jsonObject){
142 var allString = true;
143 jsonObject.stringify([1,2,3,4,5], function(k,v){allString = allString && (typeof k == "string"); return v});
146 FAIL tests[i](nativeJSON) should be false. Was true.
147 function (jsonObject){
148 var allString = true;
150 return jsonObject.stringify({a:"1", b:"2", c:"3", 5:4, 4:5, 2:6, 1:7}, array);
152 PASS tests[i](nativeJSON) is tests[i](JSON)
153 function (jsonObject){
154 var allString = true;
156 return jsonObject.stringify({get a(){return 1;array[1]="b";array[2]="c"}, b:"2", c:"3"}, array);
158 PASS tests[i](nativeJSON) is tests[i](JSON)
159 function (jsonObject){
160 var allString = true;
161 var array = [{toString:function(){array[0]='a'; array[1]='c'; array[2]='b'; return 'a'}}];
162 return jsonObject.stringify(simpleObject, array);
164 PASS tests[i](nativeJSON) is tests[i](JSON)
165 function (jsonObject){
166 var allString = true;
167 var array = [{toString:function(){array[0]='a'; array[1]='c'; array[2]='b'; return 'a'}}];
168 return jsonObject.stringify(simpleObjectWithProto, array);
170 PASS tests[i](nativeJSON) is tests[i](JSON)
171 function (jsonObject){
172 var allString = true;
173 var array = [1, new Number(2), NaN, Infinity, -Infinity, new String("str")];
174 return jsonObject.stringify({"1":"1","2":"2","NaN":"NaN","Infinity":"Infinity","-Infinity":"-Infinity","str":"str"}, array);
176 PASS tests[i](nativeJSON) is tests[i].expected
177 function (jsonObject){
178 var allString = true;
179 var array = ["1","2","3"];
180 return jsonObject.stringify({1:'a', 2:'b', 3:'c'}, array);
182 PASS tests[i](nativeJSON) is tests[i](JSON)
183 function (jsonObject){
184 var allString = true;
185 var array = ["1","2","3"];
186 return jsonObject.stringify(simpleArray, array);
188 PASS tests[i](nativeJSON) is tests[i](JSON)
189 function (jsonObject){
190 return jsonObject.stringify(simpleArray, null, " ");
192 PASS tests[i](nativeJSON) is tests[i](JSON)
193 function (jsonObject){
194 return jsonObject.stringify(simpleArray, null, 4);
196 PASS tests[i](nativeJSON) is tests[i](JSON)
197 function (jsonObject){
198 return jsonObject.stringify(simpleArray, null, "ab");
200 PASS tests[i](nativeJSON) is tests[i](JSON)
201 function (jsonObject){
202 return jsonObject.stringify(simpleArray, null, 4);
204 PASS tests[i](nativeJSON) is tests[i](JSON)
205 function (jsonObject){
206 return jsonObject.stringify(simpleObject, null, " ");
208 PASS tests[i](nativeJSON) is tests[i](JSON)
209 function (jsonObject){
210 return jsonObject.stringify(simpleObject, null, 4);
212 PASS tests[i](nativeJSON) is tests[i](JSON)
213 function (jsonObject){
214 return jsonObject.stringify(simpleObject, null, "ab");
216 PASS tests[i](nativeJSON) is tests[i](JSON)
217 function (jsonObject){
218 return jsonObject.stringify(simpleObject, null, 4);
220 PASS tests[i](nativeJSON) is tests[i](JSON)
221 function (jsonObject){
222 return jsonObject.stringify(simpleObject, null, 10);
224 PASS tests[i](nativeJSON) is tests[i](JSON)
225 function (jsonObject){
226 return jsonObject.stringify(simpleObject, null, 11);
228 PASS tests[i](nativeJSON) is tests[i].expected
229 function (jsonObject){
230 return jsonObject.stringify(simpleObject, null, " ");
232 PASS tests[i](nativeJSON) is tests[i].expected
233 function (jsonObject){
234 return jsonObject.stringify(simpleObject, null, " ");
236 PASS tests[i](nativeJSON) is tests[i].expected
237 function (jsonObject){
238 return jsonObject.stringify(complexArray, null, " ");
240 PASS tests[i](nativeJSON) is tests[i](JSON)
241 function (jsonObject){
242 return jsonObject.stringify(complexArray, null, 4);
244 PASS tests[i](nativeJSON) is tests[i](JSON)
245 function (jsonObject){
246 return jsonObject.stringify(complexArray, null, "ab");
248 PASS tests[i](nativeJSON) is tests[i](JSON)
249 function (jsonObject){
250 return jsonObject.stringify(complexArray, null, 4);
252 PASS tests[i](nativeJSON) is tests[i](JSON)
253 function (jsonObject){
254 return jsonObject.stringify(complexObject, null, " ");
256 PASS tests[i](nativeJSON) is tests[i](JSON)
257 function (jsonObject){
258 return jsonObject.stringify(complexObject, null, 4);
260 PASS tests[i](nativeJSON) is tests[i](JSON)
261 function (jsonObject){
262 return jsonObject.stringify(complexObject, null, "ab");
264 PASS tests[i](nativeJSON) is tests[i](JSON)
265 function (jsonObject){
266 return jsonObject.stringify(complexObject, null, 4);
268 PASS tests[i](nativeJSON) is tests[i](JSON)
269 function (jsonObject){
270 var allString = true;
271 var array = ["1","2","3"];
272 return jsonObject.stringify(simpleArrayWithProto, array);
274 PASS tests[i](nativeJSON) is tests[i](JSON)
275 function (jsonObject){
276 return jsonObject.stringify(simpleArrayWithProto, null, " ");
278 PASS tests[i](nativeJSON) is tests[i](JSON)
279 function (jsonObject){
280 return jsonObject.stringify(simpleArrayWithProto, null, 4);
282 PASS tests[i](nativeJSON) is tests[i](JSON)
283 function (jsonObject){
284 return jsonObject.stringify(simpleArrayWithProto, null, "ab");
286 PASS tests[i](nativeJSON) is tests[i](JSON)
287 function (jsonObject){
288 return jsonObject.stringify(simpleArrayWithProto, null, 4);
290 PASS tests[i](nativeJSON) is tests[i](JSON)
291 function (jsonObject){
292 return jsonObject.stringify(simpleObjectWithProto, null, " ");
294 PASS tests[i](nativeJSON) is tests[i](JSON)
295 function (jsonObject){
296 return jsonObject.stringify(simpleObjectWithProto, null, 4);
298 PASS tests[i](nativeJSON) is tests[i](JSON)
299 function (jsonObject){
300 return jsonObject.stringify(simpleObjectWithProto, null, "ab");
302 PASS tests[i](nativeJSON) is tests[i](JSON)
303 function (jsonObject){
304 return jsonObject.stringify(simpleObjectWithProto, null, 4);
306 PASS tests[i](nativeJSON) is tests[i](JSON)
307 function (jsonObject){
308 return jsonObject.stringify(simpleObjectWithProto, null, 10);
310 PASS tests[i](nativeJSON) is tests[i](JSON)
311 function (jsonObject){
312 return jsonObject.stringify(simpleObjectWithProto, null, 11);
314 PASS tests[i](nativeJSON) is tests[i].expected
315 function (jsonObject){
316 return jsonObject.stringify(simpleObjectWithProto, null, " ");
318 PASS tests[i](nativeJSON) is tests[i].expected
319 function (jsonObject){
320 return jsonObject.stringify(simpleObjectWithProto, null, " ");
322 PASS tests[i](nativeJSON) is tests[i].expected
323 function (jsonObject){
324 return jsonObject.stringify(complexArrayWithProto, null, " ");
326 PASS tests[i](nativeJSON) is tests[i](JSON)
327 function (jsonObject){
328 return jsonObject.stringify(complexArrayWithProto, null, 4);
330 PASS tests[i](nativeJSON) is tests[i](JSON)
331 function (jsonObject){
332 return jsonObject.stringify(complexArrayWithProto, null, "ab");
334 PASS tests[i](nativeJSON) is tests[i](JSON)
335 function (jsonObject){
336 return jsonObject.stringify(complexArrayWithProto, null, 4);
338 PASS tests[i](nativeJSON) is tests[i](JSON)
339 function (jsonObject){
340 return jsonObject.stringify(complexObjectWithProto, null, " ");
342 PASS tests[i](nativeJSON) is tests[i](JSON)
343 function (jsonObject){
344 return jsonObject.stringify(complexObjectWithProto, null, 4);
346 PASS tests[i](nativeJSON) is tests[i](JSON)
347 function (jsonObject){
348 return jsonObject.stringify(complexObjectWithProto, null, "ab");
350 PASS tests[i](nativeJSON) is tests[i](JSON)
351 function (jsonObject){
352 return jsonObject.stringify(complexObjectWithProto, null, 4);
354 PASS tests[i](nativeJSON) is tests[i](JSON)
355 function (jsonObject){
356 return jsonObject.stringify(objectWithSideEffectGetter);
358 FAIL tests[i](nativeJSON) should be {"foo":1}. Was {}.
359 function (jsonObject){
360 return jsonObject.stringify(objectWithSideEffectGetterAndProto);
362 FAIL tests[i](nativeJSON) should be {"foo":1}. Was {}.
363 function (jsonObject){
364 return jsonObject.stringify(arrayWithSideEffectGetter);
366 PASS tests[i](nativeJSON) is tests[i](JSON)
367 function (jsonObject){
368 return jsonObject.stringify(arrayWithSideEffectGetterAndProto);
370 PASS tests[i](nativeJSON) is tests[i](JSON)
371 function (jsonObject){
373 jsonObject.stringify([1,2,3,,,,4,5,6], replaceFunc);
374 return replaceTracker;
376 FAIL tests[i](nativeJSON) should be (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)undefined;6(number)4;7(number)5;8(number)6;. Was (string)[1,2,3,null,null,null,4,5,6];0(string)1;1(string)2;2(string)3;3(string)undefined;4(string)undefined;5(string)undefined;6(string)4;7(string)5;8(string)6;.
377 function (jsonObject){
379 jsonObject.stringify({a:"a", b:"b", c:"c", 3: "d", 2: "e", 1: "f"}, replaceFunc);
380 return replaceTracker;
382 PASS tests[i](nativeJSON) is tests[i].expected
383 function (jsonObject){
385 var array = [{toString:function(){count++; array[0]='a'; array[1]='c'; array[2]='b'; return 'a'}}];
386 jsonObject.stringify(simpleObject, array);
389 PASS tests[i](nativeJSON) is tests[i](JSON)
390 function (jsonObject){
391 var allString = true;
392 var array = [{toString:function(){array[0]='a'; array[1]='c'; array[2]='b'; return 'a'}}, 'b', 'c'];
393 return jsonObject.stringify(simpleObject, array);
395 PASS tests[i](nativeJSON) is tests[i](JSON)
396 function (jsonObject){
398 var array = [{toString:function(){count++; array[0]='a'; array[1]='c'; array[2]='b'; return 'a'}}, 'b', 'c'];
399 jsonObject.stringify(simpleObject, array);
402 PASS tests[i](nativeJSON) is tests[i](JSON)
403 function (jsonObject){
404 return jsonObject.stringify({a:"1", get b() { this.a="foo"; return "getter"; }, c:"3"});
406 PASS tests[i](nativeJSON) is tests[i](JSON)
407 function (jsonObject){
408 return jsonObject.stringify({a:"1", get b() { this.c="foo"; return "getter"; }, c:"3"});
410 PASS tests[i](nativeJSON) is tests[i](JSON)
411 function (jsonObject){
412 var setterCalled = false;
413 jsonObject.stringify({a:"1", set b(s) { setterCalled = true; return "setter"; }, c:"3"});
416 PASS tests[i](nativeJSON) is tests[i](JSON)
417 function (jsonObject){
418 return jsonObject.stringify({a:"1", get b(){ return "getter"; }, set b(s) { return "setter"; }, c:"3"});
420 PASS tests[i](nativeJSON) is tests[i](JSON)
421 function (jsonObject){
422 return jsonObject.stringify(new Array(10));
424 PASS tests[i](nativeJSON) is tests[i](JSON)
425 function (jsonObject){
426 return jsonObject.stringify([undefined,,null,0,false]);
428 PASS tests[i](nativeJSON) is tests[i](JSON)
429 function (jsonObject){
430 return jsonObject.stringify({p1:undefined,p2:null,p3:0,p4:false});
432 PASS tests[i](nativeJSON) is tests[i](JSON)
433 function (jsonObject){
435 return jsonObject.stringify(cyclicObject);
437 PASS tests[i](nativeJSON) threw exception TypeError: Converting circular structure to JSON.
438 function (jsonObject){
440 try { jsonObject.stringify(cyclicObject); } catch(e) { cycleTracker += " -> exception" }
443 PASS tests[i](nativeJSON) is tests[i].expected
444 function (jsonObject){
446 return jsonObject.stringify(cyclicArray);
448 PASS tests[i](nativeJSON) threw exception TypeError: Converting circular structure to JSON.
449 function (jsonObject){
451 try { jsonObject.stringify(cyclicArray); } catch(e) { cycleTracker += " -> exception" }
454 FAIL tests[i](nativeJSON) should be 0(number):[object Object]first, -> exception. Was 0(string):[object Object]first, -> exception.
455 function (jsonObject){
457 return jsonObject.stringify(magicObject) + " :: getter calls = " + getterCalls;
459 PASS tests[i](nativeJSON) is tests[i](JSON)
460 function (jsonObject){
461 return jsonObject.stringify(undefined);
463 PASS tests[i](nativeJSON) is tests[i](JSON)
464 function (jsonObject){
465 return jsonObject.stringify(null);
467 PASS tests[i](nativeJSON) is tests[i](JSON)
468 function (jsonObject){
469 return jsonObject.stringify({toJSON:function(){ return undefined; }});
471 PASS tests[i](nativeJSON) is tests[i](JSON)
472 function (jsonObject){
473 return jsonObject.stringify({toJSON:function(){ return null; }});
475 PASS tests[i](nativeJSON) is tests[i](JSON)
476 function (jsonObject){
477 return jsonObject.stringify([{toJSON:function(){ return undefined; }}]);
479 PASS tests[i](nativeJSON) is tests[i](JSON)
480 function (jsonObject){
481 return jsonObject.stringify([{toJSON:function(){ return null; }}]);
483 PASS tests[i](nativeJSON) is tests[i](JSON)
484 function (jsonObject){
485 return jsonObject.stringify({a:{toJSON:function(){ return undefined; }}});
487 PASS tests[i](nativeJSON) is tests[i](JSON)
488 function (jsonObject){
489 return jsonObject.stringify({a:{toJSON:function(){ return null; }}});
491 PASS tests[i](nativeJSON) is tests[i](JSON)
492 function (jsonObject){
493 return jsonObject.stringify({a:{toJSON:function(){ return function(){}; }}});
495 PASS tests[i](nativeJSON) is tests[i](JSON)
496 function (jsonObject){
497 return jsonObject.stringify({a:function(){}});
499 PASS tests[i](nativeJSON) is tests[i](JSON)
500 function (jsonObject){
502 for (var i = 0; i < 1024; i++)
503 deepObject = {next:deepObject};
504 return jsonObject.stringify(deepObject);
506 PASS tests[i](nativeJSON) is tests[i](JSON)
507 function (jsonObject){
509 for (var i = 0; i < 1024; i++)
510 deepArray = [deepArray];
511 return jsonObject.stringify(deepArray);
513 PASS tests[i](nativeJSON) is tests[i](JSON)
514 function (jsonObject){
516 function toDeepVirtualJSONObject() {
520 r.toJSON = toDeepVirtualJSONObject;
523 return jsonObject.stringify(toDeepVirtualJSONObject());
525 PASS tests[i](nativeJSON) is tests[i](JSON)
526 function (jsonObject){
528 function toDeepVirtualJSONArray() {
532 r.toJSON = toDeepJSONArray;
535 return jsonObject.stringify(toDeepVirtualJSONArray());
537 function (jsonObject){
538 return jsonObject.stringify(fullCharsetString);
540 PASS tests[i](nativeJSON) is tests[i](JSON)
541 PASS successfullyParsed is true