OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 // - FixedUint8ElementsAccessor | 61 // - FixedUint8ElementsAccessor |
62 // - FixedInt8ElementsAccessor | 62 // - FixedInt8ElementsAccessor |
63 // - FixedUint16ElementsAccessor | 63 // - FixedUint16ElementsAccessor |
64 // - FixedInt16ElementsAccessor | 64 // - FixedInt16ElementsAccessor |
65 // - FixedUint32ElementsAccessor | 65 // - FixedUint32ElementsAccessor |
66 // - FixedInt32ElementsAccessor | 66 // - FixedInt32ElementsAccessor |
67 // - FixedFloat32ElementsAccessor | 67 // - FixedFloat32ElementsAccessor |
68 // - FixedFloat64ElementsAccessor | 68 // - FixedFloat64ElementsAccessor |
69 // - FixedUint8ClampedElementsAccessor | 69 // - FixedUint8ClampedElementsAccessor |
70 // - DictionaryElementsAccessor | 70 // - DictionaryElementsAccessor |
71 // - NonStrictArgumentsElementsAccessor | 71 // - SloppyArgumentsElementsAccessor |
72 | 72 |
73 | 73 |
74 namespace v8 { | 74 namespace v8 { |
75 namespace internal { | 75 namespace internal { |
76 | 76 |
77 | 77 |
78 static const int kPackedSizeNotKnown = -1; | 78 static const int kPackedSizeNotKnown = -1; |
79 | 79 |
80 | 80 |
81 // First argument in list is the accessor class, the second argument is the | 81 // First argument in list is the accessor class, the second argument is the |
82 // accessor ElementsKind, and the third is the backing store class. Use the | 82 // accessor ElementsKind, and the third is the backing store class. Use the |
83 // fast element handler for smi-only arrays. The implementation is currently | 83 // fast element handler for smi-only arrays. The implementation is currently |
84 // identical. Note that the order must match that of the ElementsKind enum for | 84 // identical. Note that the order must match that of the ElementsKind enum for |
85 // the |accessor_array[]| below to work. | 85 // the |accessor_array[]| below to work. |
86 #define ELEMENTS_LIST(V) \ | 86 #define ELEMENTS_LIST(V) \ |
87 V(FastPackedSmiElementsAccessor, FAST_SMI_ELEMENTS, FixedArray) \ | 87 V(FastPackedSmiElementsAccessor, FAST_SMI_ELEMENTS, FixedArray) \ |
88 V(FastHoleySmiElementsAccessor, FAST_HOLEY_SMI_ELEMENTS, \ | 88 V(FastHoleySmiElementsAccessor, FAST_HOLEY_SMI_ELEMENTS, \ |
89 FixedArray) \ | 89 FixedArray) \ |
90 V(FastPackedObjectElementsAccessor, FAST_ELEMENTS, FixedArray) \ | 90 V(FastPackedObjectElementsAccessor, FAST_ELEMENTS, FixedArray) \ |
91 V(FastHoleyObjectElementsAccessor, FAST_HOLEY_ELEMENTS, FixedArray) \ | 91 V(FastHoleyObjectElementsAccessor, FAST_HOLEY_ELEMENTS, FixedArray) \ |
92 V(FastPackedDoubleElementsAccessor, FAST_DOUBLE_ELEMENTS, \ | 92 V(FastPackedDoubleElementsAccessor, FAST_DOUBLE_ELEMENTS, \ |
93 FixedDoubleArray) \ | 93 FixedDoubleArray) \ |
94 V(FastHoleyDoubleElementsAccessor, FAST_HOLEY_DOUBLE_ELEMENTS, \ | 94 V(FastHoleyDoubleElementsAccessor, FAST_HOLEY_DOUBLE_ELEMENTS, \ |
95 FixedDoubleArray) \ | 95 FixedDoubleArray) \ |
96 V(DictionaryElementsAccessor, DICTIONARY_ELEMENTS, \ | 96 V(DictionaryElementsAccessor, DICTIONARY_ELEMENTS, \ |
97 SeededNumberDictionary) \ | 97 SeededNumberDictionary) \ |
98 V(NonStrictArgumentsElementsAccessor, NON_STRICT_ARGUMENTS_ELEMENTS, \ | 98 V(SloppyArgumentsElementsAccessor, SLOPPY_ARGUMENTS_ELEMENTS, \ |
99 FixedArray) \ | 99 FixedArray) \ |
100 V(ExternalInt8ElementsAccessor, EXTERNAL_INT8_ELEMENTS, \ | 100 V(ExternalInt8ElementsAccessor, EXTERNAL_INT8_ELEMENTS, \ |
101 ExternalInt8Array) \ | 101 ExternalInt8Array) \ |
102 V(ExternalUint8ElementsAccessor, \ | 102 V(ExternalUint8ElementsAccessor, \ |
103 EXTERNAL_UINT8_ELEMENTS, ExternalUint8Array) \ | 103 EXTERNAL_UINT8_ELEMENTS, ExternalUint8Array) \ |
104 V(ExternalInt16ElementsAccessor, EXTERNAL_INT16_ELEMENTS, \ | 104 V(ExternalInt16ElementsAccessor, EXTERNAL_INT16_ELEMENTS, \ |
105 ExternalInt16Array) \ | 105 ExternalInt16Array) \ |
106 V(ExternalUint16ElementsAccessor, \ | 106 V(ExternalUint16ElementsAccessor, \ |
107 EXTERNAL_UINT16_ELEMENTS, ExternalUint16Array) \ | 107 EXTERNAL_UINT16_ELEMENTS, ExternalUint16Array) \ |
108 V(ExternalInt32ElementsAccessor, EXTERNAL_INT32_ELEMENTS, \ | 108 V(ExternalInt32ElementsAccessor, EXTERNAL_INT32_ELEMENTS, \ |
(...skipping 804 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
913 typename KindTraits, | 913 typename KindTraits, |
914 int ElementSize> | 914 int ElementSize> |
915 class FastElementsAccessor | 915 class FastElementsAccessor |
916 : public ElementsAccessorBase<FastElementsAccessorSubclass, KindTraits> { | 916 : public ElementsAccessorBase<FastElementsAccessorSubclass, KindTraits> { |
917 public: | 917 public: |
918 explicit FastElementsAccessor(const char* name) | 918 explicit FastElementsAccessor(const char* name) |
919 : ElementsAccessorBase<FastElementsAccessorSubclass, | 919 : ElementsAccessorBase<FastElementsAccessorSubclass, |
920 KindTraits>(name) {} | 920 KindTraits>(name) {} |
921 protected: | 921 protected: |
922 friend class ElementsAccessorBase<FastElementsAccessorSubclass, KindTraits>; | 922 friend class ElementsAccessorBase<FastElementsAccessorSubclass, KindTraits>; |
923 friend class NonStrictArgumentsElementsAccessor; | 923 friend class SloppyArgumentsElementsAccessor; |
924 | 924 |
925 typedef typename KindTraits::BackingStore BackingStore; | 925 typedef typename KindTraits::BackingStore BackingStore; |
926 | 926 |
927 // Adjusts the length of the fast backing store or returns the new length or | 927 // Adjusts the length of the fast backing store or returns the new length or |
928 // undefined in case conversion to a slow backing store should be performed. | 928 // undefined in case conversion to a slow backing store should be performed. |
929 static MaybeObject* SetLengthWithoutNormalize(FixedArrayBase* backing_store, | 929 static MaybeObject* SetLengthWithoutNormalize(FixedArrayBase* backing_store, |
930 JSArray* array, | 930 JSArray* array, |
931 Object* length_object, | 931 Object* length_object, |
932 uint32_t length) { | 932 uint32_t length) { |
933 uint32_t old_capacity = backing_store->length(); | 933 uint32_t old_capacity = backing_store->length(); |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
991 ASSERT(obj->HasFastSmiOrObjectElements() || | 991 ASSERT(obj->HasFastSmiOrObjectElements() || |
992 obj->HasFastDoubleElements() || | 992 obj->HasFastDoubleElements() || |
993 obj->HasFastArgumentsElements()); | 993 obj->HasFastArgumentsElements()); |
994 Heap* heap = obj->GetHeap(); | 994 Heap* heap = obj->GetHeap(); |
995 Object* elements = obj->elements(); | 995 Object* elements = obj->elements(); |
996 if (elements == heap->empty_fixed_array()) { | 996 if (elements == heap->empty_fixed_array()) { |
997 return heap->true_value(); | 997 return heap->true_value(); |
998 } | 998 } |
999 typename KindTraits::BackingStore* backing_store = | 999 typename KindTraits::BackingStore* backing_store = |
1000 KindTraits::BackingStore::cast(elements); | 1000 KindTraits::BackingStore::cast(elements); |
1001 bool is_non_strict_arguments_elements_map = | 1001 bool is_sloppy_arguments_elements_map = |
1002 backing_store->map() == heap->non_strict_arguments_elements_map(); | 1002 backing_store->map() == heap->sloppy_arguments_elements_map(); |
1003 if (is_non_strict_arguments_elements_map) { | 1003 if (is_sloppy_arguments_elements_map) { |
1004 backing_store = KindTraits::BackingStore::cast( | 1004 backing_store = KindTraits::BackingStore::cast( |
1005 FixedArray::cast(backing_store)->get(1)); | 1005 FixedArray::cast(backing_store)->get(1)); |
1006 } | 1006 } |
1007 uint32_t length = static_cast<uint32_t>( | 1007 uint32_t length = static_cast<uint32_t>( |
1008 obj->IsJSArray() | 1008 obj->IsJSArray() |
1009 ? Smi::cast(JSArray::cast(obj)->length())->value() | 1009 ? Smi::cast(JSArray::cast(obj)->length())->value() |
1010 : backing_store->length()); | 1010 : backing_store->length()); |
1011 if (key < length) { | 1011 if (key < length) { |
1012 if (!is_non_strict_arguments_elements_map) { | 1012 if (!is_sloppy_arguments_elements_map) { |
1013 ElementsKind kind = KindTraits::Kind; | 1013 ElementsKind kind = KindTraits::Kind; |
1014 if (IsFastPackedElementsKind(kind)) { | 1014 if (IsFastPackedElementsKind(kind)) { |
1015 MaybeObject* transitioned = | 1015 MaybeObject* transitioned = |
1016 obj->TransitionElementsKind(GetHoleyElementsKind(kind)); | 1016 obj->TransitionElementsKind(GetHoleyElementsKind(kind)); |
1017 if (transitioned->IsFailure()) return transitioned; | 1017 if (transitioned->IsFailure()) return transitioned; |
1018 } | 1018 } |
1019 if (IsFastSmiOrObjectElementsKind(KindTraits::Kind)) { | 1019 if (IsFastSmiOrObjectElementsKind(KindTraits::Kind)) { |
1020 Object* writable; | 1020 Object* writable; |
1021 MaybeObject* maybe = obj->EnsureWritableFastElements(); | 1021 MaybeObject* maybe = obj->EnsureWritableFastElements(); |
1022 if (!maybe->ToObject(&writable)) return maybe; | 1022 if (!maybe->ToObject(&writable)) return maybe; |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1145 from, from_kind, from_start, to, to_kind, to_start, copy_size); | 1145 from, from_kind, from_start, to, to_kind, to_start, copy_size); |
1146 return to->GetHeap()->undefined_value(); | 1146 return to->GetHeap()->undefined_value(); |
1147 case FAST_DOUBLE_ELEMENTS: | 1147 case FAST_DOUBLE_ELEMENTS: |
1148 case FAST_HOLEY_DOUBLE_ELEMENTS: | 1148 case FAST_HOLEY_DOUBLE_ELEMENTS: |
1149 return CopyDoubleToObjectElements( | 1149 return CopyDoubleToObjectElements( |
1150 from, from_start, to, to_kind, to_start, copy_size); | 1150 from, from_start, to, to_kind, to_start, copy_size); |
1151 case DICTIONARY_ELEMENTS: | 1151 case DICTIONARY_ELEMENTS: |
1152 CopyDictionaryToObjectElements( | 1152 CopyDictionaryToObjectElements( |
1153 from, from_start, to, to_kind, to_start, copy_size); | 1153 from, from_start, to, to_kind, to_start, copy_size); |
1154 return to->GetHeap()->undefined_value(); | 1154 return to->GetHeap()->undefined_value(); |
1155 case NON_STRICT_ARGUMENTS_ELEMENTS: { | 1155 case SLOPPY_ARGUMENTS_ELEMENTS: { |
1156 // TODO(verwaest): This is a temporary hack to support extending | 1156 // TODO(verwaest): This is a temporary hack to support extending |
1157 // NON_STRICT_ARGUMENTS_ELEMENTS in SetFastElementsCapacityAndLength. | 1157 // SLOPPY_ARGUMENTS_ELEMENTS in SetFastElementsCapacityAndLength. |
1158 // This case should be UNREACHABLE(). | 1158 // This case should be UNREACHABLE(). |
1159 FixedArray* parameter_map = FixedArray::cast(from); | 1159 FixedArray* parameter_map = FixedArray::cast(from); |
1160 FixedArrayBase* arguments = FixedArrayBase::cast(parameter_map->get(1)); | 1160 FixedArrayBase* arguments = FixedArrayBase::cast(parameter_map->get(1)); |
1161 ElementsKind from_kind = ElementsKindForArray(arguments); | 1161 ElementsKind from_kind = ElementsKindForArray(arguments); |
1162 return CopyElementsImpl(arguments, from_start, to, from_kind, | 1162 return CopyElementsImpl(arguments, from_start, to, from_kind, |
1163 to_start, packed_size, copy_size); | 1163 to_start, packed_size, copy_size); |
1164 } | 1164 } |
1165 #define TYPED_ARRAY_CASE(Type, type, TYPE, ctype, size) \ | 1165 #define TYPED_ARRAY_CASE(Type, type, TYPE, ctype, size) \ |
1166 case EXTERNAL_##TYPE##_ELEMENTS: \ | 1166 case EXTERNAL_##TYPE##_ELEMENTS: \ |
1167 case TYPE##_ELEMENTS: \ | 1167 case TYPE##_ELEMENTS: \ |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1275 CopyDoubleToDoubleElements(from, from_start, to, to_start, copy_size); | 1275 CopyDoubleToDoubleElements(from, from_start, to, to_start, copy_size); |
1276 break; | 1276 break; |
1277 case FAST_ELEMENTS: | 1277 case FAST_ELEMENTS: |
1278 case FAST_HOLEY_ELEMENTS: | 1278 case FAST_HOLEY_ELEMENTS: |
1279 CopyObjectToDoubleElements(from, from_start, to, to_start, copy_size); | 1279 CopyObjectToDoubleElements(from, from_start, to, to_start, copy_size); |
1280 break; | 1280 break; |
1281 case DICTIONARY_ELEMENTS: | 1281 case DICTIONARY_ELEMENTS: |
1282 CopyDictionaryToDoubleElements( | 1282 CopyDictionaryToDoubleElements( |
1283 from, from_start, to, to_start, copy_size); | 1283 from, from_start, to, to_start, copy_size); |
1284 break; | 1284 break; |
1285 case NON_STRICT_ARGUMENTS_ELEMENTS: | 1285 case SLOPPY_ARGUMENTS_ELEMENTS: |
1286 UNREACHABLE(); | 1286 UNREACHABLE(); |
1287 | 1287 |
1288 #define TYPED_ARRAY_CASE(Type, type, TYPE, ctype, size) \ | 1288 #define TYPED_ARRAY_CASE(Type, type, TYPE, ctype, size) \ |
1289 case EXTERNAL_##TYPE##_ELEMENTS: \ | 1289 case EXTERNAL_##TYPE##_ELEMENTS: \ |
1290 case TYPE##_ELEMENTS: \ | 1290 case TYPE##_ELEMENTS: \ |
1291 UNREACHABLE(); | 1291 UNREACHABLE(); |
1292 TYPED_ARRAYS(TYPED_ARRAY_CASE) | 1292 TYPED_ARRAYS(TYPED_ARRAY_CASE) |
1293 #undef TYPED_ARRAY_CASE | 1293 #undef TYPED_ARRAY_CASE |
1294 } | 1294 } |
1295 return to->GetHeap()->undefined_value(); | 1295 return to->GetHeap()->undefined_value(); |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1485 } | 1485 } |
1486 | 1486 |
1487 MUST_USE_RESULT static MaybeObject* DeleteCommon( | 1487 MUST_USE_RESULT static MaybeObject* DeleteCommon( |
1488 JSObject* obj, | 1488 JSObject* obj, |
1489 uint32_t key, | 1489 uint32_t key, |
1490 JSReceiver::DeleteMode mode) { | 1490 JSReceiver::DeleteMode mode) { |
1491 Isolate* isolate = obj->GetIsolate(); | 1491 Isolate* isolate = obj->GetIsolate(); |
1492 Heap* heap = isolate->heap(); | 1492 Heap* heap = isolate->heap(); |
1493 FixedArray* backing_store = FixedArray::cast(obj->elements()); | 1493 FixedArray* backing_store = FixedArray::cast(obj->elements()); |
1494 bool is_arguments = | 1494 bool is_arguments = |
1495 (obj->GetElementsKind() == NON_STRICT_ARGUMENTS_ELEMENTS); | 1495 (obj->GetElementsKind() == SLOPPY_ARGUMENTS_ELEMENTS); |
1496 if (is_arguments) { | 1496 if (is_arguments) { |
1497 backing_store = FixedArray::cast(backing_store->get(1)); | 1497 backing_store = FixedArray::cast(backing_store->get(1)); |
1498 } | 1498 } |
1499 SeededNumberDictionary* dictionary = | 1499 SeededNumberDictionary* dictionary = |
1500 SeededNumberDictionary::cast(backing_store); | 1500 SeededNumberDictionary::cast(backing_store); |
1501 int entry = dictionary->FindEntry(key); | 1501 int entry = dictionary->FindEntry(key); |
1502 if (entry != SeededNumberDictionary::kNotFound) { | 1502 if (entry != SeededNumberDictionary::kNotFound) { |
1503 Object* result = dictionary->DeleteProperty(entry, mode); | 1503 Object* result = dictionary->DeleteProperty(entry, mode); |
1504 if (result == heap->false_value()) { | 1504 if (result == heap->false_value()) { |
1505 if (mode == JSObject::STRICT_DELETION) { | 1505 if (mode == JSObject::STRICT_DELETION) { |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1625 | 1625 |
1626 static uint32_t GetKeyForIndexImpl(FixedArrayBase* store, | 1626 static uint32_t GetKeyForIndexImpl(FixedArrayBase* store, |
1627 uint32_t index) { | 1627 uint32_t index) { |
1628 SeededNumberDictionary* dict = SeededNumberDictionary::cast(store); | 1628 SeededNumberDictionary* dict = SeededNumberDictionary::cast(store); |
1629 Object* key = dict->KeyAt(index); | 1629 Object* key = dict->KeyAt(index); |
1630 return Smi::cast(key)->value(); | 1630 return Smi::cast(key)->value(); |
1631 } | 1631 } |
1632 }; | 1632 }; |
1633 | 1633 |
1634 | 1634 |
1635 class NonStrictArgumentsElementsAccessor : public ElementsAccessorBase< | 1635 class SloppyArgumentsElementsAccessor : public ElementsAccessorBase< |
1636 NonStrictArgumentsElementsAccessor, | 1636 SloppyArgumentsElementsAccessor, |
1637 ElementsKindTraits<NON_STRICT_ARGUMENTS_ELEMENTS> > { | 1637 ElementsKindTraits<SLOPPY_ARGUMENTS_ELEMENTS> > { |
1638 public: | 1638 public: |
1639 explicit NonStrictArgumentsElementsAccessor(const char* name) | 1639 explicit SloppyArgumentsElementsAccessor(const char* name) |
1640 : ElementsAccessorBase< | 1640 : ElementsAccessorBase< |
1641 NonStrictArgumentsElementsAccessor, | 1641 SloppyArgumentsElementsAccessor, |
1642 ElementsKindTraits<NON_STRICT_ARGUMENTS_ELEMENTS> >(name) {} | 1642 ElementsKindTraits<SLOPPY_ARGUMENTS_ELEMENTS> >(name) {} |
1643 protected: | 1643 protected: |
1644 friend class ElementsAccessorBase< | 1644 friend class ElementsAccessorBase< |
1645 NonStrictArgumentsElementsAccessor, | 1645 SloppyArgumentsElementsAccessor, |
1646 ElementsKindTraits<NON_STRICT_ARGUMENTS_ELEMENTS> >; | 1646 ElementsKindTraits<SLOPPY_ARGUMENTS_ELEMENTS> >; |
1647 | 1647 |
1648 MUST_USE_RESULT static MaybeObject* GetImpl(Object* receiver, | 1648 MUST_USE_RESULT static MaybeObject* GetImpl(Object* receiver, |
1649 JSObject* obj, | 1649 JSObject* obj, |
1650 uint32_t key, | 1650 uint32_t key, |
1651 FixedArrayBase* parameters) { | 1651 FixedArrayBase* parameters) { |
1652 FixedArray* parameter_map = FixedArray::cast(parameters); | 1652 FixedArray* parameter_map = FixedArray::cast(parameters); |
1653 Object* probe = GetParameterMapArg(obj, parameter_map, key); | 1653 Object* probe = GetParameterMapArg(obj, parameter_map, key); |
1654 if (!probe->IsTheHole()) { | 1654 if (!probe->IsTheHole()) { |
1655 Context* context = Context::cast(parameter_map->get(0)); | 1655 Context* context = Context::cast(parameter_map->get(0)); |
1656 int context_index = Smi::cast(probe)->value(); | 1656 int context_index = Smi::cast(probe)->value(); |
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1992 UNREACHABLE(); | 1992 UNREACHABLE(); |
1993 break; | 1993 break; |
1994 } | 1994 } |
1995 | 1995 |
1996 array->set_elements(elms); | 1996 array->set_elements(elms); |
1997 array->set_length(Smi::FromInt(number_of_elements)); | 1997 array->set_length(Smi::FromInt(number_of_elements)); |
1998 return array; | 1998 return array; |
1999 } | 1999 } |
2000 | 2000 |
2001 } } // namespace v8::internal | 2001 } } // namespace v8::internal |
OLD | NEW |