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 GlobalSet = global.Set; | 15 var GlobalSet = global.Set; |
16 var InternalArray = utils.InternalArray; | 16 var InternalArray = utils.InternalArray; |
17 var MakeTypeError; | 17 var MakeTypeError; |
18 var MaxSimple; | 18 var MaxSimple; |
19 var MinSimple; | 19 var MinSimple; |
20 var ObjectHasOwnProperty; | 20 var ObjectHasOwnProperty; |
21 var ObjectKeys; | |
22 var toStringTagSymbol = utils.ImportNow("to_string_tag_symbol"); | 21 var toStringTagSymbol = utils.ImportNow("to_string_tag_symbol"); |
23 | 22 |
24 utils.Import(function(from) { | 23 utils.Import(function(from) { |
25 MakeTypeError = from.MakeTypeError; | 24 MakeTypeError = from.MakeTypeError; |
26 MaxSimple = from.MaxSimple; | 25 MaxSimple = from.MaxSimple; |
27 MinSimple = from.MinSimple; | 26 MinSimple = from.MinSimple; |
28 ObjectHasOwnProperty = from.ObjectHasOwnProperty; | 27 ObjectHasOwnProperty = from.ObjectHasOwnProperty; |
29 ObjectKeys = from.ObjectKeys; | |
30 }); | 28 }); |
31 | 29 |
32 // ------------------------------------------------------------------- | 30 // ------------------------------------------------------------------- |
33 | 31 |
34 function CreateDataProperty(o, p, v) { | 32 function CreateDataProperty(o, p, v) { |
35 var desc = {value: v, enumerable: true, writable: true, configurable: true}; | 33 var desc = {value: v, enumerable: true, writable: true, configurable: true}; |
36 return %reflect_define_property(o, p, desc); | 34 return %reflect_define_property(o, p, desc); |
37 } | 35 } |
38 | 36 |
39 | 37 |
40 function InternalizeJSONProperty(holder, name, reviver) { | 38 function InternalizeJSONProperty(holder, name, reviver) { |
41 var val = holder[name]; | 39 var val = holder[name]; |
42 if (IS_RECEIVER(val)) { | 40 if (IS_RECEIVER(val)) { |
43 if (%is_arraylike(val)) { | 41 if (%is_arraylike(val)) { |
44 var length = TO_LENGTH(val.length); | 42 var length = TO_LENGTH(val.length); |
45 for (var i = 0; i < length; i++) { | 43 for (var i = 0; i < length; i++) { |
46 var newElement = | 44 var newElement = |
47 InternalizeJSONProperty(val, %_NumberToString(i), reviver); | 45 InternalizeJSONProperty(val, %_NumberToString(i), reviver); |
48 if (IS_UNDEFINED(newElement)) { | 46 if (IS_UNDEFINED(newElement)) { |
49 %reflect_delete_property(val, i); | 47 %reflect_delete_property(val, i); |
50 } else { | 48 } else { |
51 CreateDataProperty(val, i, newElement); | 49 CreateDataProperty(val, i, newElement); |
52 } | 50 } |
53 } | 51 } |
54 } else { | 52 } else { |
55 for (var p of ObjectKeys(val)) { | 53 for (var p of %object_keys(val)) { |
56 var newElement = InternalizeJSONProperty(val, p, reviver); | 54 var newElement = InternalizeJSONProperty(val, p, reviver); |
57 if (IS_UNDEFINED(newElement)) { | 55 if (IS_UNDEFINED(newElement)) { |
58 %reflect_delete_property(val, p); | 56 %reflect_delete_property(val, p); |
59 } else { | 57 } else { |
60 CreateDataProperty(val, p, newElement); | 58 CreateDataProperty(val, p, newElement); |
61 } | 59 } |
62 } | 60 } |
63 } | 61 } |
64 } | 62 } |
65 return %_Call(reviver, holder, name, val); | 63 return %_Call(reviver, holder, name, val); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 var p = replacer[i]; | 114 var p = replacer[i]; |
117 var strP = JSONSerialize(p, value, replacer, stack, indent, gap); | 115 var strP = JSONSerialize(p, value, replacer, stack, indent, gap); |
118 if (!IS_UNDEFINED(strP)) { | 116 if (!IS_UNDEFINED(strP)) { |
119 var member = %QuoteJSONString(p) + ":"; | 117 var member = %QuoteJSONString(p) + ":"; |
120 if (gap != "") member += " "; | 118 if (gap != "") member += " "; |
121 member += strP; | 119 member += strP; |
122 partial.push(member); | 120 partial.push(member); |
123 } | 121 } |
124 } | 122 } |
125 } else { | 123 } else { |
126 for (var p of ObjectKeys(value)) { | 124 for (var p of %object_keys(value)) { |
127 var strP = JSONSerialize(p, value, replacer, stack, indent, gap); | 125 var strP = JSONSerialize(p, value, replacer, stack, indent, gap); |
128 if (!IS_UNDEFINED(strP)) { | 126 if (!IS_UNDEFINED(strP)) { |
129 var member = %QuoteJSONString(p) + ":"; | 127 var member = %QuoteJSONString(p) + ":"; |
130 if (gap != "") member += " "; | 128 if (gap != "") member += " "; |
131 member += strP; | 129 member += strP; |
132 partial.push(member); | 130 partial.push(member); |
133 } | 131 } |
134 } | 132 } |
135 } | 133 } |
136 var final; | 134 var final; |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 function JsonSerializeAdapter(key, object) { | 252 function JsonSerializeAdapter(key, object) { |
255 var holder = {}; | 253 var holder = {}; |
256 holder[key] = object; | 254 holder[key] = object; |
257 // No need to pass the actual holder since there is no replacer function. | 255 // No need to pass the actual holder since there is no replacer function. |
258 return JSONSerialize(key, holder, UNDEFINED, new InternalArray(), "", ""); | 256 return JSONSerialize(key, holder, UNDEFINED, new InternalArray(), "", ""); |
259 } | 257 } |
260 | 258 |
261 %InstallToContext(["json_serialize_adapter", JsonSerializeAdapter]); | 259 %InstallToContext(["json_serialize_adapter", JsonSerializeAdapter]); |
262 | 260 |
263 }) | 261 }) |
OLD | NEW |