| 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 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 builder.push("[]"); | 184 builder.push("[]"); |
| 185 return; | 185 return; |
| 186 } | 186 } |
| 187 if (!%PushIfAbsent(stack, value)) { | 187 if (!%PushIfAbsent(stack, value)) { |
| 188 throw MakeTypeError('circular_structure', $Array()); | 188 throw MakeTypeError('circular_structure', $Array()); |
| 189 } | 189 } |
| 190 builder.push("["); | 190 builder.push("["); |
| 191 var val = value[0]; | 191 var val = value[0]; |
| 192 if (IS_STRING(val)) { | 192 if (IS_STRING(val)) { |
| 193 // First entry is a string. Remaining entries are likely to be strings too. | 193 // First entry is a string. Remaining entries are likely to be strings too. |
| 194 builder.push(%QuoteJSONString(val)); | 194 var array_string = %QuoteJSONStringArray(value); |
| 195 for (var i = 1; i < len; i++) { | 195 if (!IS_UNDEFINED(array_string)) { |
| 196 val = value[i]; | 196 builder[builder.length - 1] = array_string; |
| 197 if (IS_STRING(val)) { | 197 } else { |
| 198 builder.push(%QuoteJSONStringComma(val)); | 198 builder.push(%QuoteJSONString(val)); |
| 199 } else { | 199 for (var i = 1; i < len; i++) { |
| 200 builder.push(","); | 200 val = value[i]; |
| 201 var before = builder.length; | 201 if (IS_STRING(val)) { |
| 202 BasicJSONSerialize(i, value[i], stack, builder); | 202 builder.push(%QuoteJSONStringComma(val)); |
| 203 if (before == builder.length) builder[before - 1] = ",null"; | 203 } else { |
| 204 builder.push(","); |
| 205 var before = builder.length; |
| 206 BasicJSONSerialize(i, value[i], stack, builder); |
| 207 if (before == builder.length) builder[before - 1] = ",null"; |
| 208 } |
| 204 } | 209 } |
| 205 } | 210 } |
| 206 } else if (IS_NUMBER(val)) { | 211 } else if (IS_NUMBER(val)) { |
| 207 // First entry is a number. Remaining entries are likely to be numbers too. | 212 // First entry is a number. Remaining entries are likely to be numbers too. |
| 208 builder.push(NUMBER_IS_FINITE(val) ? %_NumberToString(val) : "null"); | 213 builder.push(NUMBER_IS_FINITE(val) ? %_NumberToString(val) : "null"); |
| 209 for (var i = 1; i < len; i++) { | 214 for (var i = 1; i < len; i++) { |
| 210 builder.push(","); | 215 builder.push(","); |
| 211 val = value[i]; | 216 val = value[i]; |
| 212 if (IS_NUMBER(val)) { | 217 if (IS_NUMBER(val)) { |
| 213 builder.push(NUMBER_IS_FINITE(val) | 218 builder.push(NUMBER_IS_FINITE(val) |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 333 } | 338 } |
| 334 | 339 |
| 335 function SetupJSON() { | 340 function SetupJSON() { |
| 336 InstallFunctions($JSON, DONT_ENUM, $Array( | 341 InstallFunctions($JSON, DONT_ENUM, $Array( |
| 337 "parse", JSONParse, | 342 "parse", JSONParse, |
| 338 "stringify", JSONStringify | 343 "stringify", JSONStringify |
| 339 )); | 344 )); |
| 340 } | 345 } |
| 341 | 346 |
| 342 SetupJSON(); | 347 SetupJSON(); |
| OLD | NEW |