Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Side by Side Diff: src/elements.cc

Issue 2521043005: [elements] Add CreateFromArrayLike fast-path for JS_ARRAY_TYPE (Closed)
Patch Set: avoid unnecessary writes Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/isolate-inl.h" 10 #include "src/isolate-inl.h"
(...skipping 585 matching lines...) Expand 10 before | Expand all | Expand 10 after
596 bool HasElement(Handle<JSObject> holder, uint32_t index, 596 bool HasElement(Handle<JSObject> holder, uint32_t index,
597 Handle<FixedArrayBase> backing_store, 597 Handle<FixedArrayBase> backing_store,
598 PropertyFilter filter) final { 598 PropertyFilter filter) final {
599 return Subclass::HasElementImpl(holder->GetIsolate(), holder, index, 599 return Subclass::HasElementImpl(holder->GetIsolate(), holder, index,
600 backing_store, filter); 600 backing_store, filter);
601 } 601 }
602 602
603 static bool HasElementImpl(Isolate* isolate, Handle<JSObject> holder, 603 static bool HasElementImpl(Isolate* isolate, Handle<JSObject> holder,
604 uint32_t index, 604 uint32_t index,
605 Handle<FixedArrayBase> backing_store, 605 Handle<FixedArrayBase> backing_store,
606 PropertyFilter filter) { 606 PropertyFilter filter = ALL_PROPERTIES) {
607 return Subclass::GetEntryForIndexImpl(isolate, *holder, *backing_store, 607 return Subclass::GetEntryForIndexImpl(isolate, *holder, *backing_store,
608 index, filter) != kMaxUInt32; 608 index, filter) != kMaxUInt32;
609 } 609 }
610 610
611 bool HasAccessors(JSObject* holder) final { 611 bool HasAccessors(JSObject* holder) final {
612 return Subclass::HasAccessorsImpl(holder, holder->elements()); 612 return Subclass::HasAccessorsImpl(holder, holder->elements());
613 } 613 }
614 614
615 static bool HasAccessorsImpl(JSObject* holder, 615 static bool HasAccessorsImpl(JSObject* holder,
616 FixedArrayBase* backing_store) { 616 FixedArrayBase* backing_store) {
617 return false; 617 return false;
618 } 618 }
619 619
620 Handle<Object> Get(Handle<JSObject> holder, uint32_t entry) final { 620 Handle<Object> Get(Handle<JSObject> holder, uint32_t entry) final {
621 return Subclass::GetImpl(holder, entry); 621 return Subclass::GetInternalImpl(holder, entry);
622 } 622 }
623 623
624 static Handle<Object> GetImpl(Handle<JSObject> holder, uint32_t entry) { 624 static Handle<Object> GetInternalImpl(Handle<JSObject> holder,
625 return Subclass::GetImpl(holder->elements(), entry); 625 uint32_t entry) {
626 return Subclass::GetImpl(holder->GetIsolate(), holder->elements(), entry);
626 } 627 }
627 628
628 static Handle<Object> GetImpl(FixedArrayBase* backing_store, uint32_t entry) { 629 static Handle<Object> GetImpl(Isolate* isolate, FixedArrayBase* backing_store,
629 Isolate* isolate = backing_store->GetIsolate(); 630 uint32_t entry) {
630 uint32_t index = GetIndexForEntryImpl(backing_store, entry); 631 uint32_t index = GetIndexForEntryImpl(backing_store, entry);
631 return handle(BackingStore::cast(backing_store)->get(index), isolate); 632 return handle(BackingStore::cast(backing_store)->get(index), isolate);
632 } 633 }
633 634
634 void Set(Handle<JSObject> holder, uint32_t entry, Object* value) final { 635 void Set(Handle<JSObject> holder, uint32_t entry, Object* value) final {
635 Subclass::SetImpl(holder, entry, value); 636 Subclass::SetImpl(holder, entry, value);
636 } 637 }
637 638
638 void Reconfigure(Handle<JSObject> object, Handle<FixedArrayBase> store, 639 void Reconfigure(Handle<JSObject> object, Handle<FixedArrayBase> store,
639 uint32_t entry, Handle<Object> value, 640 uint32_t entry, Handle<Object> value,
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after
1009 isolate, object, values_or_entries, get_entries, nof_items, filter); 1010 isolate, object, values_or_entries, get_entries, nof_items, filter);
1010 } 1011 }
1011 1012
1012 static Maybe<bool> CollectValuesOrEntriesImpl( 1013 static Maybe<bool> CollectValuesOrEntriesImpl(
1013 Isolate* isolate, Handle<JSObject> object, 1014 Isolate* isolate, Handle<JSObject> object,
1014 Handle<FixedArray> values_or_entries, bool get_entries, int* nof_items, 1015 Handle<FixedArray> values_or_entries, bool get_entries, int* nof_items,
1015 PropertyFilter filter) { 1016 PropertyFilter filter) {
1016 int count = 0; 1017 int count = 0;
1017 KeyAccumulator accumulator(isolate, KeyCollectionMode::kOwnOnly, 1018 KeyAccumulator accumulator(isolate, KeyCollectionMode::kOwnOnly,
1018 ALL_PROPERTIES); 1019 ALL_PROPERTIES);
1019 Subclass::CollectElementIndicesImpl( 1020 Handle<FixedArrayBase> elements(object->elements(), isolate);
1020 object, handle(object->elements(), isolate), &accumulator); 1021 Subclass::CollectElementIndicesImpl(object, elements, &accumulator);
1021 Handle<FixedArray> keys = accumulator.GetKeys(); 1022 Handle<FixedArray> keys = accumulator.GetKeys();
1022 1023
1023 for (int i = 0; i < keys->length(); ++i) { 1024 for (int i = 0; i < keys->length(); ++i) {
1024 Handle<Object> key(keys->get(i), isolate); 1025 Handle<Object> key(keys->get(i), isolate);
1025 Handle<Object> value; 1026 Handle<Object> value;
1026 uint32_t index; 1027 uint32_t index;
1027 if (!key->ToUint32(&index)) continue; 1028 if (!key->ToUint32(&index)) continue;
1028 1029
1029 uint32_t entry = Subclass::GetEntryForIndexImpl( 1030 uint32_t entry = Subclass::GetEntryForIndexImpl(isolate, *object,
1030 isolate, *object, object->elements(), index, filter); 1031 *elements, index, filter);
1031 if (entry == kMaxUInt32) continue; 1032 if (entry == kMaxUInt32) continue;
1032 1033
1033 PropertyDetails details = Subclass::GetDetailsImpl(*object, entry); 1034 PropertyDetails details = Subclass::GetDetailsImpl(*object, entry);
1034 1035
1035 if (details.kind() == kData) { 1036 if (details.kind() == kData) {
1036 value = Subclass::GetImpl(object, entry); 1037 value = Subclass::GetImpl(isolate, *elements, entry);
1037 } else { 1038 } else {
1038 LookupIterator it(isolate, object, index, LookupIterator::OWN); 1039 LookupIterator it(isolate, object, index, LookupIterator::OWN);
1039 ASSIGN_RETURN_ON_EXCEPTION_VALUE( 1040 ASSIGN_RETURN_ON_EXCEPTION_VALUE(
1040 isolate, value, Object::GetProperty(&it), Nothing<bool>()); 1041 isolate, value, Object::GetProperty(&it), Nothing<bool>());
1041 } 1042 }
1042 if (get_entries) { 1043 if (get_entries) {
1043 value = MakeEntryPair(isolate, index, value); 1044 value = MakeEntryPair(isolate, index, value);
1044 } 1045 }
1045 values_or_entries->set(count++, *value); 1046 values_or_entries->set(count++, *value);
1046 } 1047 }
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
1251 } 1252 }
1252 1253
1253 static PropertyDetails GetDetailsImpl(JSObject* holder, uint32_t entry) { 1254 static PropertyDetails GetDetailsImpl(JSObject* holder, uint32_t entry) {
1254 return PropertyDetails(NONE, DATA, 0, PropertyCellType::kNoCell); 1255 return PropertyDetails(NONE, DATA, 0, PropertyCellType::kNoCell);
1255 } 1256 }
1256 1257
1257 PropertyDetails GetDetails(JSObject* holder, uint32_t entry) final { 1258 PropertyDetails GetDetails(JSObject* holder, uint32_t entry) final {
1258 return Subclass::GetDetailsImpl(holder, entry); 1259 return Subclass::GetDetailsImpl(holder, entry);
1259 } 1260 }
1260 1261
1262 Handle<FixedArray> CreateListFromArrayLike(Isolate* isolate,
1263 Handle<JSArray> array) final {
1264 return Subclass::CreateListFromArrayLikeImpl(isolate, array);
1265 };
1266
1267 static Handle<FixedArray> CreateListFromArrayLikeImpl(Isolate* isolate,
1268 Handle<JSArray> array) {
1269 UNREACHABLE();
1270 return Handle<FixedArray>();
1271 }
1272
1261 private: 1273 private:
1262 DISALLOW_COPY_AND_ASSIGN(ElementsAccessorBase); 1274 DISALLOW_COPY_AND_ASSIGN(ElementsAccessorBase);
1263 }; 1275 };
1264 1276
1265 1277
1266 class DictionaryElementsAccessor 1278 class DictionaryElementsAccessor
1267 : public ElementsAccessorBase<DictionaryElementsAccessor, 1279 : public ElementsAccessorBase<DictionaryElementsAccessor,
1268 ElementsKindTraits<DICTIONARY_ELEMENTS> > { 1280 ElementsKindTraits<DICTIONARY_ELEMENTS> > {
1269 public: 1281 public:
1270 explicit DictionaryElementsAccessor(const char* name) 1282 explicit DictionaryElementsAccessor(const char* name)
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
1376 if (details.type() == ACCESSOR_CONSTANT) return true; 1388 if (details.type() == ACCESSOR_CONSTANT) return true;
1377 } 1389 }
1378 return false; 1390 return false;
1379 } 1391 }
1380 1392
1381 static Object* GetRaw(FixedArrayBase* store, uint32_t entry) { 1393 static Object* GetRaw(FixedArrayBase* store, uint32_t entry) {
1382 SeededNumberDictionary* backing_store = SeededNumberDictionary::cast(store); 1394 SeededNumberDictionary* backing_store = SeededNumberDictionary::cast(store);
1383 return backing_store->ValueAt(entry); 1395 return backing_store->ValueAt(entry);
1384 } 1396 }
1385 1397
1386 static Handle<Object> GetImpl(Handle<JSObject> holder, uint32_t entry) { 1398 static Handle<Object> GetImpl(Isolate* isolate, FixedArrayBase* backing_store,
1387 return GetImpl(holder->elements(), entry); 1399 uint32_t entry) {
1388 } 1400 return handle(GetRaw(backing_store, entry), isolate);
1389
1390 static Handle<Object> GetImpl(FixedArrayBase* backing_store, uint32_t entry) {
1391 return handle(GetRaw(backing_store, entry), backing_store->GetIsolate());
1392 } 1401 }
1393 1402
1394 static inline void SetImpl(Handle<JSObject> holder, uint32_t entry, 1403 static inline void SetImpl(Handle<JSObject> holder, uint32_t entry,
1395 Object* value) { 1404 Object* value) {
1396 SetImpl(holder->elements(), entry, value); 1405 SetImpl(holder->elements(), entry, value);
1397 } 1406 }
1398 1407
1399 static inline void SetImpl(FixedArrayBase* backing_store, uint32_t entry, 1408 static inline void SetImpl(FixedArrayBase* backing_store, uint32_t entry,
1400 Object* value) { 1409 Object* value) {
1401 SeededNumberDictionary::cast(backing_store)->ValueAtPut(entry, value); 1410 SeededNumberDictionary::cast(backing_store)->ValueAtPut(entry, value);
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after
1764 Handle<SeededNumberDictionary> dictionary = 1773 Handle<SeededNumberDictionary> dictionary =
1765 SeededNumberDictionary::New(isolate, capacity); 1774 SeededNumberDictionary::New(isolate, capacity);
1766 1775
1767 PropertyDetails details = PropertyDetails::Empty(); 1776 PropertyDetails details = PropertyDetails::Empty();
1768 bool used_as_prototype = object->map()->is_prototype_map(); 1777 bool used_as_prototype = object->map()->is_prototype_map();
1769 int j = 0; 1778 int j = 0;
1770 for (int i = 0; j < capacity; i++) { 1779 for (int i = 0; j < capacity; i++) {
1771 if (IsHoleyElementsKind(kind)) { 1780 if (IsHoleyElementsKind(kind)) {
1772 if (BackingStore::cast(*store)->is_the_hole(isolate, i)) continue; 1781 if (BackingStore::cast(*store)->is_the_hole(isolate, i)) continue;
1773 } 1782 }
1774 Handle<Object> value = Subclass::GetImpl(*store, i); 1783 Handle<Object> value = Subclass::GetImpl(isolate, *store, i);
1775 dictionary = SeededNumberDictionary::AddNumberEntry( 1784 dictionary = SeededNumberDictionary::AddNumberEntry(
1776 dictionary, i, value, details, used_as_prototype); 1785 dictionary, i, value, details, used_as_prototype);
1777 j++; 1786 j++;
1778 } 1787 }
1779 return dictionary; 1788 return dictionary;
1780 } 1789 }
1781 1790
1782 static void DeleteAtEnd(Handle<JSObject> obj, 1791 static void DeleteAtEnd(Handle<JSObject> obj,
1783 Handle<BackingStore> backing_store, uint32_t entry) { 1792 Handle<BackingStore> backing_store, uint32_t entry) {
1784 uint32_t length = static_cast<uint32_t>(backing_store->length()); 1793 uint32_t length = static_cast<uint32_t>(backing_store->length());
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
1925 1934
1926 static void AddElementsToKeyAccumulatorImpl(Handle<JSObject> receiver, 1935 static void AddElementsToKeyAccumulatorImpl(Handle<JSObject> receiver,
1927 KeyAccumulator* accumulator, 1936 KeyAccumulator* accumulator,
1928 AddKeyConversion convert) { 1937 AddKeyConversion convert) {
1929 Isolate* isolate = accumulator->isolate(); 1938 Isolate* isolate = accumulator->isolate();
1930 Handle<FixedArrayBase> elements(receiver->elements(), isolate); 1939 Handle<FixedArrayBase> elements(receiver->elements(), isolate);
1931 uint32_t length = Subclass::GetMaxNumberOfEntries(*receiver, *elements); 1940 uint32_t length = Subclass::GetMaxNumberOfEntries(*receiver, *elements);
1932 for (uint32_t i = 0; i < length; i++) { 1941 for (uint32_t i = 0; i < length; i++) {
1933 if (IsFastPackedElementsKind(KindTraits::Kind) || 1942 if (IsFastPackedElementsKind(KindTraits::Kind) ||
1934 HasEntryImpl(isolate, *elements, i)) { 1943 HasEntryImpl(isolate, *elements, i)) {
1935 accumulator->AddKey(Subclass::GetImpl(*elements, i), convert); 1944 accumulator->AddKey(Subclass::GetImpl(isolate, *elements, i), convert);
1936 } 1945 }
1937 } 1946 }
1938 } 1947 }
1939 1948
1940 static void ValidateContents(Handle<JSObject> holder, int length) { 1949 static void ValidateContents(Handle<JSObject> holder, int length) {
1941 #if DEBUG 1950 #if DEBUG
1942 Isolate* isolate = holder->GetIsolate(); 1951 Isolate* isolate = holder->GetIsolate();
1943 Heap* heap = isolate->heap(); 1952 Heap* heap = isolate->heap();
1944 HandleScope scope(isolate); 1953 HandleScope scope(isolate);
1945 Handle<FixedArrayBase> elements(holder->elements(), isolate); 1954 Handle<FixedArrayBase> elements(holder->elements(), isolate);
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
2066 static Maybe<bool> CollectValuesOrEntriesImpl( 2075 static Maybe<bool> CollectValuesOrEntriesImpl(
2067 Isolate* isolate, Handle<JSObject> object, 2076 Isolate* isolate, Handle<JSObject> object,
2068 Handle<FixedArray> values_or_entries, bool get_entries, int* nof_items, 2077 Handle<FixedArray> values_or_entries, bool get_entries, int* nof_items,
2069 PropertyFilter filter) { 2078 PropertyFilter filter) {
2070 Handle<BackingStore> elements(BackingStore::cast(object->elements()), 2079 Handle<BackingStore> elements(BackingStore::cast(object->elements()),
2071 isolate); 2080 isolate);
2072 int count = 0; 2081 int count = 0;
2073 uint32_t length = elements->length(); 2082 uint32_t length = elements->length();
2074 for (uint32_t index = 0; index < length; ++index) { 2083 for (uint32_t index = 0; index < length; ++index) {
2075 if (!HasEntryImpl(isolate, *elements, index)) continue; 2084 if (!HasEntryImpl(isolate, *elements, index)) continue;
2076 Handle<Object> value = Subclass::GetImpl(*elements, index); 2085 Handle<Object> value = Subclass::GetImpl(isolate, *elements, index);
2077 if (get_entries) { 2086 if (get_entries) {
2078 value = MakeEntryPair(isolate, index, value); 2087 value = MakeEntryPair(isolate, index, value);
2079 } 2088 }
2080 values_or_entries->set(count++, *value); 2089 values_or_entries->set(count++, *value);
2081 } 2090 }
2082 *nof_items = count; 2091 *nof_items = count;
2083 return Just(true); 2092 return Just(true);
2084 } 2093 }
2085 2094
2086 static void MoveElements(Isolate* isolate, Handle<JSArray> receiver, 2095 static void MoveElements(Isolate* isolate, Handle<JSArray> receiver,
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
2256 2265
2257 for (uint32_t k = start_from; k < length; ++k) { 2266 for (uint32_t k = start_from; k < length; ++k) {
2258 if (elements->get(k)->IsNaN()) return Just(true); 2267 if (elements->get(k)->IsNaN()) return Just(true);
2259 } 2268 }
2260 return Just(false); 2269 return Just(false);
2261 } 2270 }
2262 } 2271 }
2263 } 2272 }
2264 } 2273 }
2265 2274
2275 static Handle<FixedArray> CreateListFromArrayLikeImpl(Isolate* isolate,
2276 Handle<JSArray> array) {
2277 uint32_t length = 0;
2278 array->length()->ToArrayLength(&length);
2279 Handle<FixedArray> result = isolate->factory()->NewFixedArray(length);
2280 Handle<FixedArrayBase> elements(array->elements(), isolate);
2281 for (int i = 0; i < elements->length(); i++) {
Jakob Kummerow 2016/11/24 10:55:16 s/elements->length()/length/ for a minor gain in e
2282 if (!Subclass::HasElementImpl(isolate, array, i, elements)) continue;
2283 Handle<Object> value;
2284 value = Subclass::GetImpl(isolate, *elements, i);
2285 if (value->IsName()) {
2286 value = isolate->factory()->InternalizeName(Handle<Name>::cast(value));
2287 }
2288 result->set(i, *value);
2289 }
2290 return result;
2291 }
2292
2266 private: 2293 private:
2267 // SpliceShrinkStep might modify the backing_store. 2294 // SpliceShrinkStep might modify the backing_store.
2268 static void SpliceShrinkStep(Isolate* isolate, Handle<JSArray> receiver, 2295 static void SpliceShrinkStep(Isolate* isolate, Handle<JSArray> receiver,
2269 Handle<FixedArrayBase> backing_store, 2296 Handle<FixedArrayBase> backing_store,
2270 uint32_t start, uint32_t delete_count, 2297 uint32_t start, uint32_t delete_count,
2271 uint32_t add_count, uint32_t len, 2298 uint32_t add_count, uint32_t len,
2272 uint32_t new_length) { 2299 uint32_t new_length) {
2273 const int move_left_count = len - delete_count - start; 2300 const int move_left_count = len - delete_count - start;
2274 const int move_left_dst_index = start + add_count; 2301 const int move_left_dst_index = start + add_count;
2275 Subclass::MoveElements(isolate, receiver, backing_store, 2302 Subclass::MoveElements(isolate, receiver, backing_store,
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
2314 if (IsFastSmiOrObjectElementsKind(kind)) { 2341 if (IsFastSmiOrObjectElementsKind(kind)) {
2315 HandleScope scope(isolate); 2342 HandleScope scope(isolate);
2316 JSObject::EnsureWritableFastElements(receiver); 2343 JSObject::EnsureWritableFastElements(receiver);
2317 } 2344 }
2318 Handle<FixedArrayBase> backing_store(receiver->elements(), isolate); 2345 Handle<FixedArrayBase> backing_store(receiver->elements(), isolate);
2319 uint32_t length = 2346 uint32_t length =
2320 static_cast<uint32_t>(Smi::cast(receiver->length())->value()); 2347 static_cast<uint32_t>(Smi::cast(receiver->length())->value());
2321 DCHECK(length > 0); 2348 DCHECK(length > 0);
2322 int new_length = length - 1; 2349 int new_length = length - 1;
2323 int remove_index = remove_position == AT_START ? 0 : new_length; 2350 int remove_index = remove_position == AT_START ? 0 : new_length;
2324 Handle<Object> result = Subclass::GetImpl(*backing_store, remove_index); 2351 Handle<Object> result =
2352 Subclass::GetImpl(isolate, *backing_store, remove_index);
2325 if (remove_position == AT_START) { 2353 if (remove_position == AT_START) {
2326 Subclass::MoveElements(isolate, receiver, backing_store, 0, 1, new_length, 2354 Subclass::MoveElements(isolate, receiver, backing_store, 0, 1, new_length,
2327 0, 0); 2355 0, 0);
2328 } 2356 }
2329 Subclass::SetLengthImpl(isolate, receiver, new_length, backing_store); 2357 Subclass::SetLengthImpl(isolate, receiver, new_length, backing_store);
2330 2358
2331 if (IsHoleyElementsKind(kind) && result->IsTheHole(isolate)) { 2359 if (IsHoleyElementsKind(kind) && result->IsTheHole(isolate)) {
2332 return isolate->factory()->undefined_value(); 2360 return isolate->factory()->undefined_value();
2333 } 2361 }
2334 return result; 2362 return result;
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
2535 ElementsKindTraits<FAST_HOLEY_ELEMENTS> >(name) {} 2563 ElementsKindTraits<FAST_HOLEY_ELEMENTS> >(name) {}
2536 }; 2564 };
2537 2565
2538 template <typename Subclass, typename KindTraits> 2566 template <typename Subclass, typename KindTraits>
2539 class FastDoubleElementsAccessor 2567 class FastDoubleElementsAccessor
2540 : public FastElementsAccessor<Subclass, KindTraits> { 2568 : public FastElementsAccessor<Subclass, KindTraits> {
2541 public: 2569 public:
2542 explicit FastDoubleElementsAccessor(const char* name) 2570 explicit FastDoubleElementsAccessor(const char* name)
2543 : FastElementsAccessor<Subclass, KindTraits>(name) {} 2571 : FastElementsAccessor<Subclass, KindTraits>(name) {}
2544 2572
2545 static Handle<Object> GetImpl(Handle<JSObject> holder, uint32_t entry) { 2573 static Handle<Object> GetImpl(Isolate* isolate, FixedArrayBase* backing_store,
2546 return GetImpl(holder->elements(), entry); 2574 uint32_t entry) {
2547 }
2548
2549 static Handle<Object> GetImpl(FixedArrayBase* backing_store, uint32_t entry) {
2550 Isolate* isolate = backing_store->GetIsolate();
2551 return FixedDoubleArray::get(FixedDoubleArray::cast(backing_store), entry, 2575 return FixedDoubleArray::get(FixedDoubleArray::cast(backing_store), entry,
2552 isolate); 2576 isolate);
2553 } 2577 }
2554 2578
2555 static inline void SetImpl(Handle<JSObject> holder, uint32_t entry, 2579 static inline void SetImpl(Handle<JSObject> holder, uint32_t entry,
2556 Object* value) { 2580 Object* value) {
2557 SetImpl(holder->elements(), entry, value); 2581 SetImpl(holder->elements(), entry, value);
2558 } 2582 }
2559 2583
2560 static inline void SetImpl(FixedArrayBase* backing_store, uint32_t entry, 2584 static inline void SetImpl(FixedArrayBase* backing_store, uint32_t entry,
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
2687 static inline void SetImpl(FixedArrayBase* backing_store, uint32_t entry, 2711 static inline void SetImpl(FixedArrayBase* backing_store, uint32_t entry,
2688 Object* value) { 2712 Object* value) {
2689 BackingStore::cast(backing_store)->SetValue(entry, value); 2713 BackingStore::cast(backing_store)->SetValue(entry, value);
2690 } 2714 }
2691 2715
2692 static inline void SetImpl(FixedArrayBase* backing_store, uint32_t entry, 2716 static inline void SetImpl(FixedArrayBase* backing_store, uint32_t entry,
2693 Object* value, WriteBarrierMode mode) { 2717 Object* value, WriteBarrierMode mode) {
2694 BackingStore::cast(backing_store)->SetValue(entry, value); 2718 BackingStore::cast(backing_store)->SetValue(entry, value);
2695 } 2719 }
2696 2720
2697 static Handle<Object> GetImpl(Handle<JSObject> holder, uint32_t entry) { 2721 static Handle<Object> GetImpl(Isolate* isolate, FixedArrayBase* backing_store,
2698 return GetImpl(holder->elements(), entry); 2722 uint32_t entry) {
2699 }
2700
2701 static Handle<Object> GetImpl(FixedArrayBase* backing_store, uint32_t entry) {
2702 return BackingStore::get(BackingStore::cast(backing_store), entry); 2723 return BackingStore::get(BackingStore::cast(backing_store), entry);
2703 } 2724 }
2704 2725
2705 static PropertyDetails GetDetailsImpl(JSObject* holder, uint32_t entry) { 2726 static PropertyDetails GetDetailsImpl(JSObject* holder, uint32_t entry) {
2706 return PropertyDetails(DONT_DELETE, DATA, 0, PropertyCellType::kNoCell); 2727 return PropertyDetails(DONT_DELETE, DATA, 0, PropertyCellType::kNoCell);
2707 } 2728 }
2708 2729
2709 static PropertyDetails GetDetailsImpl(FixedArrayBase* backing_store, 2730 static PropertyDetails GetDetailsImpl(FixedArrayBase* backing_store,
2710 uint32_t entry) { 2731 uint32_t entry) {
2711 return PropertyDetails(DONT_DELETE, DATA, 0, PropertyCellType::kNoCell); 2732 return PropertyDetails(DONT_DELETE, DATA, 0, PropertyCellType::kNoCell);
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
2755 } 2776 }
2756 2777
2757 static uint32_t NumberOfElementsImpl(JSObject* receiver, 2778 static uint32_t NumberOfElementsImpl(JSObject* receiver,
2758 FixedArrayBase* backing_store) { 2779 FixedArrayBase* backing_store) {
2759 return AccessorClass::GetCapacityImpl(receiver, backing_store); 2780 return AccessorClass::GetCapacityImpl(receiver, backing_store);
2760 } 2781 }
2761 2782
2762 static void AddElementsToKeyAccumulatorImpl(Handle<JSObject> receiver, 2783 static void AddElementsToKeyAccumulatorImpl(Handle<JSObject> receiver,
2763 KeyAccumulator* accumulator, 2784 KeyAccumulator* accumulator,
2764 AddKeyConversion convert) { 2785 AddKeyConversion convert) {
2786 Isolate* isolate = receiver->GetIsolate();
2765 Handle<FixedArrayBase> elements(receiver->elements()); 2787 Handle<FixedArrayBase> elements(receiver->elements());
2766 uint32_t length = AccessorClass::GetCapacityImpl(*receiver, *elements); 2788 uint32_t length = AccessorClass::GetCapacityImpl(*receiver, *elements);
2767 for (uint32_t i = 0; i < length; i++) { 2789 for (uint32_t i = 0; i < length; i++) {
2768 Handle<Object> value = AccessorClass::GetImpl(*elements, i); 2790 Handle<Object> value = AccessorClass::GetImpl(isolate, *elements, i);
2769 accumulator->AddKey(value, convert); 2791 accumulator->AddKey(value, convert);
2770 } 2792 }
2771 } 2793 }
2772 2794
2773 static Maybe<bool> CollectValuesOrEntriesImpl( 2795 static Maybe<bool> CollectValuesOrEntriesImpl(
2774 Isolate* isolate, Handle<JSObject> object, 2796 Isolate* isolate, Handle<JSObject> object,
2775 Handle<FixedArray> values_or_entries, bool get_entries, int* nof_items, 2797 Handle<FixedArray> values_or_entries, bool get_entries, int* nof_items,
2776 PropertyFilter filter) { 2798 PropertyFilter filter) {
2777 int count = 0; 2799 int count = 0;
2778 if ((filter & ONLY_CONFIGURABLE) == 0) { 2800 if ((filter & ONLY_CONFIGURABLE) == 0) {
2779 Handle<FixedArrayBase> elements(object->elements()); 2801 Handle<FixedArrayBase> elements(object->elements());
2780 uint32_t length = AccessorClass::GetCapacityImpl(*object, *elements); 2802 uint32_t length = AccessorClass::GetCapacityImpl(*object, *elements);
2781 for (uint32_t index = 0; index < length; ++index) { 2803 for (uint32_t index = 0; index < length; ++index) {
2782 Handle<Object> value = AccessorClass::GetImpl(*elements, index); 2804 Handle<Object> value =
2805 AccessorClass::GetImpl(isolate, *elements, index);
2783 if (get_entries) { 2806 if (get_entries) {
2784 value = MakeEntryPair(isolate, index, value); 2807 value = MakeEntryPair(isolate, index, value);
2785 } 2808 }
2786 values_or_entries->set(count++, *value); 2809 values_or_entries->set(count++, *value);
2787 } 2810 }
2788 } 2811 }
2789 *nof_items = count; 2812 *nof_items = count;
2790 return Just(true); 2813 return Just(true);
2791 } 2814 }
2792 2815
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
2895 2918
2896 template <typename Subclass, typename ArgumentsAccessor, typename KindTraits> 2919 template <typename Subclass, typename ArgumentsAccessor, typename KindTraits>
2897 class SloppyArgumentsElementsAccessor 2920 class SloppyArgumentsElementsAccessor
2898 : public ElementsAccessorBase<Subclass, KindTraits> { 2921 : public ElementsAccessorBase<Subclass, KindTraits> {
2899 public: 2922 public:
2900 explicit SloppyArgumentsElementsAccessor(const char* name) 2923 explicit SloppyArgumentsElementsAccessor(const char* name)
2901 : ElementsAccessorBase<Subclass, KindTraits>(name) { 2924 : ElementsAccessorBase<Subclass, KindTraits>(name) {
2902 USE(KindTraits::Kind); 2925 USE(KindTraits::Kind);
2903 } 2926 }
2904 2927
2905 static Handle<Object> GetImpl(Handle<JSObject> holder, uint32_t entry) { 2928 static Handle<Object> GetImpl(Isolate* isolate, FixedArrayBase* parameters,
2906 return GetImpl(holder->elements(), entry); 2929 uint32_t entry) {
2907 }
2908
2909 static Handle<Object> GetImpl(FixedArrayBase* parameters, uint32_t entry) {
2910 Isolate* isolate = parameters->GetIsolate();
2911 Handle<FixedArray> parameter_map(FixedArray::cast(parameters), isolate); 2930 Handle<FixedArray> parameter_map(FixedArray::cast(parameters), isolate);
2912 uint32_t length = parameter_map->length() - 2; 2931 uint32_t length = parameter_map->length() - 2;
2913 if (entry < length) { 2932 if (entry < length) {
2914 DisallowHeapAllocation no_gc; 2933 DisallowHeapAllocation no_gc;
2915 Object* probe = parameter_map->get(entry + 2); 2934 Object* probe = parameter_map->get(entry + 2);
2916 Context* context = Context::cast(parameter_map->get(0)); 2935 Context* context = Context::cast(parameter_map->get(0));
2917 int context_entry = Smi::cast(probe)->value(); 2936 int context_entry = Smi::cast(probe)->value();
2918 DCHECK(!context->get(context_entry)->IsTheHole(isolate)); 2937 DCHECK(!context->get(context_entry)->IsTheHole(isolate));
2919 return handle(context->get(context_entry), isolate); 2938 return handle(context->get(context_entry), isolate);
2920 } else { 2939 } else {
2921 // Object is not mapped, defer to the arguments. 2940 // Object is not mapped, defer to the arguments.
2922 Handle<Object> result = ArgumentsAccessor::GetImpl( 2941 Handle<Object> result = ArgumentsAccessor::GetImpl(
2923 FixedArray::cast(parameter_map->get(1)), entry - length); 2942 isolate, FixedArray::cast(parameter_map->get(1)), entry - length);
2924 // Elements of the arguments object in slow mode might be slow aliases. 2943 // Elements of the arguments object in slow mode might be slow aliases.
2925 if (result->IsAliasedArgumentsEntry()) { 2944 if (result->IsAliasedArgumentsEntry()) {
2926 DisallowHeapAllocation no_gc; 2945 DisallowHeapAllocation no_gc;
2927 AliasedArgumentsEntry* alias = AliasedArgumentsEntry::cast(*result); 2946 AliasedArgumentsEntry* alias = AliasedArgumentsEntry::cast(*result);
2928 Context* context = Context::cast(parameter_map->get(0)); 2947 Context* context = Context::cast(parameter_map->get(0));
2929 int context_entry = alias->aliased_context_slot(); 2948 int context_entry = alias->aliased_context_slot();
2930 DCHECK(!context->get(context_entry)->IsTheHole(isolate)); 2949 DCHECK(!context->get(context_entry)->IsTheHole(isolate));
2931 return handle(context->get(context_entry), isolate); 2950 return handle(context->get(context_entry), isolate);
2932 } 2951 }
2933 return result; 2952 return result;
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
3011 } 3030 }
3012 3031
3013 static void AddElementsToKeyAccumulatorImpl(Handle<JSObject> receiver, 3032 static void AddElementsToKeyAccumulatorImpl(Handle<JSObject> receiver,
3014 KeyAccumulator* accumulator, 3033 KeyAccumulator* accumulator,
3015 AddKeyConversion convert) { 3034 AddKeyConversion convert) {
3016 Isolate* isolate = accumulator->isolate(); 3035 Isolate* isolate = accumulator->isolate();
3017 Handle<FixedArrayBase> elements(receiver->elements(), isolate); 3036 Handle<FixedArrayBase> elements(receiver->elements(), isolate);
3018 uint32_t length = GetCapacityImpl(*receiver, *elements); 3037 uint32_t length = GetCapacityImpl(*receiver, *elements);
3019 for (uint32_t entry = 0; entry < length; entry++) { 3038 for (uint32_t entry = 0; entry < length; entry++) {
3020 if (!HasEntryImpl(isolate, *elements, entry)) continue; 3039 if (!HasEntryImpl(isolate, *elements, entry)) continue;
3021 Handle<Object> value = GetImpl(*elements, entry); 3040 Handle<Object> value = Subclass::GetImpl(isolate, *elements, entry);
3022 accumulator->AddKey(value, convert); 3041 accumulator->AddKey(value, convert);
3023 } 3042 }
3024 } 3043 }
3025 3044
3026 static bool HasEntryImpl(Isolate* isolate, FixedArrayBase* parameters, 3045 static bool HasEntryImpl(Isolate* isolate, FixedArrayBase* parameters,
3027 uint32_t entry) { 3046 uint32_t entry) {
3028 FixedArray* parameter_map = FixedArray::cast(parameters); 3047 FixedArray* parameter_map = FixedArray::cast(parameters);
3029 uint32_t length = parameter_map->length() - 2; 3048 uint32_t length = parameter_map->length() - 2;
3030 if (entry < length) { 3049 if (entry < length) {
3031 return HasParameterMapArg(parameter_map, entry); 3050 return HasParameterMapArg(parameter_map, entry);
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
3147 bool search_for_hole = value->IsUndefined(isolate); 3166 bool search_for_hole = value->IsUndefined(isolate);
3148 3167
3149 for (uint32_t k = start_from; k < length; ++k) { 3168 for (uint32_t k = start_from; k < length; ++k) {
3150 uint32_t entry = GetEntryForIndexImpl(isolate, *object, *parameter_map, k, 3169 uint32_t entry = GetEntryForIndexImpl(isolate, *object, *parameter_map, k,
3151 ALL_PROPERTIES); 3170 ALL_PROPERTIES);
3152 if (entry == kMaxUInt32) { 3171 if (entry == kMaxUInt32) {
3153 if (search_for_hole) return Just(true); 3172 if (search_for_hole) return Just(true);
3154 continue; 3173 continue;
3155 } 3174 }
3156 3175
3157 Handle<Object> element_k = GetImpl(*parameter_map, entry); 3176 Handle<Object> element_k =
3177 Subclass::GetImpl(isolate, *parameter_map, entry);
3158 3178
3159 if (element_k->IsAccessorPair()) { 3179 if (element_k->IsAccessorPair()) {
3160 LookupIterator it(isolate, object, k, LookupIterator::OWN); 3180 LookupIterator it(isolate, object, k, LookupIterator::OWN);
3161 DCHECK(it.IsFound()); 3181 DCHECK(it.IsFound());
3162 DCHECK_EQ(it.state(), LookupIterator::ACCESSOR); 3182 DCHECK_EQ(it.state(), LookupIterator::ACCESSOR);
3163 ASSIGN_RETURN_ON_EXCEPTION_VALUE(isolate, element_k, 3183 ASSIGN_RETURN_ON_EXCEPTION_VALUE(isolate, element_k,
3164 Object::GetPropertyWithAccessor(&it), 3184 Object::GetPropertyWithAccessor(&it),
3165 Nothing<bool>()); 3185 Nothing<bool>());
3166 3186
3167 if (value->SameValueZero(*element_k)) return Just(true); 3187 if (value->SameValueZero(*element_k)) return Just(true);
(...skipping 18 matching lines...) Expand all
3186 Handle<FixedArray> parameter_map(FixedArray::cast(object->elements()), 3206 Handle<FixedArray> parameter_map(FixedArray::cast(object->elements()),
3187 isolate); 3207 isolate);
3188 3208
3189 for (uint32_t k = start_from; k < length; ++k) { 3209 for (uint32_t k = start_from; k < length; ++k) {
3190 uint32_t entry = GetEntryForIndexImpl(isolate, *object, *parameter_map, k, 3210 uint32_t entry = GetEntryForIndexImpl(isolate, *object, *parameter_map, k,
3191 ALL_PROPERTIES); 3211 ALL_PROPERTIES);
3192 if (entry == kMaxUInt32) { 3212 if (entry == kMaxUInt32) {
3193 continue; 3213 continue;
3194 } 3214 }
3195 3215
3196 Handle<Object> element_k = GetImpl(*parameter_map, entry); 3216 Handle<Object> element_k =
3217 Subclass::GetImpl(isolate, *parameter_map, entry);
3197 3218
3198 if (element_k->IsAccessorPair()) { 3219 if (element_k->IsAccessorPair()) {
3199 LookupIterator it(isolate, object, k, LookupIterator::OWN); 3220 LookupIterator it(isolate, object, k, LookupIterator::OWN);
3200 DCHECK(it.IsFound()); 3221 DCHECK(it.IsFound());
3201 DCHECK_EQ(it.state(), LookupIterator::ACCESSOR); 3222 DCHECK_EQ(it.state(), LookupIterator::ACCESSOR);
3202 ASSIGN_RETURN_ON_EXCEPTION_VALUE(isolate, element_k, 3223 ASSIGN_RETURN_ON_EXCEPTION_VALUE(isolate, element_k,
3203 Object::GetPropertyWithAccessor(&it), 3224 Object::GetPropertyWithAccessor(&it),
3204 Nothing<int64_t>()); 3225 Nothing<int64_t>());
3205 3226
3206 if (value->StrictEquals(*element_k)) { 3227 if (value->StrictEquals(*element_k)) {
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
3331 Handle<JSArray> result_array = isolate->factory()->NewJSArray( 3352 Handle<JSArray> result_array = isolate->factory()->NewJSArray(
3332 FAST_HOLEY_ELEMENTS, result_len, result_len); 3353 FAST_HOLEY_ELEMENTS, result_len, result_len);
3333 DisallowHeapAllocation no_gc; 3354 DisallowHeapAllocation no_gc;
3334 FixedArray* elements = FixedArray::cast(result_array->elements()); 3355 FixedArray* elements = FixedArray::cast(result_array->elements());
3335 FixedArray* parameters = FixedArray::cast(receiver->elements()); 3356 FixedArray* parameters = FixedArray::cast(receiver->elements());
3336 uint32_t insertion_index = 0; 3357 uint32_t insertion_index = 0;
3337 for (uint32_t i = start; i < end; i++) { 3358 for (uint32_t i = start; i < end; i++) {
3338 uint32_t entry = GetEntryForIndexImpl(isolate, *receiver, parameters, i, 3359 uint32_t entry = GetEntryForIndexImpl(isolate, *receiver, parameters, i,
3339 ALL_PROPERTIES); 3360 ALL_PROPERTIES);
3340 if (entry != kMaxUInt32 && HasEntryImpl(isolate, parameters, entry)) { 3361 if (entry != kMaxUInt32 && HasEntryImpl(isolate, parameters, entry)) {
3341 elements->set(insertion_index, *GetImpl(parameters, entry)); 3362 elements->set(insertion_index, *GetImpl(isolate, parameters, entry));
3342 } else { 3363 } else {
3343 elements->set_the_hole(insertion_index); 3364 elements->set_the_hole(insertion_index);
3344 } 3365 }
3345 insertion_index++; 3366 insertion_index++;
3346 } 3367 }
3347 return result_array; 3368 return result_array;
3348 } 3369 }
3349 3370
3350 static Handle<SeededNumberDictionary> NormalizeImpl( 3371 static Handle<SeededNumberDictionary> NormalizeImpl(
3351 Handle<JSObject> object, Handle<FixedArrayBase> elements) { 3372 Handle<JSObject> object, Handle<FixedArrayBase> elements) {
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
3431 3452
3432 template <typename Subclass, typename BackingStoreAccessor, typename KindTraits> 3453 template <typename Subclass, typename BackingStoreAccessor, typename KindTraits>
3433 class StringWrapperElementsAccessor 3454 class StringWrapperElementsAccessor
3434 : public ElementsAccessorBase<Subclass, KindTraits> { 3455 : public ElementsAccessorBase<Subclass, KindTraits> {
3435 public: 3456 public:
3436 explicit StringWrapperElementsAccessor(const char* name) 3457 explicit StringWrapperElementsAccessor(const char* name)
3437 : ElementsAccessorBase<Subclass, KindTraits>(name) { 3458 : ElementsAccessorBase<Subclass, KindTraits>(name) {
3438 USE(KindTraits::Kind); 3459 USE(KindTraits::Kind);
3439 } 3460 }
3440 3461
3462 static Handle<Object> GetInternalImpl(Handle<JSObject> holder,
3463 uint32_t entry) {
3464 return GetImpl(holder, entry);
3465 }
3466
3441 static Handle<Object> GetImpl(Handle<JSObject> holder, uint32_t entry) { 3467 static Handle<Object> GetImpl(Handle<JSObject> holder, uint32_t entry) {
3442 Isolate* isolate = holder->GetIsolate(); 3468 Isolate* isolate = holder->GetIsolate();
3443 Handle<String> string(GetString(*holder), isolate); 3469 Handle<String> string(GetString(*holder), isolate);
3444 uint32_t length = static_cast<uint32_t>(string->length()); 3470 uint32_t length = static_cast<uint32_t>(string->length());
3445 if (entry < length) { 3471 if (entry < length) {
3446 return isolate->factory()->LookupSingleCharacterStringFromCode( 3472 return isolate->factory()->LookupSingleCharacterStringFromCode(
3447 String::Flatten(string)->Get(entry)); 3473 String::Flatten(string)->Get(entry));
3448 } 3474 }
3449 return BackingStoreAccessor::GetImpl(holder, entry - length); 3475 return BackingStoreAccessor::GetImpl(isolate, holder->elements(),
3476 entry - length);
3477 }
3478
3479 static Handle<Object> GetImpl(Isolate* isolate, FixedArrayBase* elements,
3480 uint32_t entry) {
3481 UNREACHABLE();
3482 return Handle<Object>();
3450 } 3483 }
3451 3484
3452 static PropertyDetails GetDetailsImpl(JSObject* holder, uint32_t entry) { 3485 static PropertyDetails GetDetailsImpl(JSObject* holder, uint32_t entry) {
3453 uint32_t length = static_cast<uint32_t>(GetString(holder)->length()); 3486 uint32_t length = static_cast<uint32_t>(GetString(holder)->length());
3454 if (entry < length) { 3487 if (entry < length) {
3455 PropertyAttributes attributes = 3488 PropertyAttributes attributes =
3456 static_cast<PropertyAttributes>(READ_ONLY | DONT_DELETE); 3489 static_cast<PropertyAttributes>(READ_ONLY | DONT_DELETE);
3457 return PropertyDetails(attributes, v8::internal::DATA, 0, 3490 return PropertyDetails(attributes, v8::internal::DATA, 0,
3458 PropertyCellType::kNoCell); 3491 PropertyCellType::kNoCell);
3459 } 3492 }
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after
3824 insertion_index += len; 3857 insertion_index += len;
3825 } 3858 }
3826 3859
3827 DCHECK_EQ(insertion_index, result_len); 3860 DCHECK_EQ(insertion_index, result_len);
3828 return result_array; 3861 return result_array;
3829 } 3862 }
3830 3863
3831 ElementsAccessor** ElementsAccessor::elements_accessors_ = NULL; 3864 ElementsAccessor** ElementsAccessor::elements_accessors_ = NULL;
3832 } // namespace internal 3865 } // namespace internal
3833 } // namespace v8 3866 } // namespace v8
OLDNEW
« src/elements.h ('K') | « src/elements.h ('k') | src/objects.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698