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

Side by Side Diff: src/elements.cc

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

Powered by Google App Engine
This is Rietveld 408576698