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