| OLD | NEW |
| 1 // Copyright 2009 the V8 project authors. All rights reserved. | 1 // Copyright 2009 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 return unfiltered; | 60 return unfiltered; |
| 61 } | 61 } |
| 62 } | 62 } |
| 63 | 63 |
| 64 function SerializeArray(value, replacer, stack, indent, gap) { | 64 function SerializeArray(value, replacer, stack, indent, gap) { |
| 65 if (!%PushIfAbsent(stack, value)) { | 65 if (!%PushIfAbsent(stack, value)) { |
| 66 throw MakeTypeError('circular_structure', $Array()); | 66 throw MakeTypeError('circular_structure', $Array()); |
| 67 } | 67 } |
| 68 var stepback = indent; | 68 var stepback = indent; |
| 69 indent += gap; | 69 indent += gap; |
| 70 var partial = new InternalArray(); | 70 var partial = new InternalPackedArray(); |
| 71 var len = value.length; | 71 var len = value.length; |
| 72 for (var i = 0; i < len; i++) { | 72 for (var i = 0; i < len; i++) { |
| 73 var strP = JSONSerialize($String(i), value, replacer, stack, | 73 var strP = JSONSerialize($String(i), value, replacer, stack, |
| 74 indent, gap); | 74 indent, gap); |
| 75 if (IS_UNDEFINED(strP)) { | 75 if (IS_UNDEFINED(strP)) { |
| 76 strP = "null"; | 76 strP = "null"; |
| 77 } | 77 } |
| 78 partial.push(strP); | 78 partial.push(strP); |
| 79 } | 79 } |
| 80 var final; | 80 var final; |
| 81 if (gap == "") { | 81 if (gap == "") { |
| 82 final = "[" + partial.join(",") + "]"; | 82 final = "[" + partial.join(",") + "]"; |
| 83 } else if (partial.length > 0) { | 83 } else if (partial.length > 0) { |
| 84 var separator = ",\n" + indent; | 84 var separator = ",\n" + indent; |
| 85 final = "[\n" + indent + partial.join(separator) + "\n" + | 85 final = "[\n" + indent + partial.join(separator) + "\n" + |
| 86 stepback + "]"; | 86 stepback + "]"; |
| 87 } else { | 87 } else { |
| 88 final = "[]"; | 88 final = "[]"; |
| 89 } | 89 } |
| 90 stack.pop(); | 90 stack.pop(); |
| 91 return final; | 91 return final; |
| 92 } | 92 } |
| 93 | 93 |
| 94 function SerializeObject(value, replacer, stack, indent, gap) { | 94 function SerializeObject(value, replacer, stack, indent, gap) { |
| 95 if (!%PushIfAbsent(stack, value)) { | 95 if (!%PushIfAbsent(stack, value)) { |
| 96 throw MakeTypeError('circular_structure', $Array()); | 96 throw MakeTypeError('circular_structure', $Array()); |
| 97 } | 97 } |
| 98 var stepback = indent; | 98 var stepback = indent; |
| 99 indent += gap; | 99 indent += gap; |
| 100 var partial = new InternalArray(); | 100 var partial = new InternalPackedArray(); |
| 101 if (IS_ARRAY(replacer)) { | 101 if (IS_ARRAY(replacer)) { |
| 102 var length = replacer.length; | 102 var length = replacer.length; |
| 103 for (var i = 0; i < length; i++) { | 103 for (var i = 0; i < length; i++) { |
| 104 if (%_CallFunction(replacer, i, ObjectHasOwnProperty)) { | 104 if (%_CallFunction(replacer, i, ObjectHasOwnProperty)) { |
| 105 var p = replacer[i]; | 105 var p = replacer[i]; |
| 106 var strP = JSONSerialize(p, value, replacer, stack, indent, gap); | 106 var strP = JSONSerialize(p, value, replacer, stack, indent, gap); |
| 107 if (!IS_UNDEFINED(strP)) { | 107 if (!IS_UNDEFINED(strP)) { |
| 108 var member = %QuoteJSONString(p) + ":"; | 108 var member = %QuoteJSONString(p) + ":"; |
| 109 if (gap != "") member += " "; | 109 if (gap != "") member += " "; |
| 110 member += strP; | 110 member += strP; |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 | 217 |
| 218 | 218 |
| 219 function JSONSerializeAdapter(key, object) { | 219 function JSONSerializeAdapter(key, object) { |
| 220 var holder = {}; | 220 var holder = {}; |
| 221 holder[key] = object; | 221 holder[key] = object; |
| 222 // No need to pass the actual holder since there is no replacer function. | 222 // No need to pass the actual holder since there is no replacer function. |
| 223 return JSONSerialize(key, holder, void 0, new InternalArray(), "", ""); | 223 return JSONSerialize(key, holder, void 0, new InternalArray(), "", ""); |
| 224 } | 224 } |
| 225 | 225 |
| 226 SetUpJSON(); | 226 SetUpJSON(); |
| OLD | NEW |