OLD | NEW |
1 // Copyright 2009 the V8 project authors. All rights reserved. | 1 // Copyright 2009 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 (function(global, utils) { | 5 (function(global, utils) { |
6 | 6 |
7 "use strict"; | 7 "use strict"; |
8 | 8 |
9 %CheckIsBootstrapping(); | 9 %CheckIsBootstrapping(); |
10 | 10 |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 replacer = property_list; | 226 replacer = property_list; |
227 } | 227 } |
228 if (IS_OBJECT(space)) { | 228 if (IS_OBJECT(space)) { |
229 // Unwrap 'space' if it is wrapped | 229 // Unwrap 'space' if it is wrapped |
230 if (IS_NUMBER_WRAPPER(space)) { | 230 if (IS_NUMBER_WRAPPER(space)) { |
231 space = TO_NUMBER(space); | 231 space = TO_NUMBER(space); |
232 } else if (IS_STRING_WRAPPER(space)) { | 232 } else if (IS_STRING_WRAPPER(space)) { |
233 space = TO_STRING(space); | 233 space = TO_STRING(space); |
234 } | 234 } |
235 } | 235 } |
| 236 if (!IS_CALLABLE(replacer) && !property_list) { |
| 237 return %BasicJSONStringify(value, space); |
| 238 } |
236 var gap; | 239 var gap; |
237 if (IS_NUMBER(space)) { | 240 if (IS_NUMBER(space)) { |
238 space = MaxSimple(0, MinSimple(TO_INTEGER(space), 10)); | 241 space = MaxSimple(0, MinSimple(TO_INTEGER(space), 10)); |
239 gap = %_SubString(" ", 0, space); | 242 gap = %_SubString(" ", 0, space); |
240 } else if (IS_STRING(space)) { | 243 } else if (IS_STRING(space)) { |
241 if (space.length > 10) { | 244 if (space.length > 10) { |
242 gap = %_SubString(space, 0, 10); | 245 gap = %_SubString(space, 0, 10); |
243 } else { | 246 } else { |
244 gap = space; | 247 gap = space; |
245 } | 248 } |
246 } else { | 249 } else { |
247 gap = ""; | 250 gap = ""; |
248 } | 251 } |
249 if (!IS_CALLABLE(replacer) && !property_list) { | |
250 return %BasicJSONStringify(value, gap); | |
251 } | |
252 return JSONSerialize('', {'': value}, replacer, new Stack(), "", gap); | 252 return JSONSerialize('', {'': value}, replacer, new Stack(), "", gap); |
253 } | 253 } |
254 | 254 |
255 // ------------------------------------------------------------------- | 255 // ------------------------------------------------------------------- |
256 | 256 |
257 %AddNamedProperty(GlobalJSON, toStringTagSymbol, "JSON", READ_ONLY | DONT_ENUM); | 257 %AddNamedProperty(GlobalJSON, toStringTagSymbol, "JSON", READ_ONLY | DONT_ENUM); |
258 | 258 |
259 // Set up non-enumerable properties of the JSON object. | 259 // Set up non-enumerable properties of the JSON object. |
260 utils.InstallFunctions(GlobalJSON, DONT_ENUM, [ | 260 utils.InstallFunctions(GlobalJSON, DONT_ENUM, [ |
261 "parse", JSONParse, | 261 "parse", JSONParse, |
(...skipping 12 matching lines...) Expand all Loading... |
274 } | 274 } |
275 return o.toISOString(); | 275 return o.toISOString(); |
276 } | 276 } |
277 | 277 |
278 // Set up non-enumerable functions of the Date prototype object. | 278 // Set up non-enumerable functions of the Date prototype object. |
279 utils.InstallFunctions(GlobalDate.prototype, DONT_ENUM, [ | 279 utils.InstallFunctions(GlobalDate.prototype, DONT_ENUM, [ |
280 "toJSON", DateToJSON | 280 "toJSON", DateToJSON |
281 ]); | 281 ]); |
282 | 282 |
283 }) | 283 }) |
OLD | NEW |