| 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, shared, exports) { | 7 (function(global, shared, exports) { |
| 8 | 8 |
| 9 "use strict"; | 9 "use strict"; |
| 10 | 10 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 var unfiltered = %ParseJson(TO_STRING_INLINE(text)); | 44 var unfiltered = %ParseJson(TO_STRING_INLINE(text)); |
| 45 if (IS_SPEC_FUNCTION(reviver)) { | 45 if (IS_SPEC_FUNCTION(reviver)) { |
| 46 return Revive({'': unfiltered}, '', reviver); | 46 return Revive({'': unfiltered}, '', reviver); |
| 47 } else { | 47 } else { |
| 48 return unfiltered; | 48 return unfiltered; |
| 49 } | 49 } |
| 50 } | 50 } |
| 51 | 51 |
| 52 | 52 |
| 53 function SerializeArray(value, replacer, stack, indent, gap) { | 53 function SerializeArray(value, replacer, stack, indent, gap) { |
| 54 if (!%PushIfAbsent(stack, value)) { | 54 if (!%PushIfAbsent(stack, value)) throw MakeTypeError(kCircularStructure); |
| 55 throw MakeTypeError('circular_structure', []); | |
| 56 } | |
| 57 var stepback = indent; | 55 var stepback = indent; |
| 58 indent += gap; | 56 indent += gap; |
| 59 var partial = new InternalArray(); | 57 var partial = new InternalArray(); |
| 60 var len = value.length; | 58 var len = value.length; |
| 61 for (var i = 0; i < len; i++) { | 59 for (var i = 0; i < len; i++) { |
| 62 var strP = JSONSerialize(%_NumberToString(i), value, replacer, stack, | 60 var strP = JSONSerialize(%_NumberToString(i), value, replacer, stack, |
| 63 indent, gap); | 61 indent, gap); |
| 64 if (IS_UNDEFINED(strP)) { | 62 if (IS_UNDEFINED(strP)) { |
| 65 strP = "null"; | 63 strP = "null"; |
| 66 } | 64 } |
| 67 partial.push(strP); | 65 partial.push(strP); |
| 68 } | 66 } |
| 69 var final; | 67 var final; |
| 70 if (gap == "") { | 68 if (gap == "") { |
| 71 final = "[" + partial.join(",") + "]"; | 69 final = "[" + partial.join(",") + "]"; |
| 72 } else if (partial.length > 0) { | 70 } else if (partial.length > 0) { |
| 73 var separator = ",\n" + indent; | 71 var separator = ",\n" + indent; |
| 74 final = "[\n" + indent + partial.join(separator) + "\n" + | 72 final = "[\n" + indent + partial.join(separator) + "\n" + |
| 75 stepback + "]"; | 73 stepback + "]"; |
| 76 } else { | 74 } else { |
| 77 final = "[]"; | 75 final = "[]"; |
| 78 } | 76 } |
| 79 stack.pop(); | 77 stack.pop(); |
| 80 return final; | 78 return final; |
| 81 } | 79 } |
| 82 | 80 |
| 83 | 81 |
| 84 function SerializeObject(value, replacer, stack, indent, gap) { | 82 function SerializeObject(value, replacer, stack, indent, gap) { |
| 85 if (!%PushIfAbsent(stack, value)) { | 83 if (!%PushIfAbsent(stack, value)) throw MakeTypeError(kCircularStructure); |
| 86 throw MakeTypeError('circular_structure', []); | |
| 87 } | |
| 88 var stepback = indent; | 84 var stepback = indent; |
| 89 indent += gap; | 85 indent += gap; |
| 90 var partial = new InternalArray(); | 86 var partial = new InternalArray(); |
| 91 if (IS_ARRAY(replacer)) { | 87 if (IS_ARRAY(replacer)) { |
| 92 var length = replacer.length; | 88 var length = replacer.length; |
| 93 for (var i = 0; i < length; i++) { | 89 for (var i = 0; i < length; i++) { |
| 94 if (%_CallFunction(replacer, i, $objectHasOwnProperty)) { | 90 if (%_CallFunction(replacer, i, $objectHasOwnProperty)) { |
| 95 var p = replacer[i]; | 91 var p = replacer[i]; |
| 96 var strP = JSONSerialize(p, value, replacer, stack, indent, gap); | 92 var strP = JSONSerialize(p, value, replacer, stack, indent, gap); |
| 97 if (!IS_UNDEFINED(strP)) { | 93 if (!IS_UNDEFINED(strP)) { |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 // JSON Builtins | 229 // JSON Builtins |
| 234 | 230 |
| 235 $jsonSerializeAdapter = function(key, object) { | 231 $jsonSerializeAdapter = function(key, object) { |
| 236 var holder = {}; | 232 var holder = {}; |
| 237 holder[key] = object; | 233 holder[key] = object; |
| 238 // No need to pass the actual holder since there is no replacer function. | 234 // No need to pass the actual holder since there is no replacer function. |
| 239 return JSONSerialize(key, holder, UNDEFINED, new InternalArray(), "", ""); | 235 return JSONSerialize(key, holder, UNDEFINED, new InternalArray(), "", ""); |
| 240 } | 236 } |
| 241 | 237 |
| 242 }) | 238 }) |
| OLD | NEW |