| 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 var $jsonSerializeAdapter; | 5 var $jsonSerializeAdapter; |
| 6 | 6 |
| 7 (function() { | 7 (function() { |
| 8 | 8 |
| 9 "use strict"; | 9 "use strict"; |
| 10 | 10 |
| 11 %CheckIsBootstrapping(); | 11 %CheckIsBootstrapping(); |
| 12 | 12 |
| 13 var GlobalJSON = global.JSON; | 13 var GlobalJSON = global.JSON; |
| 14 | 14 |
| 15 // ------------------------------------------------------------------- | 15 // ------------------------------------------------------------------- |
| 16 | 16 |
| 17 function Revive(holder, name, reviver) { | 17 function Revive(holder, name, reviver) { |
| 18 var val = holder[name]; | 18 var val = holder[name]; |
| 19 if (IS_OBJECT(val)) { | 19 if (IS_OBJECT(val)) { |
| 20 if (IS_ARRAY(val)) { | 20 if (IS_ARRAY(val)) { |
| 21 var length = val.length; | 21 var length = val.length; |
| 22 for (var i = 0; i < length; i++) { | 22 for (var i = 0; i < length; i++) { |
| 23 var newElement = Revive(val, %_NumberToString(i), reviver); | 23 var newElement = Revive(val, %_NumberToString(i), reviver); |
| 24 val[i] = newElement; | 24 val[i] = newElement; |
| 25 } | 25 } |
| 26 } else { | 26 } else { |
| 27 for (var p in val) { | 27 for (var p in val) { |
| 28 if (%_CallFunction(val, p, ObjectHasOwnProperty)) { | 28 if (%_CallFunction(val, p, $objectHasOwnProperty)) { |
| 29 var newElement = Revive(val, p, reviver); | 29 var newElement = Revive(val, p, reviver); |
| 30 if (IS_UNDEFINED(newElement)) { | 30 if (IS_UNDEFINED(newElement)) { |
| 31 delete val[p]; | 31 delete val[p]; |
| 32 } else { | 32 } else { |
| 33 val[p] = newElement; | 33 val[p] = newElement; |
| 34 } | 34 } |
| 35 } | 35 } |
| 36 } | 36 } |
| 37 } | 37 } |
| 38 } | 38 } |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 function SerializeObject(value, replacer, stack, indent, gap) { | 84 function SerializeObject(value, replacer, stack, indent, gap) { |
| 85 if (!%PushIfAbsent(stack, value)) { | 85 if (!%PushIfAbsent(stack, value)) { |
| 86 throw MakeTypeError('circular_structure', []); | 86 throw MakeTypeError('circular_structure', []); |
| 87 } | 87 } |
| 88 var stepback = indent; | 88 var stepback = indent; |
| 89 indent += gap; | 89 indent += gap; |
| 90 var partial = new InternalArray(); | 90 var partial = new InternalArray(); |
| 91 if (IS_ARRAY(replacer)) { | 91 if (IS_ARRAY(replacer)) { |
| 92 var length = replacer.length; | 92 var length = replacer.length; |
| 93 for (var i = 0; i < length; i++) { | 93 for (var i = 0; i < length; i++) { |
| 94 if (%_CallFunction(replacer, i, ObjectHasOwnProperty)) { | 94 if (%_CallFunction(replacer, i, $objectHasOwnProperty)) { |
| 95 var p = replacer[i]; | 95 var p = replacer[i]; |
| 96 var strP = JSONSerialize(p, value, replacer, stack, indent, gap); | 96 var strP = JSONSerialize(p, value, replacer, stack, indent, gap); |
| 97 if (!IS_UNDEFINED(strP)) { | 97 if (!IS_UNDEFINED(strP)) { |
| 98 var member = %QuoteJSONString(p) + ":"; | 98 var member = %QuoteJSONString(p) + ":"; |
| 99 if (gap != "") member += " "; | 99 if (gap != "") member += " "; |
| 100 member += strP; | 100 member += strP; |
| 101 partial.push(member); | 101 partial.push(member); |
| 102 } | 102 } |
| 103 } | 103 } |
| 104 } | 104 } |
| 105 } else { | 105 } else { |
| 106 for (var p in value) { | 106 for (var p in value) { |
| 107 if (%_CallFunction(value, p, ObjectHasOwnProperty)) { | 107 if (%_CallFunction(value, p, $objectHasOwnProperty)) { |
| 108 var strP = JSONSerialize(p, value, replacer, stack, indent, gap); | 108 var strP = JSONSerialize(p, value, replacer, stack, indent, gap); |
| 109 if (!IS_UNDEFINED(strP)) { | 109 if (!IS_UNDEFINED(strP)) { |
| 110 var member = %QuoteJSONString(p) + ":"; | 110 var member = %QuoteJSONString(p) + ":"; |
| 111 if (gap != "") member += " "; | 111 if (gap != "") member += " "; |
| 112 member += strP; | 112 member += strP; |
| 113 partial.push(member); | 113 partial.push(member); |
| 114 } | 114 } |
| 115 } | 115 } |
| 116 } | 116 } |
| 117 } | 117 } |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 replacer = property_list; | 217 replacer = property_list; |
| 218 } | 218 } |
| 219 return JSONSerialize('', {'': value}, replacer, new InternalArray(), "", gap); | 219 return JSONSerialize('', {'': value}, replacer, new InternalArray(), "", gap); |
| 220 } | 220 } |
| 221 | 221 |
| 222 // ------------------------------------------------------------------- | 222 // ------------------------------------------------------------------- |
| 223 | 223 |
| 224 %AddNamedProperty(GlobalJSON, symbolToStringTag, "JSON", READ_ONLY | DONT_ENUM); | 224 %AddNamedProperty(GlobalJSON, symbolToStringTag, "JSON", READ_ONLY | DONT_ENUM); |
| 225 | 225 |
| 226 // Set up non-enumerable properties of the JSON object. | 226 // Set up non-enumerable properties of the JSON object. |
| 227 InstallFunctions(GlobalJSON, DONT_ENUM, [ | 227 $installFunctions(GlobalJSON, DONT_ENUM, [ |
| 228 "parse", JSONParse, | 228 "parse", JSONParse, |
| 229 "stringify", JSONStringify | 229 "stringify", JSONStringify |
| 230 ]); | 230 ]); |
| 231 | 231 |
| 232 // ------------------------------------------------------------------- | 232 // ------------------------------------------------------------------- |
| 233 // JSON Builtins | 233 // JSON Builtins |
| 234 | 234 |
| 235 $jsonSerializeAdapter = function(key, object) { | 235 $jsonSerializeAdapter = function(key, object) { |
| 236 var holder = {}; | 236 var holder = {}; |
| 237 holder[key] = object; | 237 holder[key] = object; |
| 238 // No need to pass the actual holder since there is no replacer function. | 238 // No need to pass the actual holder since there is no replacer function. |
| 239 return JSONSerialize(key, holder, UNDEFINED, new InternalArray(), "", ""); | 239 return JSONSerialize(key, holder, UNDEFINED, new InternalArray(), "", ""); |
| 240 } | 240 } |
| 241 | 241 |
| 242 })(); | 242 })(); |
| OLD | NEW |