OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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/builtins.h" | 5 #include "src/builtins.h" |
6 | 6 |
7 #include "src/api-arguments.h" | 7 #include "src/api-arguments.h" |
8 #include "src/api-natives.h" | 8 #include "src/api-natives.h" |
9 #include "src/api.h" | 9 #include "src/api.h" |
10 #include "src/base/once.h" | 10 #include "src/base/once.h" |
(...skipping 847 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
858 Isolate* isolate_; | 858 Isolate* isolate_; |
859 Handle<Object> storage_; // Always a global handle. | 859 Handle<Object> storage_; // Always a global handle. |
860 // Index after last seen index. Always less than or equal to | 860 // Index after last seen index. Always less than or equal to |
861 // JSObject::kMaxElementCount. | 861 // JSObject::kMaxElementCount. |
862 uint32_t index_offset_; | 862 uint32_t index_offset_; |
863 uint32_t bit_field_; | 863 uint32_t bit_field_; |
864 }; | 864 }; |
865 | 865 |
866 | 866 |
867 uint32_t EstimateElementCount(Handle<JSArray> array) { | 867 uint32_t EstimateElementCount(Handle<JSArray> array) { |
| 868 DisallowHeapAllocation no_gc; |
868 uint32_t length = static_cast<uint32_t>(array->length()->Number()); | 869 uint32_t length = static_cast<uint32_t>(array->length()->Number()); |
869 int element_count = 0; | 870 int element_count = 0; |
870 switch (array->GetElementsKind()) { | 871 switch (array->GetElementsKind()) { |
871 case FAST_SMI_ELEMENTS: | 872 case FAST_SMI_ELEMENTS: |
872 case FAST_HOLEY_SMI_ELEMENTS: | 873 case FAST_HOLEY_SMI_ELEMENTS: |
873 case FAST_ELEMENTS: | 874 case FAST_ELEMENTS: |
874 case FAST_HOLEY_ELEMENTS: { | 875 case FAST_HOLEY_ELEMENTS: { |
875 // Fast elements can't have lengths that are not representable by | 876 // Fast elements can't have lengths that are not representable by |
876 // a 32-bit signed integer. | 877 // a 32-bit signed integer. |
877 DCHECK(static_cast<int32_t>(FixedArray::kMaxLength) >= 0); | 878 DCHECK(static_cast<int32_t>(FixedArray::kMaxLength) >= 0); |
878 int fast_length = static_cast<int>(length); | 879 int fast_length = static_cast<int>(length); |
879 Isolate* isolate = array->GetIsolate(); | 880 Isolate* isolate = array->GetIsolate(); |
880 Handle<FixedArray> elements(FixedArray::cast(array->elements()), isolate); | 881 FixedArray* elements = FixedArray::cast(array->elements()); |
881 for (int i = 0; i < fast_length; i++) { | 882 for (int i = 0; i < fast_length; i++) { |
882 if (!elements->get(i)->IsTheHole(isolate)) element_count++; | 883 if (!elements->get(i)->IsTheHole(isolate)) element_count++; |
883 } | 884 } |
884 break; | 885 break; |
885 } | 886 } |
886 case FAST_DOUBLE_ELEMENTS: | 887 case FAST_DOUBLE_ELEMENTS: |
887 case FAST_HOLEY_DOUBLE_ELEMENTS: { | 888 case FAST_HOLEY_DOUBLE_ELEMENTS: { |
888 // Fast elements can't have lengths that are not representable by | 889 // Fast elements can't have lengths that are not representable by |
889 // a 32-bit signed integer. | 890 // a 32-bit signed integer. |
890 DCHECK(static_cast<int32_t>(FixedDoubleArray::kMaxLength) >= 0); | 891 DCHECK(static_cast<int32_t>(FixedDoubleArray::kMaxLength) >= 0); |
891 int fast_length = static_cast<int>(length); | 892 int fast_length = static_cast<int>(length); |
892 if (array->elements()->IsFixedArray()) { | 893 if (array->elements()->IsFixedArray()) { |
893 DCHECK(FixedArray::cast(array->elements())->length() == 0); | 894 DCHECK(FixedArray::cast(array->elements())->length() == 0); |
894 break; | 895 break; |
895 } | 896 } |
896 Handle<FixedDoubleArray> elements( | 897 FixedDoubleArray* elements = FixedDoubleArray::cast(array->elements()); |
897 FixedDoubleArray::cast(array->elements())); | |
898 for (int i = 0; i < fast_length; i++) { | 898 for (int i = 0; i < fast_length; i++) { |
899 if (!elements->is_the_hole(i)) element_count++; | 899 if (!elements->is_the_hole(i)) element_count++; |
900 } | 900 } |
901 break; | 901 break; |
902 } | 902 } |
903 case DICTIONARY_ELEMENTS: { | 903 case DICTIONARY_ELEMENTS: { |
904 Handle<SeededNumberDictionary> dictionary( | 904 SeededNumberDictionary* dictionary = |
905 SeededNumberDictionary::cast(array->elements())); | 905 SeededNumberDictionary::cast(array->elements()); |
| 906 Isolate* isolate = dictionary->GetIsolate(); |
906 int capacity = dictionary->Capacity(); | 907 int capacity = dictionary->Capacity(); |
907 for (int i = 0; i < capacity; i++) { | 908 for (int i = 0; i < capacity; i++) { |
908 Handle<Object> key(dictionary->KeyAt(i), array->GetIsolate()); | 909 Object* key = dictionary->KeyAt(i); |
909 if (dictionary->IsKey(*key)) { | 910 if (dictionary->IsKey(isolate, key)) { |
910 element_count++; | 911 element_count++; |
911 } | 912 } |
912 } | 913 } |
913 break; | 914 break; |
914 } | 915 } |
915 #define TYPED_ARRAY_CASE(Type, type, TYPE, ctype, size) case TYPE##_ELEMENTS: | 916 #define TYPED_ARRAY_CASE(Type, type, TYPE, ctype, size) case TYPE##_ELEMENTS: |
916 | 917 |
917 TYPED_ARRAYS(TYPED_ARRAY_CASE) | 918 TYPED_ARRAYS(TYPED_ARRAY_CASE) |
918 #undef TYPED_ARRAY_CASE | 919 #undef TYPED_ARRAY_CASE |
919 // External arrays are always dense. | 920 // External arrays are always dense. |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
976 indices->Add(i); | 977 indices->Add(i); |
977 } | 978 } |
978 } | 979 } |
979 break; | 980 break; |
980 } | 981 } |
981 case DICTIONARY_ELEMENTS: { | 982 case DICTIONARY_ELEMENTS: { |
982 DisallowHeapAllocation no_gc; | 983 DisallowHeapAllocation no_gc; |
983 SeededNumberDictionary* dict = | 984 SeededNumberDictionary* dict = |
984 SeededNumberDictionary::cast(object->elements()); | 985 SeededNumberDictionary::cast(object->elements()); |
985 uint32_t capacity = dict->Capacity(); | 986 uint32_t capacity = dict->Capacity(); |
986 Heap* heap = isolate->heap(); | |
987 Object* undefined = heap->undefined_value(); | |
988 Object* the_hole = heap->the_hole_value(); | |
989 FOR_WITH_HANDLE_SCOPE(isolate, uint32_t, j = 0, j, j < capacity, j++, { | 987 FOR_WITH_HANDLE_SCOPE(isolate, uint32_t, j = 0, j, j < capacity, j++, { |
990 Object* k = dict->KeyAt(j); | 988 Object* k = dict->KeyAt(j); |
991 if (k == undefined) continue; | 989 if (!dict->IsKey(isolate, k)) continue; |
992 if (k == the_hole) continue; | |
993 DCHECK(k->IsNumber()); | 990 DCHECK(k->IsNumber()); |
994 uint32_t index = static_cast<uint32_t>(k->Number()); | 991 uint32_t index = static_cast<uint32_t>(k->Number()); |
995 if (index < range) { | 992 if (index < range) { |
996 indices->Add(index); | 993 indices->Add(index); |
997 } | 994 } |
998 }); | 995 }); |
999 break; | 996 break; |
1000 } | 997 } |
1001 #define TYPED_ARRAY_CASE(Type, type, TYPE, ctype, size) case TYPE##_ELEMENTS: | 998 #define TYPED_ARRAY_CASE(Type, type, TYPE, ctype, size) case TYPE##_ELEMENTS: |
1002 | 999 |
(...skipping 4804 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5807 BUILTIN_LIST_T(DEFINE_BUILTIN_ACCESSOR_T) | 5804 BUILTIN_LIST_T(DEFINE_BUILTIN_ACCESSOR_T) |
5808 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H) | 5805 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H) |
5809 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) | 5806 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) |
5810 #undef DEFINE_BUILTIN_ACCESSOR_C | 5807 #undef DEFINE_BUILTIN_ACCESSOR_C |
5811 #undef DEFINE_BUILTIN_ACCESSOR_A | 5808 #undef DEFINE_BUILTIN_ACCESSOR_A |
5812 #undef DEFINE_BUILTIN_ACCESSOR_T | 5809 #undef DEFINE_BUILTIN_ACCESSOR_T |
5813 #undef DEFINE_BUILTIN_ACCESSOR_H | 5810 #undef DEFINE_BUILTIN_ACCESSOR_H |
5814 | 5811 |
5815 } // namespace internal | 5812 } // namespace internal |
5816 } // namespace v8 | 5813 } // namespace v8 |
OLD | NEW |