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

Side by Side Diff: src/objects.cc

Issue 2684983005: Merged: [key] Fix for-in with trailing shadowing keys with dict-mode receiver (Closed)
Patch Set: Created 3 years, 10 months 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 | « no previous file | test/mjsunit/for-in.js » ('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 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 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/objects.h" 5 #include "src/objects.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 #include <iomanip> 8 #include <iomanip>
9 #include <memory> 9 #include <memory>
10 #include <sstream> 10 #include <sstream>
(...skipping 17765 matching lines...) Expand 10 before | Expand all | Expand 10 after
17776 return da.dictionary_index() < db.dictionary_index(); 17776 return da.dictionary_index() < db.dictionary_index();
17777 } 17777 }
17778 Dictionary* dict; 17778 Dictionary* dict;
17779 }; 17779 };
17780 17780
17781 template <typename Derived, typename Shape, typename Key> 17781 template <typename Derived, typename Shape, typename Key>
17782 void Dictionary<Derived, Shape, Key>::CopyEnumKeysTo( 17782 void Dictionary<Derived, Shape, Key>::CopyEnumKeysTo(
17783 Handle<Dictionary<Derived, Shape, Key>> dictionary, 17783 Handle<Dictionary<Derived, Shape, Key>> dictionary,
17784 Handle<FixedArray> storage, KeyCollectionMode mode, 17784 Handle<FixedArray> storage, KeyCollectionMode mode,
17785 KeyAccumulator* accumulator) { 17785 KeyAccumulator* accumulator) {
17786 DCHECK_IMPLIES(mode != KeyCollectionMode::kOwnOnly, accumulator != nullptr);
17786 Isolate* isolate = dictionary->GetIsolate(); 17787 Isolate* isolate = dictionary->GetIsolate();
17787 int length = storage->length(); 17788 int length = storage->length();
17788 int capacity = dictionary->Capacity(); 17789 int capacity = dictionary->Capacity();
17789 int properties = 0; 17790 int properties = 0;
17790 for (int i = 0; i < capacity; i++) { 17791 for (int i = 0; i < capacity; i++) {
17791 Object* key = dictionary->KeyAt(i); 17792 Object* key = dictionary->KeyAt(i);
17792 bool is_shadowing_key = false; 17793 bool is_shadowing_key = false;
17793 if (!dictionary->IsKey(isolate, key)) continue; 17794 if (!dictionary->IsKey(isolate, key)) continue;
17794 if (key->IsSymbol()) continue; 17795 if (key->IsSymbol()) continue;
17795 PropertyDetails details = dictionary->DetailsAt(i); 17796 PropertyDetails details = dictionary->DetailsAt(i);
17796 if (details.IsDontEnum()) { 17797 if (details.IsDontEnum()) {
17797 if (mode == KeyCollectionMode::kIncludePrototypes) { 17798 if (mode == KeyCollectionMode::kIncludePrototypes) {
17798 is_shadowing_key = true; 17799 is_shadowing_key = true;
17799 } else { 17800 } else {
17800 continue; 17801 continue;
17801 } 17802 }
17802 } 17803 }
17803 if (dictionary->IsDeleted(i)) continue; 17804 if (dictionary->IsDeleted(i)) continue;
17804 if (is_shadowing_key) { 17805 if (is_shadowing_key) {
17805 accumulator->AddShadowingKey(key); 17806 accumulator->AddShadowingKey(key);
17806 continue; 17807 continue;
17807 } else { 17808 } else {
17808 storage->set(properties, Smi::FromInt(i)); 17809 storage->set(properties, Smi::FromInt(i));
17809 } 17810 }
17810 properties++; 17811 properties++;
17811 if (properties == length) break; 17812 if (mode == KeyCollectionMode::kOwnOnly && properties == length) break;
17812 } 17813 }
17813 17814
17814 CHECK_EQ(length, properties); 17815 CHECK_EQ(length, properties);
17815 DisallowHeapAllocation no_gc; 17816 DisallowHeapAllocation no_gc;
17816 Dictionary<Derived, Shape, Key>* raw_dictionary = *dictionary; 17817 Dictionary<Derived, Shape, Key>* raw_dictionary = *dictionary;
17817 FixedArray* raw_storage = *storage; 17818 FixedArray* raw_storage = *storage;
17818 EnumIndexComparator<Derived> cmp(static_cast<Derived*>(*dictionary)); 17819 EnumIndexComparator<Derived> cmp(static_cast<Derived*>(*dictionary));
17819 Smi** start = reinterpret_cast<Smi**>(storage->GetFirstElementAddress()); 17820 Smi** start = reinterpret_cast<Smi**>(storage->GetFirstElementAddress());
17820 std::sort(start, start + length, cmp); 17821 std::sort(start, start + length, cmp);
17821 for (int i = 0; i < length; i++) { 17822 for (int i = 0; i < length; i++) {
(...skipping 2090 matching lines...) Expand 10 before | Expand all | Expand 10 after
19912 // depend on this. 19913 // depend on this.
19913 return DICTIONARY_ELEMENTS; 19914 return DICTIONARY_ELEMENTS;
19914 } 19915 }
19915 DCHECK_LE(kind, LAST_ELEMENTS_KIND); 19916 DCHECK_LE(kind, LAST_ELEMENTS_KIND);
19916 return kind; 19917 return kind;
19917 } 19918 }
19918 } 19919 }
19919 19920
19920 } // namespace internal 19921 } // namespace internal
19921 } // namespace v8 19922 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | test/mjsunit/for-in.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698