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 |
11 // ------------------------------------------------------------------- | 11 // ------------------------------------------------------------------- |
12 // Imports | 12 // Imports |
13 | 13 |
14 var GlobalJSON = global.JSON; | 14 var GlobalJSON = global.JSON; |
15 var InternalArray = utils.InternalArray; | 15 var InternalArray = utils.InternalArray; |
16 var MathMax; | 16 var MathMax; |
17 var MathMin; | 17 var MathMin; |
18 var ObjectHasOwnProperty; | 18 var ObjectHasOwnProperty; |
19 var ToNumber; | |
20 var toStringTagSymbol = utils.ImportNow("to_string_tag_symbol"); | 19 var toStringTagSymbol = utils.ImportNow("to_string_tag_symbol"); |
21 | 20 |
22 utils.Import(function(from) { | 21 utils.Import(function(from) { |
23 MathMax = from.MathMax; | 22 MathMax = from.MathMax; |
24 MathMin = from.MathMin; | 23 MathMin = from.MathMin; |
25 ObjectHasOwnProperty = from.ObjectHasOwnProperty; | 24 ObjectHasOwnProperty = from.ObjectHasOwnProperty; |
26 ToNumber = from.ToNumber; | |
27 }); | 25 }); |
28 | 26 |
29 // ------------------------------------------------------------------- | 27 // ------------------------------------------------------------------- |
30 | 28 |
31 function Revive(holder, name, reviver) { | 29 function Revive(holder, name, reviver) { |
32 var val = holder[name]; | 30 var val = holder[name]; |
33 if (IS_OBJECT(val)) { | 31 if (IS_OBJECT(val)) { |
34 if (IS_ARRAY(val)) { | 32 if (IS_ARRAY(val)) { |
35 var length = val.length; | 33 var length = val.length; |
36 for (var i = 0; i < length; i++) { | 34 for (var i = 0; i < length; i++) { |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 return JSON_NUMBER_TO_STRING(value); | 155 return JSON_NUMBER_TO_STRING(value); |
158 } else if (IS_BOOLEAN(value)) { | 156 } else if (IS_BOOLEAN(value)) { |
159 return value ? "true" : "false"; | 157 return value ? "true" : "false"; |
160 } else if (IS_NULL(value)) { | 158 } else if (IS_NULL(value)) { |
161 return "null"; | 159 return "null"; |
162 } else if (IS_SPEC_OBJECT(value) && !IS_CALLABLE(value)) { | 160 } else if (IS_SPEC_OBJECT(value) && !IS_CALLABLE(value)) { |
163 // Non-callable object. If it's a primitive wrapper, it must be unwrapped. | 161 // Non-callable object. If it's a primitive wrapper, it must be unwrapped. |
164 if (IS_ARRAY(value)) { | 162 if (IS_ARRAY(value)) { |
165 return SerializeArray(value, replacer, stack, indent, gap); | 163 return SerializeArray(value, replacer, stack, indent, gap); |
166 } else if (IS_NUMBER_WRAPPER(value)) { | 164 } else if (IS_NUMBER_WRAPPER(value)) { |
167 value = ToNumber(value); | 165 value = TO_NUMBER(value); |
168 return JSON_NUMBER_TO_STRING(value); | 166 return JSON_NUMBER_TO_STRING(value); |
169 } else if (IS_STRING_WRAPPER(value)) { | 167 } else if (IS_STRING_WRAPPER(value)) { |
170 return %QuoteJSONString(TO_STRING(value)); | 168 return %QuoteJSONString(TO_STRING(value)); |
171 } else if (IS_BOOLEAN_WRAPPER(value)) { | 169 } else if (IS_BOOLEAN_WRAPPER(value)) { |
172 return %_ValueOf(value) ? "true" : "false"; | 170 return %_ValueOf(value) ? "true" : "false"; |
173 } else { | 171 } else { |
174 return SerializeObject(value, replacer, stack, indent, gap); | 172 return SerializeObject(value, replacer, stack, indent, gap); |
175 } | 173 } |
176 } | 174 } |
177 // Undefined or a callable object. | 175 // Undefined or a callable object. |
(...skipping 25 matching lines...) Expand all Loading... |
203 if (!seen_properties[item]) { | 201 if (!seen_properties[item]) { |
204 property_list.push(item); | 202 property_list.push(item); |
205 seen_properties[item] = true; | 203 seen_properties[item] = true; |
206 } | 204 } |
207 } | 205 } |
208 replacer = property_list; | 206 replacer = property_list; |
209 } | 207 } |
210 if (IS_OBJECT(space)) { | 208 if (IS_OBJECT(space)) { |
211 // Unwrap 'space' if it is wrapped | 209 // Unwrap 'space' if it is wrapped |
212 if (IS_NUMBER_WRAPPER(space)) { | 210 if (IS_NUMBER_WRAPPER(space)) { |
213 space = ToNumber(space); | 211 space = TO_NUMBER(space); |
214 } else if (IS_STRING_WRAPPER(space)) { | 212 } else if (IS_STRING_WRAPPER(space)) { |
215 space = TO_STRING(space); | 213 space = TO_STRING(space); |
216 } | 214 } |
217 } | 215 } |
218 var gap; | 216 var gap; |
219 if (IS_NUMBER(space)) { | 217 if (IS_NUMBER(space)) { |
220 space = MathMax(0, MathMin(TO_INTEGER(space), 10)); | 218 space = MathMax(0, MathMin(TO_INTEGER(space), 10)); |
221 gap = %_SubString(" ", 0, space); | 219 gap = %_SubString(" ", 0, space); |
222 } else if (IS_STRING(space)) { | 220 } else if (IS_STRING(space)) { |
223 if (space.length > 10) { | 221 if (space.length > 10) { |
(...skipping 23 matching lines...) Expand all Loading... |
247 function JsonSerializeAdapter(key, object) { | 245 function JsonSerializeAdapter(key, object) { |
248 var holder = {}; | 246 var holder = {}; |
249 holder[key] = object; | 247 holder[key] = object; |
250 // No need to pass the actual holder since there is no replacer function. | 248 // No need to pass the actual holder since there is no replacer function. |
251 return JSONSerialize(key, holder, UNDEFINED, new InternalArray(), "", ""); | 249 return JSONSerialize(key, holder, UNDEFINED, new InternalArray(), "", ""); |
252 } | 250 } |
253 | 251 |
254 %InstallToContext(["json_serialize_adapter", JsonSerializeAdapter]); | 252 %InstallToContext(["json_serialize_adapter", JsonSerializeAdapter]); |
255 | 253 |
256 }) | 254 }) |
OLD | NEW |