Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: src/array.js

Issue 5614004: Use the PushIfAbsent function for the JSON stringify stack.... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 10 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | src/json.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 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 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 var result = %_FastAsciiArrayJoin(elements, ""); 152 var result = %_FastAsciiArrayJoin(elements, "");
153 if (!IS_UNDEFINED(result)) return result; 153 if (!IS_UNDEFINED(result)) return result;
154 return %StringBuilderConcat(elements, elements_length, ''); 154 return %StringBuilderConcat(elements, elements_length, '');
155 } finally { 155 } finally {
156 // Make sure to pop the visited array no matter what happens. 156 // Make sure to pop the visited array no matter what happens.
157 if (is_array) visited_arrays.pop(); 157 if (is_array) visited_arrays.pop();
158 } 158 }
159 } 159 }
160 160
161 161
162 function ConvertToString(e) { 162 function ConvertToString(x) {
163 if (e == null) return ''; 163 if (IS_STRING(x)) return x;
164 else return ToString(e); 164 if (IS_NUMBER(x)) return %_NumberToString(x);
165 if (IS_BOOLEAN(x)) return x ? 'true' : 'false';
166 return (IS_NULL_OR_UNDEFINED(x)) ? '' : %ToString(%DefaultString(x));
165 } 167 }
166 168
167 169
168 function ConvertToLocaleString(e) { 170 function ConvertToLocaleString(e) {
169 if (e == null) { 171 // e_obj's toLocaleString might be overwritten, check if it is a function.
170 return ''; 172 // Call ConvertToString if toLocaleString is not a function.
171 } else { 173 // See issue 877615.
172 // e_obj's toLocaleString might be overwritten, check if it is a function. 174 var e_obj = ToObject(e);
173 // Call ToString if toLocaleString is not a function. 175 if (IS_FUNCTION(e_obj.toLocaleString))
174 // See issue 877615. 176 return ToString(e_obj.toLocaleString());
175 var e_obj = ToObject(e); 177 else
176 if (IS_FUNCTION(e_obj.toLocaleString)) 178 return ConvertToString(e);
177 return ToString(e_obj.toLocaleString());
178 else
179 return ToString(e);
180 }
181 } 179 }
182 180
183 181
184 // This function implements the optimized splice implementation that can use 182 // This function implements the optimized splice implementation that can use
185 // special array operations to handle sparse arrays in a sensible fashion. 183 // special array operations to handle sparse arrays in a sensible fashion.
186 function SmartSlice(array, start_i, del_count, len, deleted_elements) { 184 function SmartSlice(array, start_i, del_count, len, deleted_elements) {
187 // Move deleted elements to a new array (the return value from splice). 185 // Move deleted elements to a new array (the return value from splice).
188 // Intervals array can contain keys and intervals. See comment in Concat. 186 // Intervals array can contain keys and intervals. See comment in Concat.
189 var intervals = %GetArrayKeys(array, start_i + del_count); 187 var intervals = %GetArrayKeys(array, start_i + del_count);
190 var length = intervals.length; 188 var length = intervals.length;
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 throw new $TypeError('Array.prototype.toString is not generic'); 356 throw new $TypeError('Array.prototype.toString is not generic');
359 } 357 }
360 return Join(this, this.length, ',', ConvertToLocaleString); 358 return Join(this, this.length, ',', ConvertToLocaleString);
361 } 359 }
362 360
363 361
364 function ArrayJoin(separator) { 362 function ArrayJoin(separator) {
365 if (IS_UNDEFINED(separator)) { 363 if (IS_UNDEFINED(separator)) {
366 separator = ','; 364 separator = ',';
367 } else if (!IS_STRING(separator)) { 365 } else if (!IS_STRING(separator)) {
368 separator = ToString(separator); 366 separator = NonStringToString(separator);
369 } 367 }
370 368
371 var result = %_FastAsciiArrayJoin(this, separator); 369 var result = %_FastAsciiArrayJoin(this, separator);
372 if (!IS_UNDEFINED(result)) return result; 370 if (!IS_UNDEFINED(result)) return result;
373 371
374 var length = TO_UINT32(this.length); 372 return Join(this, TO_UINT32(this.length), separator, ConvertToString);
375 return Join(this, length, separator, ConvertToString);
376 } 373 }
377 374
378 375
379 // Removes the last element from the array and returns it. See 376 // Removes the last element from the array and returns it. See
380 // ECMA-262, section 15.4.4.6. 377 // ECMA-262, section 15.4.4.6.
381 function ArrayPop() { 378 function ArrayPop() {
382 var n = TO_UINT32(this.length); 379 var n = TO_UINT32(this.length);
383 if (n == 0) { 380 if (n == 0) {
384 this.length = n; 381 this.length = n;
385 return; 382 return;
(...skipping 785 matching lines...) Expand 10 before | Expand all | Expand 10 after
1171 "lastIndexOf", getFunction("lastIndexOf", ArrayLastIndexOf, 1), 1168 "lastIndexOf", getFunction("lastIndexOf", ArrayLastIndexOf, 1),
1172 "reduce", getFunction("reduce", ArrayReduce, 1), 1169 "reduce", getFunction("reduce", ArrayReduce, 1),
1173 "reduceRight", getFunction("reduceRight", ArrayReduceRight, 1) 1170 "reduceRight", getFunction("reduceRight", ArrayReduceRight, 1)
1174 )); 1171 ));
1175 1172
1176 %FinishArrayPrototypeSetup($Array.prototype); 1173 %FinishArrayPrototypeSetup($Array.prototype);
1177 } 1174 }
1178 1175
1179 1176
1180 SetupArray(); 1177 SetupArray();
OLDNEW
« no previous file with comments | « no previous file | src/json.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698