OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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/objects.h" | 5 #include "src/objects.h" |
6 | 6 |
7 #include <cmath> | 7 #include <cmath> |
8 #include <iomanip> | 8 #include <iomanip> |
9 #include <memory> | 9 #include <memory> |
10 #include <sstream> | 10 #include <sstream> |
(...skipping 840 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
851 return isolate->factory()->undefined_value(); | 851 return isolate->factory()->undefined_value(); |
852 } | 852 } |
853 if (!func->IsCallable()) { | 853 if (!func->IsCallable()) { |
854 THROW_NEW_ERROR(isolate, NewTypeError(MessageTemplate::kPropertyNotFunction, | 854 THROW_NEW_ERROR(isolate, NewTypeError(MessageTemplate::kPropertyNotFunction, |
855 func, name, receiver), | 855 func, name, receiver), |
856 Object); | 856 Object); |
857 } | 857 } |
858 return func; | 858 return func; |
859 } | 859 } |
860 | 860 |
| 861 namespace { |
| 862 MaybeHandle<FixedArray> CreateListFromArrayLikeFastPath( |
| 863 Isolate* isolate, Handle<Object> object, ElementTypes element_types) { |
| 864 if (element_types != ElementTypes::kAll || !object->IsJSArray()) { |
| 865 return MaybeHandle<FixedArray>(); |
| 866 } |
| 867 Handle<JSArray> array = Handle<JSArray>::cast(object); |
| 868 uint32_t length; |
| 869 if (!array->HasArrayPrototype(isolate) || |
| 870 !array->length()->ToUint32(&length) || !array->HasFastElements() || |
| 871 !JSObject::PrototypeHasNoElements(isolate, *array)) { |
| 872 return MaybeHandle<FixedArray>(); |
| 873 } |
| 874 return array->GetElementsAccessor()->CreateListFromArray(isolate, array); |
| 875 } |
| 876 } // namespace |
861 | 877 |
862 // static | 878 // static |
863 MaybeHandle<FixedArray> Object::CreateListFromArrayLike( | 879 MaybeHandle<FixedArray> Object::CreateListFromArrayLike( |
864 Isolate* isolate, Handle<Object> object, ElementTypes element_types) { | 880 Isolate* isolate, Handle<Object> object, ElementTypes element_types) { |
| 881 // Fast-path for JS_ARRAY_TYPE. |
| 882 MaybeHandle<FixedArray> fast_result = |
| 883 CreateListFromArrayLikeFastPath(isolate, object, element_types); |
| 884 if (!fast_result.is_null()) return fast_result; |
865 // 1. ReturnIfAbrupt(object). | 885 // 1. ReturnIfAbrupt(object). |
866 // 2. (default elementTypes -- not applicable.) | 886 // 2. (default elementTypes -- not applicable.) |
867 // 3. If Type(obj) is not Object, throw a TypeError exception. | 887 // 3. If Type(obj) is not Object, throw a TypeError exception. |
868 if (!object->IsJSReceiver()) { | 888 if (!object->IsJSReceiver()) { |
869 THROW_NEW_ERROR(isolate, | 889 THROW_NEW_ERROR(isolate, |
870 NewTypeError(MessageTemplate::kCalledOnNonObject, | 890 NewTypeError(MessageTemplate::kCalledOnNonObject, |
871 isolate->factory()->NewStringFromAsciiChecked( | 891 isolate->factory()->NewStringFromAsciiChecked( |
872 "CreateListFromArrayLike")), | 892 "CreateListFromArrayLike")), |
873 FixedArray); | 893 FixedArray); |
874 } | 894 } |
| 895 |
875 // 4. Let len be ? ToLength(? Get(obj, "length")). | 896 // 4. Let len be ? ToLength(? Get(obj, "length")). |
876 Handle<JSReceiver> receiver = Handle<JSReceiver>::cast(object); | 897 Handle<JSReceiver> receiver = Handle<JSReceiver>::cast(object); |
877 Handle<Object> raw_length_number; | 898 Handle<Object> raw_length_number; |
878 ASSIGN_RETURN_ON_EXCEPTION(isolate, raw_length_number, | 899 ASSIGN_RETURN_ON_EXCEPTION(isolate, raw_length_number, |
879 Object::GetLengthFromArrayLike(isolate, receiver), | 900 Object::GetLengthFromArrayLike(isolate, receiver), |
880 FixedArray); | 901 FixedArray); |
881 uint32_t len; | 902 uint32_t len; |
882 if (!raw_length_number->ToUint32(&len) || | 903 if (!raw_length_number->ToUint32(&len) || |
883 len > static_cast<uint32_t>(FixedArray::kMaxLength)) { | 904 len > static_cast<uint32_t>(FixedArray::kMaxLength)) { |
884 THROW_NEW_ERROR(isolate, | 905 THROW_NEW_ERROR(isolate, |
(...skipping 19533 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
20418 // depend on this. | 20439 // depend on this. |
20419 return DICTIONARY_ELEMENTS; | 20440 return DICTIONARY_ELEMENTS; |
20420 } | 20441 } |
20421 DCHECK_LE(kind, LAST_ELEMENTS_KIND); | 20442 DCHECK_LE(kind, LAST_ELEMENTS_KIND); |
20422 return kind; | 20443 return kind; |
20423 } | 20444 } |
20424 } | 20445 } |
20425 | 20446 |
20426 } // namespace internal | 20447 } // namespace internal |
20427 } // namespace v8 | 20448 } // namespace v8 |
OLD | NEW |