| 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 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 return SerializeObject(value, replacer, stack, indent, gap); | 195 return SerializeObject(value, replacer, stack, indent, gap); |
| 196 } | 196 } |
| 197 } | 197 } |
| 198 // Undefined or a callable object. | 198 // Undefined or a callable object. |
| 199 return UNDEFINED; | 199 return UNDEFINED; |
| 200 } | 200 } |
| 201 | 201 |
| 202 | 202 |
| 203 function JSONStringify(value, replacer, space) { | 203 function JSONStringify(value, replacer, space) { |
| 204 if (arguments.length === 1 && !IS_PROXY(value)) { | 204 if (arguments.length === 1 && !IS_PROXY(value)) { |
| 205 return %BasicJSONStringify(value); | 205 return %BasicJSONStringify(value, ""); |
| 206 } | 206 } |
| 207 if (!IS_CALLABLE(replacer) && %is_arraylike(replacer)) { | 207 if (!IS_CALLABLE(replacer) && %is_arraylike(replacer)) { |
| 208 var property_list = new InternalArray(); | 208 var property_list = new InternalArray(); |
| 209 var seen_properties = new GlobalSet(); | 209 var seen_properties = new GlobalSet(); |
| 210 var length = TO_LENGTH(replacer.length); | 210 var length = TO_LENGTH(replacer.length); |
| 211 for (var i = 0; i < length; i++) { | 211 for (var i = 0; i < length; i++) { |
| 212 var v = replacer[i]; | 212 var v = replacer[i]; |
| 213 var item; | 213 var item; |
| 214 if (IS_STRING(v)) { | 214 if (IS_STRING(v)) { |
| 215 item = v; | 215 item = v; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 241 gap = %_SubString(" ", 0, space); | 241 gap = %_SubString(" ", 0, space); |
| 242 } else if (IS_STRING(space)) { | 242 } else if (IS_STRING(space)) { |
| 243 if (space.length > 10) { | 243 if (space.length > 10) { |
| 244 gap = %_SubString(space, 0, 10); | 244 gap = %_SubString(space, 0, 10); |
| 245 } else { | 245 } else { |
| 246 gap = space; | 246 gap = space; |
| 247 } | 247 } |
| 248 } else { | 248 } else { |
| 249 gap = ""; | 249 gap = ""; |
| 250 } | 250 } |
| 251 if (!IS_CALLABLE(replacer) && !property_list && !gap && !IS_PROXY(value)) { | 251 if (!IS_CALLABLE(replacer) && !property_list && !IS_PROXY(value)) { |
| 252 return %BasicJSONStringify(value); | 252 return %BasicJSONStringify(value, gap); |
| 253 } | 253 } |
| 254 return JSONSerialize('', {'': value}, replacer, new Stack(), "", gap); | 254 return JSONSerialize('', {'': value}, replacer, new Stack(), "", gap); |
| 255 } | 255 } |
| 256 | 256 |
| 257 // ------------------------------------------------------------------- | 257 // ------------------------------------------------------------------- |
| 258 | 258 |
| 259 %AddNamedProperty(GlobalJSON, toStringTagSymbol, "JSON", READ_ONLY | DONT_ENUM); | 259 %AddNamedProperty(GlobalJSON, toStringTagSymbol, "JSON", READ_ONLY | DONT_ENUM); |
| 260 | 260 |
| 261 // Set up non-enumerable properties of the JSON object. | 261 // Set up non-enumerable properties of the JSON object. |
| 262 utils.InstallFunctions(GlobalJSON, DONT_ENUM, [ | 262 utils.InstallFunctions(GlobalJSON, DONT_ENUM, [ |
| (...skipping 15 matching lines...) Expand all Loading... |
| 278 } | 278 } |
| 279 | 279 |
| 280 // Set up non-enumerable functions of the Date prototype object. | 280 // Set up non-enumerable functions of the Date prototype object. |
| 281 utils.InstallFunctions(GlobalDate.prototype, DONT_ENUM, [ | 281 utils.InstallFunctions(GlobalDate.prototype, DONT_ENUM, [ |
| 282 "toJSON", DateToJSON | 282 "toJSON", DateToJSON |
| 283 ]); | 283 ]); |
| 284 | 284 |
| 285 // ------------------------------------------------------------------- | 285 // ------------------------------------------------------------------- |
| 286 // JSON Builtins | 286 // JSON Builtins |
| 287 | 287 |
| 288 function JsonSerializeAdapter(key, object) { | 288 function JsonSerializeAdapter(key, object, indent, gap) { |
| 289 var holder = {}; | 289 var holder = {}; |
| 290 holder[key] = object; | 290 holder[key] = object; |
| 291 // No need to pass the actual holder since there is no replacer function. | 291 // No need to pass the actual holder since there is no replacer function. |
| 292 return JSONSerialize(key, holder, UNDEFINED, new Stack(), "", ""); | 292 var current_indent = ""; |
| 293 for (var i = 0; i < indent; i++) current_indent += gap; |
| 294 return JSONSerialize( |
| 295 key, holder, UNDEFINED, new Stack(), current_indent, gap); |
| 293 } | 296 } |
| 294 | 297 |
| 295 %InstallToContext(["json_serialize_adapter", JsonSerializeAdapter]); | 298 %InstallToContext(["json_serialize_adapter", JsonSerializeAdapter]); |
| 296 | 299 |
| 297 }) | 300 }) |
| OLD | NEW |