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

Side by Side Diff: src/runtime/runtime-array.cc

Issue 1670153002: Fix Array.prototype.sort for *_STRING_WRAPPER_ELEMENTS (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 10 months 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
« no previous file with comments | « src/objects.cc ('k') | test/mjsunit/regress/regress-crbug-584188.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 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 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 #include "src/runtime/runtime-utils.h" 5 #include "src/runtime/runtime-utils.h"
6 6
7 #include "src/arguments.h" 7 #include "src/arguments.h"
8 #include "src/conversions-inl.h" 8 #include "src/conversions-inl.h"
9 #include "src/elements.h" 9 #include "src/elements.h"
10 #include "src/factory.h" 10 #include "src/factory.h"
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 // might have elements. Can either return an array of keys (positive integers 192 // might have elements. Can either return an array of keys (positive integers
193 // or undefined) or a number representing the positive length of an interval 193 // or undefined) or a number representing the positive length of an interval
194 // starting at index 0. 194 // starting at index 0.
195 // Intervals can span over some keys that are not in the object. 195 // Intervals can span over some keys that are not in the object.
196 RUNTIME_FUNCTION(Runtime_GetArrayKeys) { 196 RUNTIME_FUNCTION(Runtime_GetArrayKeys) {
197 HandleScope scope(isolate); 197 HandleScope scope(isolate);
198 DCHECK(args.length() == 2); 198 DCHECK(args.length() == 2);
199 CONVERT_ARG_HANDLE_CHECKED(JSObject, array, 0); 199 CONVERT_ARG_HANDLE_CHECKED(JSObject, array, 0);
200 CONVERT_NUMBER_CHECKED(uint32_t, length, Uint32, args[1]); 200 CONVERT_NUMBER_CHECKED(uint32_t, length, Uint32, args[1]);
201 201
202 if (array->HasFastStringWrapperElements()) {
203 int string_length =
204 String::cast(Handle<JSValue>::cast(array)->value())->length();
205 int backing_store_length = array->elements()->length();
206 return *isolate->factory()->NewNumberFromUint(
207 Min(length,
208 static_cast<uint32_t>(Max(string_length, backing_store_length))));
209 }
210
202 if (!array->elements()->IsDictionary()) { 211 if (!array->elements()->IsDictionary()) {
203 RUNTIME_ASSERT(array->HasFastSmiOrObjectElements() || 212 RUNTIME_ASSERT(array->HasFastSmiOrObjectElements() ||
204 array->HasFastDoubleElements()); 213 array->HasFastDoubleElements());
205 uint32_t actual_length = static_cast<uint32_t>(array->elements()->length()); 214 uint32_t actual_length = static_cast<uint32_t>(array->elements()->length());
206 return *isolate->factory()->NewNumberFromUint(Min(actual_length, length)); 215 return *isolate->factory()->NewNumberFromUint(Min(actual_length, length));
207 } 216 }
208 217
209 KeyAccumulator accumulator(isolate, OWN_ONLY, ALL_PROPERTIES); 218 KeyAccumulator accumulator(isolate, OWN_ONLY, ALL_PROPERTIES);
210 // No need to separate protoype levels since we only get numbers/element keys 219 // No need to separate prototype levels since we only get element keys.
211 for (PrototypeIterator iter(isolate, array, 220 for (PrototypeIterator iter(isolate, array,
212 PrototypeIterator::START_AT_RECEIVER); 221 PrototypeIterator::START_AT_RECEIVER);
213 !iter.IsAtEnd(); iter.Advance()) { 222 !iter.IsAtEnd(); iter.Advance()) {
214 if (PrototypeIterator::GetCurrent(iter)->IsJSProxy() || 223 if (PrototypeIterator::GetCurrent(iter)->IsJSProxy() ||
215 PrototypeIterator::GetCurrent<JSObject>(iter) 224 PrototypeIterator::GetCurrent<JSObject>(iter)
216 ->HasIndexedInterceptor()) { 225 ->HasIndexedInterceptor()) {
217 // Bail out if we find a proxy or interceptor, likely not worth 226 // Bail out if we find a proxy or interceptor, likely not worth
218 // collecting keys in that case. 227 // collecting keys in that case.
219 return *isolate->factory()->NewNumberFromUint(length); 228 return *isolate->factory()->NewNumberFromUint(length);
220 } 229 }
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
495 CONVERT_ARG_HANDLE_CHECKED(Object, original_array, 0); 504 CONVERT_ARG_HANDLE_CHECKED(Object, original_array, 0);
496 Handle<Object> constructor; 505 Handle<Object> constructor;
497 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( 506 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
498 isolate, constructor, 507 isolate, constructor,
499 Object::ArraySpeciesConstructor(isolate, original_array)); 508 Object::ArraySpeciesConstructor(isolate, original_array));
500 return *constructor; 509 return *constructor;
501 } 510 }
502 511
503 } // namespace internal 512 } // namespace internal
504 } // namespace v8 513 } // namespace v8
OLDNEW
« no previous file with comments | « src/objects.cc ('k') | test/mjsunit/regress/regress-crbug-584188.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698