| 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 var $jsonSerializeAdapter; | 5 var $jsonSerializeAdapter; | 
| 6 | 6 | 
| 7 (function(global, utils) { | 7 (function(global, utils) { | 
| 8 | 8 | 
| 9 "use strict"; | 9 "use strict"; | 
| 10 | 10 | 
| 11 %CheckIsBootstrapping(); | 11 %CheckIsBootstrapping(); | 
| 12 | 12 | 
| 13 // ------------------------------------------------------------------- | 13 // ------------------------------------------------------------------- | 
| 14 // Imports | 14 // Imports | 
| 15 | 15 | 
| 16 var GlobalJSON = global.JSON; | 16 var GlobalJSON = global.JSON; | 
| 17 var InternalArray = utils.InternalArray; | 17 var InternalArray = utils.InternalArray; | 
| 18 | 18 | 
| 19 var MathMax; | 19 var MathMax; | 
| 20 var MathMin; | 20 var MathMin; | 
| 21 var ObjectHasOwnProperty; |  | 
| 22 | 21 | 
| 23 utils.Import(function(from) { | 22 utils.Import(function(from) { | 
| 24   MathMax = from.MathMax; | 23   MathMax = from.MathMax; | 
| 25   MathMin = from.MathMin; | 24   MathMin = from.MathMin; | 
| 26   ObjectHasOwnProperty = from.ObjectHasOwnProperty; |  | 
| 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++) { | 
| 37         var newElement = Revive(val, %_NumberToString(i), reviver); | 35         var newElement = Revive(val, %_NumberToString(i), reviver); | 
| 38         val[i] = newElement; | 36         val[i] = newElement; | 
| 39       } | 37       } | 
| 40     } else { | 38     } else { | 
| 41       for (var p in val) { | 39       for (var p in val) { | 
| 42         if (HAS_OWN_PROPERTY(val, p)) { | 40         if (%_CallFunction(val, p, $objectHasOwnProperty)) { | 
| 43           var newElement = Revive(val, p, reviver); | 41           var newElement = Revive(val, p, reviver); | 
| 44           if (IS_UNDEFINED(newElement)) { | 42           if (IS_UNDEFINED(newElement)) { | 
| 45             delete val[p]; | 43             delete val[p]; | 
| 46           } else { | 44           } else { | 
| 47             val[p] = newElement; | 45             val[p] = newElement; | 
| 48           } | 46           } | 
| 49         } | 47         } | 
| 50       } | 48       } | 
| 51     } | 49     } | 
| 52   } | 50   } | 
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 94 | 92 | 
| 95 | 93 | 
| 96 function SerializeObject(value, replacer, stack, indent, gap) { | 94 function SerializeObject(value, replacer, stack, indent, gap) { | 
| 97   if (!%PushIfAbsent(stack, value)) throw MakeTypeError(kCircularStructure); | 95   if (!%PushIfAbsent(stack, value)) throw MakeTypeError(kCircularStructure); | 
| 98   var stepback = indent; | 96   var stepback = indent; | 
| 99   indent += gap; | 97   indent += gap; | 
| 100   var partial = new InternalArray(); | 98   var partial = new InternalArray(); | 
| 101   if (IS_ARRAY(replacer)) { | 99   if (IS_ARRAY(replacer)) { | 
| 102     var length = replacer.length; | 100     var length = replacer.length; | 
| 103     for (var i = 0; i < length; i++) { | 101     for (var i = 0; i < length; i++) { | 
| 104       if (HAS_OWN_PROPERTY(replacer, i)) { | 102       if (%_CallFunction(replacer, i, $objectHasOwnProperty)) { | 
| 105         var p = replacer[i]; | 103         var p = replacer[i]; | 
| 106         var strP = JSONSerialize(p, value, replacer, stack, indent, gap); | 104         var strP = JSONSerialize(p, value, replacer, stack, indent, gap); | 
| 107         if (!IS_UNDEFINED(strP)) { | 105         if (!IS_UNDEFINED(strP)) { | 
| 108           var member = %QuoteJSONString(p) + ":"; | 106           var member = %QuoteJSONString(p) + ":"; | 
| 109           if (gap != "") member += " "; | 107           if (gap != "") member += " "; | 
| 110           member += strP; | 108           member += strP; | 
| 111           partial.push(member); | 109           partial.push(member); | 
| 112         } | 110         } | 
| 113       } | 111       } | 
| 114     } | 112     } | 
| 115   } else { | 113   } else { | 
| 116     for (var p in value) { | 114     for (var p in value) { | 
| 117       if (HAS_OWN_PROPERTY(value, p)) { | 115       if (%_CallFunction(value, p, $objectHasOwnProperty)) { | 
| 118         var strP = JSONSerialize(p, value, replacer, stack, indent, gap); | 116         var strP = JSONSerialize(p, value, replacer, stack, indent, gap); | 
| 119         if (!IS_UNDEFINED(strP)) { | 117         if (!IS_UNDEFINED(strP)) { | 
| 120           var member = %QuoteJSONString(p) + ":"; | 118           var member = %QuoteJSONString(p) + ":"; | 
| 121           if (gap != "") member += " "; | 119           if (gap != "") member += " "; | 
| 122           member += strP; | 120           member += strP; | 
| 123           partial.push(member); | 121           partial.push(member); | 
| 124         } | 122         } | 
| 125       } | 123       } | 
| 126     } | 124     } | 
| 127   } | 125   } | 
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 227     replacer = property_list; | 225     replacer = property_list; | 
| 228   } | 226   } | 
| 229   return JSONSerialize('', {'': value}, replacer, new InternalArray(), "", gap); | 227   return JSONSerialize('', {'': value}, replacer, new InternalArray(), "", gap); | 
| 230 } | 228 } | 
| 231 | 229 | 
| 232 // ------------------------------------------------------------------- | 230 // ------------------------------------------------------------------- | 
| 233 | 231 | 
| 234 %AddNamedProperty(GlobalJSON, symbolToStringTag, "JSON", READ_ONLY | DONT_ENUM); | 232 %AddNamedProperty(GlobalJSON, symbolToStringTag, "JSON", READ_ONLY | DONT_ENUM); | 
| 235 | 233 | 
| 236 // Set up non-enumerable properties of the JSON object. | 234 // Set up non-enumerable properties of the JSON object. | 
| 237 utils.InstallFunctions(GlobalJSON, DONT_ENUM, [ | 235 $installFunctions(GlobalJSON, DONT_ENUM, [ | 
| 238   "parse", JSONParse, | 236   "parse", JSONParse, | 
| 239   "stringify", JSONStringify | 237   "stringify", JSONStringify | 
| 240 ]); | 238 ]); | 
| 241 | 239 | 
| 242 // ------------------------------------------------------------------- | 240 // ------------------------------------------------------------------- | 
| 243 // JSON Builtins | 241 // JSON Builtins | 
| 244 | 242 | 
| 245 $jsonSerializeAdapter = function(key, object) { | 243 $jsonSerializeAdapter = function(key, object) { | 
| 246   var holder = {}; | 244   var holder = {}; | 
| 247   holder[key] = object; | 245   holder[key] = object; | 
| 248   // No need to pass the actual holder since there is no replacer function. | 246   // No need to pass the actual holder since there is no replacer function. | 
| 249   return JSONSerialize(key, holder, UNDEFINED, new InternalArray(), "", ""); | 247   return JSONSerialize(key, holder, UNDEFINED, new InternalArray(), "", ""); | 
| 250 } | 248 } | 
| 251 | 249 | 
| 252 }) | 250 }) | 
| OLD | NEW | 
|---|