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