OLD | NEW |
1 // Copyright 2009 the V8 project authors. All rights reserved. | 1 // Copyright 2009 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
300 BasicSerializeArray(value, stack, builder); | 300 BasicSerializeArray(value, stack, builder); |
301 } else { | 301 } else { |
302 BasicSerializeObject(value, stack, builder); | 302 BasicSerializeObject(value, stack, builder); |
303 } | 303 } |
304 } | 304 } |
305 } | 305 } |
306 | 306 |
307 | 307 |
308 function JSONStringify(value, replacer, space) { | 308 function JSONStringify(value, replacer, space) { |
309 if (%_ArgumentsLength() == 1) { | 309 if (%_ArgumentsLength() == 1) { |
| 310 var result = %BasicJSONStringify(value); |
| 311 if (result != 0) return result; |
310 var builder = new InternalArray(); | 312 var builder = new InternalArray(); |
311 BasicJSONSerialize('', value, new InternalArray(), builder); | 313 BasicJSONSerialize('', value, new InternalArray(), builder); |
312 if (builder.length == 0) return; | 314 if (builder.length == 0) return; |
313 var result = %_FastAsciiArrayJoin(builder, ""); | 315 result = %_FastAsciiArrayJoin(builder, ""); |
314 if (!IS_UNDEFINED(result)) return result; | 316 if (!IS_UNDEFINED(result)) return result; |
315 return %StringBuilderConcat(builder, builder.length, ""); | 317 return %StringBuilderConcat(builder, builder.length, ""); |
316 } | 318 } |
317 if (IS_OBJECT(space)) { | 319 if (IS_OBJECT(space)) { |
318 // Unwrap 'space' if it is wrapped | 320 // Unwrap 'space' if it is wrapped |
319 if (IS_NUMBER_WRAPPER(space)) { | 321 if (IS_NUMBER_WRAPPER(space)) { |
320 space = ToNumber(space); | 322 space = ToNumber(space); |
321 } else if (IS_STRING_WRAPPER(space)) { | 323 } else if (IS_STRING_WRAPPER(space)) { |
322 space = ToString(space); | 324 space = ToString(space); |
323 } | 325 } |
(...skipping 16 matching lines...) Expand all Loading... |
340 | 342 |
341 function SetUpJSON() { | 343 function SetUpJSON() { |
342 %CheckIsBootstrapping(); | 344 %CheckIsBootstrapping(); |
343 InstallFunctions($JSON, DONT_ENUM, $Array( | 345 InstallFunctions($JSON, DONT_ENUM, $Array( |
344 "parse", JSONParse, | 346 "parse", JSONParse, |
345 "stringify", JSONStringify | 347 "stringify", JSONStringify |
346 )); | 348 )); |
347 } | 349 } |
348 | 350 |
349 SetUpJSON(); | 351 SetUpJSON(); |
OLD | NEW |