| 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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 } | 50 } |
| 51 } | 51 } |
| 52 } | 52 } |
| 53 } | 53 } |
| 54 return %_CallFunction(holder, name, val, reviver); | 54 return %_CallFunction(holder, name, val, reviver); |
| 55 } | 55 } |
| 56 | 56 |
| 57 | 57 |
| 58 function JSONParse(text, reviver) { | 58 function JSONParse(text, reviver) { |
| 59 var unfiltered = %ParseJson(TO_STRING_INLINE(text)); | 59 var unfiltered = %ParseJson(TO_STRING_INLINE(text)); |
| 60 if (IS_SPEC_FUNCTION(reviver)) { | 60 if (IS_CALLABLE(reviver)) { |
| 61 return Revive({'': unfiltered}, '', reviver); | 61 return Revive({'': unfiltered}, '', reviver); |
| 62 } else { | 62 } else { |
| 63 return unfiltered; | 63 return unfiltered; |
| 64 } | 64 } |
| 65 } | 65 } |
| 66 | 66 |
| 67 | 67 |
| 68 function SerializeArray(value, replacer, stack, indent, gap) { | 68 function SerializeArray(value, replacer, stack, indent, gap) { |
| 69 if (!%PushIfAbsent(stack, value)) throw MakeTypeError(kCircularStructure); | 69 if (!%PushIfAbsent(stack, value)) throw MakeTypeError(kCircularStructure); |
| 70 var stepback = indent; | 70 var stepback = indent; |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 } | 138 } |
| 139 stack.pop(); | 139 stack.pop(); |
| 140 return final; | 140 return final; |
| 141 } | 141 } |
| 142 | 142 |
| 143 | 143 |
| 144 function JSONSerialize(key, holder, replacer, stack, indent, gap) { | 144 function JSONSerialize(key, holder, replacer, stack, indent, gap) { |
| 145 var value = holder[key]; | 145 var value = holder[key]; |
| 146 if (IS_SPEC_OBJECT(value)) { | 146 if (IS_SPEC_OBJECT(value)) { |
| 147 var toJSON = value.toJSON; | 147 var toJSON = value.toJSON; |
| 148 if (IS_SPEC_FUNCTION(toJSON)) { | 148 if (IS_CALLABLE(toJSON)) { |
| 149 value = %_CallFunction(value, key, toJSON); | 149 value = %_CallFunction(value, key, toJSON); |
| 150 } | 150 } |
| 151 } | 151 } |
| 152 if (IS_SPEC_FUNCTION(replacer)) { | 152 if (IS_CALLABLE(replacer)) { |
| 153 value = %_CallFunction(holder, key, value, replacer); | 153 value = %_CallFunction(holder, key, value, replacer); |
| 154 } | 154 } |
| 155 if (IS_STRING(value)) { | 155 if (IS_STRING(value)) { |
| 156 return %QuoteJSONString(value); | 156 return %QuoteJSONString(value); |
| 157 } else if (IS_NUMBER(value)) { | 157 } else if (IS_NUMBER(value)) { |
| 158 return JSON_NUMBER_TO_STRING(value); | 158 return JSON_NUMBER_TO_STRING(value); |
| 159 } else if (IS_BOOLEAN(value)) { | 159 } else if (IS_BOOLEAN(value)) { |
| 160 return value ? "true" : "false"; | 160 return value ? "true" : "false"; |
| 161 } else if (IS_NULL(value)) { | 161 } else if (IS_NULL(value)) { |
| 162 return "null"; | 162 return "null"; |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 function JsonSerializeAdapter(key, object) { | 248 function JsonSerializeAdapter(key, object) { |
| 249 var holder = {}; | 249 var holder = {}; |
| 250 holder[key] = object; | 250 holder[key] = object; |
| 251 // No need to pass the actual holder since there is no replacer function. | 251 // No need to pass the actual holder since there is no replacer function. |
| 252 return JSONSerialize(key, holder, UNDEFINED, new InternalArray(), "", ""); | 252 return JSONSerialize(key, holder, UNDEFINED, new InternalArray(), "", ""); |
| 253 } | 253 } |
| 254 | 254 |
| 255 %InstallToContext(["json_serialize_adapter", JsonSerializeAdapter]); | 255 %InstallToContext(["json_serialize_adapter", JsonSerializeAdapter]); |
| 256 | 256 |
| 257 }) | 257 }) |
| OLD | NEW |