OLD | NEW |
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/code-stubs.h" | 8 #include "src/code-stubs.h" |
9 #include "src/conversions-inl.h" | 9 #include "src/conversions-inl.h" |
10 #include "src/elements.h" | 10 #include "src/elements.h" |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 // Returns an array that tells you where in the [0, length) interval an array | 176 // Returns an array that tells you where in the [0, length) interval an array |
177 // might have elements. Can either return an array of keys (positive integers | 177 // might have elements. Can either return an array of keys (positive integers |
178 // or undefined) or a number representing the positive length of an interval | 178 // or undefined) or a number representing the positive length of an interval |
179 // starting at index 0. | 179 // starting at index 0. |
180 // Intervals can span over some keys that are not in the object. | 180 // Intervals can span over some keys that are not in the object. |
181 RUNTIME_FUNCTION(Runtime_GetArrayKeys) { | 181 RUNTIME_FUNCTION(Runtime_GetArrayKeys) { |
182 HandleScope scope(isolate); | 182 HandleScope scope(isolate); |
183 DCHECK(args.length() == 2); | 183 DCHECK(args.length() == 2); |
184 CONVERT_ARG_HANDLE_CHECKED(JSObject, array, 0); | 184 CONVERT_ARG_HANDLE_CHECKED(JSObject, array, 0); |
185 CONVERT_NUMBER_CHECKED(uint32_t, length, Uint32, args[1]); | 185 CONVERT_NUMBER_CHECKED(uint32_t, length, Uint32, args[1]); |
| 186 ElementsKind kind = array->GetElementsKind(); |
186 | 187 |
187 if (array->HasFastStringWrapperElements()) { | 188 if (IsFastElementsKind(kind) || IsFixedTypedArrayElementsKind(kind)) { |
| 189 uint32_t actual_length = static_cast<uint32_t>(array->elements()->length()); |
| 190 return *isolate->factory()->NewNumberFromUint(Min(actual_length, length)); |
| 191 } |
| 192 |
| 193 if (kind == FAST_STRING_WRAPPER_ELEMENTS) { |
188 int string_length = | 194 int string_length = |
189 String::cast(Handle<JSValue>::cast(array)->value())->length(); | 195 String::cast(Handle<JSValue>::cast(array)->value())->length(); |
190 int backing_store_length = array->elements()->length(); | 196 int backing_store_length = array->elements()->length(); |
191 return *isolate->factory()->NewNumberFromUint( | 197 return *isolate->factory()->NewNumberFromUint( |
192 Min(length, | 198 Min(length, |
193 static_cast<uint32_t>(Max(string_length, backing_store_length)))); | 199 static_cast<uint32_t>(Max(string_length, backing_store_length)))); |
194 } | 200 } |
195 | 201 |
196 if (!array->elements()->IsDictionary()) { | |
197 CHECK(array->HasFastSmiOrObjectElements() || | |
198 array->HasFastDoubleElements()); | |
199 uint32_t actual_length = static_cast<uint32_t>(array->elements()->length()); | |
200 return *isolate->factory()->NewNumberFromUint(Min(actual_length, length)); | |
201 } | |
202 | |
203 KeyAccumulator accumulator(isolate, KeyCollectionMode::kOwnOnly, | 202 KeyAccumulator accumulator(isolate, KeyCollectionMode::kOwnOnly, |
204 ALL_PROPERTIES); | 203 ALL_PROPERTIES); |
205 // No need to separate prototype levels since we only get element keys. | |
206 for (PrototypeIterator iter(isolate, array, kStartAtReceiver); | 204 for (PrototypeIterator iter(isolate, array, kStartAtReceiver); |
207 !iter.IsAtEnd(); iter.Advance()) { | 205 !iter.IsAtEnd(); iter.Advance()) { |
208 if (PrototypeIterator::GetCurrent(iter)->IsJSProxy() || | 206 if (PrototypeIterator::GetCurrent(iter)->IsJSProxy() || |
209 PrototypeIterator::GetCurrent<JSObject>(iter) | 207 PrototypeIterator::GetCurrent<JSObject>(iter) |
210 ->HasIndexedInterceptor()) { | 208 ->HasIndexedInterceptor()) { |
211 // Bail out if we find a proxy or interceptor, likely not worth | 209 // Bail out if we find a proxy or interceptor, likely not worth |
212 // collecting keys in that case. | 210 // collecting keys in that case. |
213 return *isolate->factory()->NewNumberFromUint(length); | 211 return *isolate->factory()->NewNumberFromUint(length); |
214 } | 212 } |
215 Handle<JSObject> current = PrototypeIterator::GetCurrent<JSObject>(iter); | 213 Handle<JSObject> current = PrototypeIterator::GetCurrent<JSObject>(iter); |
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
502 RUNTIME_FUNCTION(Runtime_ArraySpeciesConstructor) { | 500 RUNTIME_FUNCTION(Runtime_ArraySpeciesConstructor) { |
503 HandleScope scope(isolate); | 501 HandleScope scope(isolate); |
504 DCHECK(args.length() == 1); | 502 DCHECK(args.length() == 1); |
505 CONVERT_ARG_HANDLE_CHECKED(Object, original_array, 0); | 503 CONVERT_ARG_HANDLE_CHECKED(Object, original_array, 0); |
506 RETURN_RESULT_OR_FAILURE( | 504 RETURN_RESULT_OR_FAILURE( |
507 isolate, Object::ArraySpeciesConstructor(isolate, original_array)); | 505 isolate, Object::ArraySpeciesConstructor(isolate, original_array)); |
508 } | 506 } |
509 | 507 |
510 } // namespace internal | 508 } // namespace internal |
511 } // namespace v8 | 509 } // namespace v8 |
OLD | NEW |