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 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 gap = %_SubString(space, 0, 10); | 206 gap = %_SubString(space, 0, 10); |
207 } else { | 207 } else { |
208 gap = space; | 208 gap = space; |
209 } | 209 } |
210 } else { | 210 } else { |
211 gap = ""; | 211 gap = ""; |
212 } | 212 } |
213 if (IS_ARRAY(replacer)) { | 213 if (IS_ARRAY(replacer)) { |
214 // Deduplicate replacer array items. | 214 // Deduplicate replacer array items. |
215 var property_list = new InternalArray(); | 215 var property_list = new InternalArray(); |
216 var seen_properties = {}; | 216 var seen_properties = { __proto__: null }; |
| 217 var seen_sentinel = {}; |
217 var length = replacer.length; | 218 var length = replacer.length; |
218 for (var i = 0; i < length; i++) { | 219 for (var i = 0; i < length; i++) { |
219 var item = replacer[i]; | 220 var item = replacer[i]; |
220 if (IS_NUMBER(item)) item = %_NumberToString(item); | 221 if (IS_STRING_WRAPPER(item)) { |
221 if (IS_STRING(item) && !(item in seen_properties)) { | 222 item = ToString(item); |
| 223 } else { |
| 224 if (IS_NUMBER_WRAPPER(item)) item = ToNumber(item); |
| 225 if (IS_NUMBER(item)) item = %_NumberToString(item); |
| 226 } |
| 227 if (IS_STRING(item) && seen_properties[item] != seen_sentinel) { |
222 property_list.push(item); | 228 property_list.push(item); |
223 seen_properties[item] = true; | 229 // We cannot use true here because __proto__ needs to be an object. |
| 230 seen_properties[item] = seen_sentinel; |
224 } | 231 } |
225 } | 232 } |
226 replacer = property_list; | 233 replacer = property_list; |
227 } | 234 } |
228 return JSONSerialize('', {'': value}, replacer, new InternalArray(), "", gap); | 235 return JSONSerialize('', {'': value}, replacer, new InternalArray(), "", gap); |
229 } | 236 } |
230 | 237 |
231 | 238 |
232 // ------------------------------------------------------------------- | 239 // ------------------------------------------------------------------- |
233 | 240 |
(...skipping 12 matching lines...) Expand all Loading... |
246 | 253 |
247 // ------------------------------------------------------------------- | 254 // ------------------------------------------------------------------- |
248 // JSON Builtins | 255 // JSON Builtins |
249 | 256 |
250 function JSONSerializeAdapter(key, object) { | 257 function JSONSerializeAdapter(key, object) { |
251 var holder = {}; | 258 var holder = {}; |
252 holder[key] = object; | 259 holder[key] = object; |
253 // No need to pass the actual holder since there is no replacer function. | 260 // No need to pass the actual holder since there is no replacer function. |
254 return JSONSerialize(key, holder, UNDEFINED, new InternalArray(), "", ""); | 261 return JSONSerialize(key, holder, UNDEFINED, new InternalArray(), "", ""); |
255 } | 262 } |
OLD | NEW |