| 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/elements.h" | 5 #include "src/elements.h" |
| 6 | 6 |
| 7 #include "src/arguments.h" | 7 #include "src/arguments.h" |
| 8 #include "src/conversions.h" | 8 #include "src/conversions.h" |
| 9 #include "src/factory.h" | 9 #include "src/factory.h" |
| 10 #include "src/messages.h" | 10 #include "src/messages.h" |
| (...skipping 536 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 547 backing_store, filter); | 547 backing_store, filter); |
| 548 } | 548 } |
| 549 | 549 |
| 550 static bool HasElementImpl(Handle<JSObject> holder, uint32_t index, | 550 static bool HasElementImpl(Handle<JSObject> holder, uint32_t index, |
| 551 Handle<FixedArrayBase> backing_store, | 551 Handle<FixedArrayBase> backing_store, |
| 552 PropertyFilter filter) { | 552 PropertyFilter filter) { |
| 553 return ElementsAccessorSubclass::GetEntryForIndexImpl( | 553 return ElementsAccessorSubclass::GetEntryForIndexImpl( |
| 554 *holder, *backing_store, index, filter) != kMaxUInt32; | 554 *holder, *backing_store, index, filter) != kMaxUInt32; |
| 555 } | 555 } |
| 556 | 556 |
| 557 bool HasAccessors(JSObject* holder) final { |
| 558 return ElementsAccessorSubclass::HasAccessorsImpl(holder, |
| 559 holder->elements()); |
| 560 } |
| 561 |
| 562 static bool HasAccessorsImpl(JSObject* holder, |
| 563 FixedArrayBase* backing_store) { |
| 564 return false; |
| 565 } |
| 566 |
| 557 Handle<Object> Get(Handle<JSObject> holder, uint32_t entry) final { | 567 Handle<Object> Get(Handle<JSObject> holder, uint32_t entry) final { |
| 558 return ElementsAccessorSubclass::GetImpl(holder, entry); | 568 return ElementsAccessorSubclass::GetImpl(holder, entry); |
| 559 } | 569 } |
| 560 | 570 |
| 561 static Handle<Object> GetImpl(Handle<JSObject> holder, uint32_t entry) { | 571 static Handle<Object> GetImpl(Handle<JSObject> holder, uint32_t entry) { |
| 562 return ElementsAccessorSubclass::GetImpl(holder->elements(), entry); | 572 return ElementsAccessorSubclass::GetImpl(holder->elements(), entry); |
| 563 } | 573 } |
| 564 | 574 |
| 565 static Handle<Object> GetImpl(FixedArrayBase* backing_store, uint32_t entry) { | 575 static Handle<Object> GetImpl(FixedArrayBase* backing_store, uint32_t entry) { |
| 566 Isolate* isolate = backing_store->GetIsolate(); | 576 Isolate* isolate = backing_store->GetIsolate(); |
| (...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1018 SeededNumberDictionary::cast(obj->elements())); | 1028 SeededNumberDictionary::cast(obj->elements())); |
| 1019 uint32_t index = GetIndexForEntryImpl(*dict, entry); | 1029 uint32_t index = GetIndexForEntryImpl(*dict, entry); |
| 1020 Handle<Object> result = SeededNumberDictionary::DeleteProperty(dict, entry); | 1030 Handle<Object> result = SeededNumberDictionary::DeleteProperty(dict, entry); |
| 1021 USE(result); | 1031 USE(result); |
| 1022 DCHECK(result->IsTrue()); | 1032 DCHECK(result->IsTrue()); |
| 1023 Handle<FixedArray> new_elements = | 1033 Handle<FixedArray> new_elements = |
| 1024 SeededNumberDictionary::Shrink(dict, index); | 1034 SeededNumberDictionary::Shrink(dict, index); |
| 1025 obj->set_elements(*new_elements); | 1035 obj->set_elements(*new_elements); |
| 1026 } | 1036 } |
| 1027 | 1037 |
| 1038 static bool HasAccessorsImpl(JSObject* holder, |
| 1039 FixedArrayBase* backing_store) { |
| 1040 SeededNumberDictionary* dict = SeededNumberDictionary::cast(backing_store); |
| 1041 if (!dict->requires_slow_elements()) return false; |
| 1042 int capacity = dict->Capacity(); |
| 1043 for (int i = 0; i < capacity; i++) { |
| 1044 Object* key = dict->KeyAt(i); |
| 1045 if (!dict->IsKey(key)) continue; |
| 1046 DCHECK(!dict->IsDeleted(i)); |
| 1047 PropertyDetails details = dict->DetailsAt(i); |
| 1048 if (details.type() == ACCESSOR_CONSTANT) return true; |
| 1049 } |
| 1050 return false; |
| 1051 } |
| 1052 |
| 1028 static Object* GetRaw(FixedArrayBase* store, uint32_t entry) { | 1053 static Object* GetRaw(FixedArrayBase* store, uint32_t entry) { |
| 1029 SeededNumberDictionary* backing_store = SeededNumberDictionary::cast(store); | 1054 SeededNumberDictionary* backing_store = SeededNumberDictionary::cast(store); |
| 1030 return backing_store->ValueAt(entry); | 1055 return backing_store->ValueAt(entry); |
| 1031 } | 1056 } |
| 1032 | 1057 |
| 1033 static Handle<Object> GetImpl(Handle<JSObject> holder, uint32_t entry) { | 1058 static Handle<Object> GetImpl(Handle<JSObject> holder, uint32_t entry) { |
| 1034 return GetImpl(holder->elements(), entry); | 1059 return GetImpl(holder->elements(), entry); |
| 1035 } | 1060 } |
| 1036 | 1061 |
| 1037 static Handle<Object> GetImpl(FixedArrayBase* backing_store, uint32_t entry) { | 1062 static Handle<Object> GetImpl(FixedArrayBase* backing_store, uint32_t entry) { |
| (...skipping 856 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1894 uint32_t entry) { | 1919 uint32_t entry) { |
| 1895 return PropertyDetails(DONT_DELETE, DATA, 0, PropertyCellType::kNoCell); | 1920 return PropertyDetails(DONT_DELETE, DATA, 0, PropertyCellType::kNoCell); |
| 1896 } | 1921 } |
| 1897 | 1922 |
| 1898 static bool HasElementImpl(Handle<JSObject> holder, uint32_t index, | 1923 static bool HasElementImpl(Handle<JSObject> holder, uint32_t index, |
| 1899 Handle<FixedArrayBase> backing_store, | 1924 Handle<FixedArrayBase> backing_store, |
| 1900 PropertyFilter filter) { | 1925 PropertyFilter filter) { |
| 1901 return index < AccessorClass::GetCapacityImpl(*holder, *backing_store); | 1926 return index < AccessorClass::GetCapacityImpl(*holder, *backing_store); |
| 1902 } | 1927 } |
| 1903 | 1928 |
| 1929 static bool HasAccessorsImpl(JSObject* holder, |
| 1930 FixedArrayBase* backing_store) { |
| 1931 return false; |
| 1932 } |
| 1933 |
| 1904 static void SetLengthImpl(Isolate* isolate, Handle<JSArray> array, | 1934 static void SetLengthImpl(Isolate* isolate, Handle<JSArray> array, |
| 1905 uint32_t length, | 1935 uint32_t length, |
| 1906 Handle<FixedArrayBase> backing_store) { | 1936 Handle<FixedArrayBase> backing_store) { |
| 1907 // External arrays do not support changing their length. | 1937 // External arrays do not support changing their length. |
| 1908 UNREACHABLE(); | 1938 UNREACHABLE(); |
| 1909 } | 1939 } |
| 1910 | 1940 |
| 1911 static void DeleteImpl(Handle<JSObject> obj, uint32_t entry) { | 1941 static void DeleteImpl(Handle<JSObject> obj, uint32_t entry) { |
| 1912 UNREACHABLE(); | 1942 UNREACHABLE(); |
| 1913 } | 1943 } |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2065 FixedArray* parameter_map = FixedArray::cast(parameters); | 2095 FixedArray* parameter_map = FixedArray::cast(parameters); |
| 2066 uint32_t length = parameter_map->length() - 2; | 2096 uint32_t length = parameter_map->length() - 2; |
| 2067 if (entry < length) { | 2097 if (entry < length) { |
| 2068 return !GetParameterMapArg(parameter_map, entry)->IsTheHole(); | 2098 return !GetParameterMapArg(parameter_map, entry)->IsTheHole(); |
| 2069 } | 2099 } |
| 2070 | 2100 |
| 2071 FixedArrayBase* arguments = FixedArrayBase::cast(parameter_map->get(1)); | 2101 FixedArrayBase* arguments = FixedArrayBase::cast(parameter_map->get(1)); |
| 2072 return ArgumentsAccessor::HasEntryImpl(arguments, entry - length); | 2102 return ArgumentsAccessor::HasEntryImpl(arguments, entry - length); |
| 2073 } | 2103 } |
| 2074 | 2104 |
| 2105 static bool HasAccessorsImpl(JSObject* holder, |
| 2106 FixedArrayBase* backing_store) { |
| 2107 FixedArray* parameter_map = FixedArray::cast(backing_store); |
| 2108 FixedArrayBase* arguments = FixedArrayBase::cast(parameter_map->get(1)); |
| 2109 return ArgumentsAccessor::HasAccessorsImpl(holder, arguments); |
| 2110 } |
| 2111 |
| 2075 static uint32_t GetIndexForEntryImpl(FixedArrayBase* parameters, | 2112 static uint32_t GetIndexForEntryImpl(FixedArrayBase* parameters, |
| 2076 uint32_t entry) { | 2113 uint32_t entry) { |
| 2077 FixedArray* parameter_map = FixedArray::cast(parameters); | 2114 FixedArray* parameter_map = FixedArray::cast(parameters); |
| 2078 uint32_t length = parameter_map->length() - 2; | 2115 uint32_t length = parameter_map->length() - 2; |
| 2079 if (entry < length) return entry; | 2116 if (entry < length) return entry; |
| 2080 | 2117 |
| 2081 FixedArray* arguments = FixedArray::cast(parameter_map->get(1)); | 2118 FixedArray* arguments = FixedArray::cast(parameter_map->get(1)); |
| 2082 return ArgumentsAccessor::GetIndexForEntryImpl(arguments, entry - length); | 2119 return ArgumentsAccessor::GetIndexForEntryImpl(arguments, entry - length); |
| 2083 } | 2120 } |
| 2084 | 2121 |
| (...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2455 | 2492 |
| 2456 class SlowStringWrapperElementsAccessor | 2493 class SlowStringWrapperElementsAccessor |
| 2457 : public StringWrapperElementsAccessor< | 2494 : public StringWrapperElementsAccessor< |
| 2458 SlowStringWrapperElementsAccessor, DictionaryElementsAccessor, | 2495 SlowStringWrapperElementsAccessor, DictionaryElementsAccessor, |
| 2459 ElementsKindTraits<SLOW_STRING_WRAPPER_ELEMENTS>> { | 2496 ElementsKindTraits<SLOW_STRING_WRAPPER_ELEMENTS>> { |
| 2460 public: | 2497 public: |
| 2461 explicit SlowStringWrapperElementsAccessor(const char* name) | 2498 explicit SlowStringWrapperElementsAccessor(const char* name) |
| 2462 : StringWrapperElementsAccessor< | 2499 : StringWrapperElementsAccessor< |
| 2463 SlowStringWrapperElementsAccessor, DictionaryElementsAccessor, | 2500 SlowStringWrapperElementsAccessor, DictionaryElementsAccessor, |
| 2464 ElementsKindTraits<SLOW_STRING_WRAPPER_ELEMENTS>>(name) {} | 2501 ElementsKindTraits<SLOW_STRING_WRAPPER_ELEMENTS>>(name) {} |
| 2502 |
| 2503 static bool HasAccessorsImpl(JSObject* holder, |
| 2504 FixedArrayBase* backing_store) { |
| 2505 return DictionaryElementsAccessor::HasAccessorsImpl(holder, backing_store); |
| 2506 } |
| 2465 }; | 2507 }; |
| 2466 | 2508 |
| 2467 } // namespace | 2509 } // namespace |
| 2468 | 2510 |
| 2469 | 2511 |
| 2470 void CheckArrayAbuse(Handle<JSObject> obj, const char* op, uint32_t index, | 2512 void CheckArrayAbuse(Handle<JSObject> obj, const char* op, uint32_t index, |
| 2471 bool allow_appending) { | 2513 bool allow_appending) { |
| 2472 DisallowHeapAllocation no_allocation; | 2514 DisallowHeapAllocation no_allocation; |
| 2473 Object* raw_length = NULL; | 2515 Object* raw_length = NULL; |
| 2474 const char* elements_type = "array"; | 2516 const char* elements_type = "array"; |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2677 } | 2719 } |
| 2678 } | 2720 } |
| 2679 | 2721 |
| 2680 DCHECK(j == result_len); | 2722 DCHECK(j == result_len); |
| 2681 return result_array; | 2723 return result_array; |
| 2682 } | 2724 } |
| 2683 | 2725 |
| 2684 ElementsAccessor** ElementsAccessor::elements_accessors_ = NULL; | 2726 ElementsAccessor** ElementsAccessor::elements_accessors_ = NULL; |
| 2685 } // namespace internal | 2727 } // namespace internal |
| 2686 } // namespace v8 | 2728 } // namespace v8 |
| OLD | NEW |