| 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 21 matching lines...) Expand all Loading... |
| 32 // ------------------------------------------------------------------- | 32 // ------------------------------------------------------------------- |
| 33 | 33 |
| 34 function CreateDataProperty(o, p, v) { | 34 function CreateDataProperty(o, p, v) { |
| 35 var desc = {value: v, enumerable: true, writable: true, configurable: true}; | 35 var desc = {value: v, enumerable: true, writable: true, configurable: true}; |
| 36 return %reflect_define_property(o, p, desc); | 36 return %reflect_define_property(o, p, desc); |
| 37 } | 37 } |
| 38 | 38 |
| 39 | 39 |
| 40 function InternalizeJSONProperty(holder, name, reviver) { | 40 function InternalizeJSONProperty(holder, name, reviver) { |
| 41 var val = holder[name]; | 41 var val = holder[name]; |
| 42 if (IS_SPEC_OBJECT(val)) { | 42 if (IS_RECEIVER(val)) { |
| 43 if (%is_arraylike(val)) { | 43 if (%is_arraylike(val)) { |
| 44 var length = TO_LENGTH(val.length); | 44 var length = TO_LENGTH(val.length); |
| 45 for (var i = 0; i < length; i++) { | 45 for (var i = 0; i < length; i++) { |
| 46 var newElement = | 46 var newElement = |
| 47 InternalizeJSONProperty(val, %_NumberToString(i), reviver); | 47 InternalizeJSONProperty(val, %_NumberToString(i), reviver); |
| 48 if (IS_UNDEFINED(newElement)) { | 48 if (IS_UNDEFINED(newElement)) { |
| 49 %reflect_delete_property(val, i); | 49 %reflect_delete_property(val, i); |
| 50 } else { | 50 } else { |
| 51 CreateDataProperty(val, i, newElement); | 51 CreateDataProperty(val, i, newElement); |
| 52 } | 52 } |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 } else { | 143 } else { |
| 144 final = "{}"; | 144 final = "{}"; |
| 145 } | 145 } |
| 146 stack.pop(); | 146 stack.pop(); |
| 147 return final; | 147 return final; |
| 148 } | 148 } |
| 149 | 149 |
| 150 | 150 |
| 151 function JSONSerialize(key, holder, replacer, stack, indent, gap) { | 151 function JSONSerialize(key, holder, replacer, stack, indent, gap) { |
| 152 var value = holder[key]; | 152 var value = holder[key]; |
| 153 if (IS_SPEC_OBJECT(value)) { | 153 if (IS_RECEIVER(value)) { |
| 154 var toJSON = value.toJSON; | 154 var toJSON = value.toJSON; |
| 155 if (IS_CALLABLE(toJSON)) { | 155 if (IS_CALLABLE(toJSON)) { |
| 156 value = %_Call(toJSON, value, key); | 156 value = %_Call(toJSON, value, key); |
| 157 } | 157 } |
| 158 } | 158 } |
| 159 if (IS_CALLABLE(replacer)) { | 159 if (IS_CALLABLE(replacer)) { |
| 160 value = %_Call(replacer, holder, key, value); | 160 value = %_Call(replacer, holder, key, value); |
| 161 } | 161 } |
| 162 if (IS_STRING(value)) { | 162 if (IS_STRING(value)) { |
| 163 return %QuoteJSONString(value); | 163 return %QuoteJSONString(value); |
| 164 } else if (IS_NUMBER(value)) { | 164 } else if (IS_NUMBER(value)) { |
| 165 return JSON_NUMBER_TO_STRING(value); | 165 return JSON_NUMBER_TO_STRING(value); |
| 166 } else if (IS_BOOLEAN(value)) { | 166 } else if (IS_BOOLEAN(value)) { |
| 167 return value ? "true" : "false"; | 167 return value ? "true" : "false"; |
| 168 } else if (IS_NULL(value)) { | 168 } else if (IS_NULL(value)) { |
| 169 return "null"; | 169 return "null"; |
| 170 } else if (IS_SPEC_OBJECT(value) && !IS_CALLABLE(value)) { | 170 } else if (IS_RECEIVER(value) && !IS_CALLABLE(value)) { |
| 171 // Non-callable object. If it's a primitive wrapper, it must be unwrapped. | 171 // Non-callable object. If it's a primitive wrapper, it must be unwrapped. |
| 172 if (%is_arraylike(value)) { | 172 if (%is_arraylike(value)) { |
| 173 return SerializeArray(value, replacer, stack, indent, gap); | 173 return SerializeArray(value, replacer, stack, indent, gap); |
| 174 } else if (IS_NUMBER_WRAPPER(value)) { | 174 } else if (IS_NUMBER_WRAPPER(value)) { |
| 175 value = TO_NUMBER(value); | 175 value = TO_NUMBER(value); |
| 176 return JSON_NUMBER_TO_STRING(value); | 176 return JSON_NUMBER_TO_STRING(value); |
| 177 } else if (IS_STRING_WRAPPER(value)) { | 177 } else if (IS_STRING_WRAPPER(value)) { |
| 178 return %QuoteJSONString(TO_STRING(value)); | 178 return %QuoteJSONString(TO_STRING(value)); |
| 179 } else if (IS_BOOLEAN_WRAPPER(value)) { | 179 } else if (IS_BOOLEAN_WRAPPER(value)) { |
| 180 return %_ValueOf(value) ? "true" : "false"; | 180 return %_ValueOf(value) ? "true" : "false"; |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 function JsonSerializeAdapter(key, object) { | 254 function JsonSerializeAdapter(key, object) { |
| 255 var holder = {}; | 255 var holder = {}; |
| 256 holder[key] = object; | 256 holder[key] = object; |
| 257 // No need to pass the actual holder since there is no replacer function. | 257 // No need to pass the actual holder since there is no replacer function. |
| 258 return JSONSerialize(key, holder, UNDEFINED, new InternalArray(), "", ""); | 258 return JSONSerialize(key, holder, UNDEFINED, new InternalArray(), "", ""); |
| 259 } | 259 } |
| 260 | 260 |
| 261 %InstallToContext(["json_serialize_adapter", JsonSerializeAdapter]); | 261 %InstallToContext(["json_serialize_adapter", JsonSerializeAdapter]); |
| 262 | 262 |
| 263 }) | 263 }) |
| OLD | NEW |