Chromium Code Reviews| 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 10 matching lines...) Expand all Loading... | |
| 21 | 21 |
| 22 utils.Import(function(from) { | 22 utils.Import(function(from) { |
| 23 MakeTypeError = from.MakeTypeError; | 23 MakeTypeError = from.MakeTypeError; |
| 24 MaxSimple = from.MaxSimple; | 24 MaxSimple = from.MaxSimple; |
| 25 MinSimple = from.MinSimple; | 25 MinSimple = from.MinSimple; |
| 26 ObjectHasOwnProperty = from.ObjectHasOwnProperty; | 26 ObjectHasOwnProperty = from.ObjectHasOwnProperty; |
| 27 }); | 27 }); |
| 28 | 28 |
| 29 // ------------------------------------------------------------------- | 29 // ------------------------------------------------------------------- |
| 30 | 30 |
| 31 function Revive(holder, name, reviver) { | 31 function InternalizeJSONProperty(holder, name, reviver) { |
| 32 var val = holder[name]; | 32 var val = holder[name]; |
| 33 if (IS_OBJECT(val)) { | 33 if (IS_OBJECT(val)) { |
| 34 if (IS_ARRAY(val)) { | 34 if (IS_ARRAY(val)) { |
|
Yang
2015/12/08 14:21:54
I thought IS_ARRAY is not the same as IsArray from
| |
| 35 var length = val.length; | 35 var length = val.length; |
| 36 for (var i = 0; i < length; i++) { | 36 for (var i = 0; i < length; i++) { |
| 37 var newElement = Revive(val, %_NumberToString(i), reviver); | 37 var newElement = |
| 38 val[i] = newElement; | 38 InternalizeJSONProperty(val, %_NumberToString(i), reviver); |
| 39 if (IS_UNDEFINED(newElement)) { | |
| 40 delete val[i]; | |
| 41 } else { | |
| 42 val[i] = newElement; | |
|
Yang
2015/12/08 14:21:54
is this equivalent to CreateDataProperty? What if
adamk
2015/12/09 23:49:20
What was the response to this comment? Perhaps thi
| |
| 43 } | |
| 39 } | 44 } |
| 40 } else { | 45 } else { |
| 41 for (var p in val) { | 46 for (var p in val) { |
| 42 if (HAS_OWN_PROPERTY(val, p)) { | 47 if (HAS_OWN_PROPERTY(val, p)) { |
| 43 var newElement = Revive(val, p, reviver); | 48 var newElement = InternalizeJSONProperty(val, p, reviver); |
| 44 if (IS_UNDEFINED(newElement)) { | 49 if (IS_UNDEFINED(newElement)) { |
| 45 delete val[p]; | 50 delete val[p]; |
| 46 } else { | 51 } else { |
| 47 val[p] = newElement; | 52 val[p] = newElement; |
| 48 } | 53 } |
| 49 } | 54 } |
| 50 } | 55 } |
| 51 } | 56 } |
| 52 } | 57 } |
| 53 return %_Call(reviver, holder, name, val); | 58 return %_Call(reviver, holder, name, val); |
| 54 } | 59 } |
| 55 | 60 |
| 56 | 61 |
| 57 function JSONParse(text, reviver) { | 62 function JSONParse(text, reviver) { |
| 58 var unfiltered = %ParseJson(text); | 63 var unfiltered = %ParseJson(text); |
| 59 if (IS_CALLABLE(reviver)) { | 64 if (IS_CALLABLE(reviver)) { |
| 60 return Revive({'': unfiltered}, '', reviver); | 65 return InternalizeJSONProperty({'': unfiltered}, '', reviver); |
| 61 } else { | 66 } else { |
| 62 return unfiltered; | 67 return unfiltered; |
| 63 } | 68 } |
| 64 } | 69 } |
| 65 | 70 |
| 66 | 71 |
| 67 function SerializeArray(value, replacer, stack, indent, gap) { | 72 function SerializeArray(value, replacer, stack, indent, gap) { |
| 68 if (!%PushIfAbsent(stack, value)) throw MakeTypeError(kCircularStructure); | 73 if (!%PushIfAbsent(stack, value)) throw MakeTypeError(kCircularStructure); |
| 69 var stepback = indent; | 74 var stepback = indent; |
| 70 indent += gap; | 75 indent += gap; |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 247 function JsonSerializeAdapter(key, object) { | 252 function JsonSerializeAdapter(key, object) { |
| 248 var holder = {}; | 253 var holder = {}; |
| 249 holder[key] = object; | 254 holder[key] = object; |
| 250 // 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. |
| 251 return JSONSerialize(key, holder, UNDEFINED, new InternalArray(), "", ""); | 256 return JSONSerialize(key, holder, UNDEFINED, new InternalArray(), "", ""); |
| 252 } | 257 } |
| 253 | 258 |
| 254 %InstallToContext(["json_serialize_adapter", JsonSerializeAdapter]); | 259 %InstallToContext(["json_serialize_adapter", JsonSerializeAdapter]); |
| 255 | 260 |
| 256 }) | 261 }) |
| OLD | NEW |