OLD | NEW |
---|---|
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 <sstream> | 9 #include <sstream> |
10 | 10 |
(...skipping 16453 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
16464 uint32_t>::DeleteProperty(Handle<SeededNumberDictionary>, int); | 16464 uint32_t>::DeleteProperty(Handle<SeededNumberDictionary>, int); |
16465 | 16465 |
16466 template Handle<Object> | 16466 template Handle<Object> |
16467 Dictionary<UnseededNumberDictionary, UnseededNumberDictionaryShape, | 16467 Dictionary<UnseededNumberDictionary, UnseededNumberDictionaryShape, |
16468 uint32_t>::DeleteProperty(Handle<UnseededNumberDictionary>, int); | 16468 uint32_t>::DeleteProperty(Handle<UnseededNumberDictionary>, int); |
16469 | 16469 |
16470 template Handle<NameDictionary> | 16470 template Handle<NameDictionary> |
16471 HashTable<NameDictionary, NameDictionaryShape, Handle<Name> >:: | 16471 HashTable<NameDictionary, NameDictionaryShape, Handle<Name> >:: |
16472 New(Isolate*, int, MinimumCapacity, PretenureFlag); | 16472 New(Isolate*, int, MinimumCapacity, PretenureFlag); |
16473 | 16473 |
16474 template Handle<ObjectHashSet> HashTable<ObjectHashSet, ObjectHashSetShape, | |
16475 Handle<Object>>::New(Isolate*, int n, | |
16476 MinimumCapacity, | |
16477 PretenureFlag); | |
16478 | |
16474 template Handle<NameDictionary> | 16479 template Handle<NameDictionary> |
16475 HashTable<NameDictionary, NameDictionaryShape, Handle<Name> >:: | 16480 HashTable<NameDictionary, NameDictionaryShape, Handle<Name> >:: |
16476 Shrink(Handle<NameDictionary>, Handle<Name>); | 16481 Shrink(Handle<NameDictionary>, Handle<Name>); |
16477 | 16482 |
16478 template Handle<SeededNumberDictionary> | 16483 template Handle<SeededNumberDictionary> |
16479 HashTable<SeededNumberDictionary, SeededNumberDictionaryShape, uint32_t>:: | 16484 HashTable<SeededNumberDictionary, SeededNumberDictionaryShape, uint32_t>:: |
16480 Shrink(Handle<SeededNumberDictionary>, uint32_t); | 16485 Shrink(Handle<SeededNumberDictionary>, uint32_t); |
16481 | 16486 |
16482 template Handle<UnseededNumberDictionary> | 16487 template Handle<UnseededNumberDictionary> |
16483 HashTable<UnseededNumberDictionary, UnseededNumberDictionaryShape, | 16488 HashTable<UnseededNumberDictionary, UnseededNumberDictionaryShape, |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
16534 | 16539 |
16535 template int NameDictionaryBase<NameDictionary, NameDictionaryShape>::FindEntry( | 16540 template int NameDictionaryBase<NameDictionary, NameDictionaryShape>::FindEntry( |
16536 Handle<Name>); | 16541 Handle<Name>); |
16537 | 16542 |
16538 template int Dictionary<GlobalDictionary, GlobalDictionaryShape, Handle<Name>>:: | 16543 template int Dictionary<GlobalDictionary, GlobalDictionaryShape, Handle<Name>>:: |
16539 NumberOfElementsFilterAttributes(PropertyFilter filter); | 16544 NumberOfElementsFilterAttributes(PropertyFilter filter); |
16540 | 16545 |
16541 template int Dictionary<NameDictionary, NameDictionaryShape, Handle<Name>>:: | 16546 template int Dictionary<NameDictionary, NameDictionaryShape, Handle<Name>>:: |
16542 NumberOfElementsFilterAttributes(PropertyFilter filter); | 16547 NumberOfElementsFilterAttributes(PropertyFilter filter); |
16543 | 16548 |
16544 template void Dictionary<GlobalDictionary, GlobalDictionaryShape, | 16549 template void |
16545 Handle<Name>>::CopyEnumKeysTo(FixedArray* storage); | 16550 Dictionary<GlobalDictionary, GlobalDictionaryShape, Handle<Name>>:: |
16551 CopyEnumKeysTo(Handle<Dictionary<GlobalDictionary, GlobalDictionaryShape, | |
16552 Handle<Name>>> | |
16553 dictionary, | |
16554 Handle<FixedArray> storage, KeyCollectionMode mode, | |
16555 KeyAccumulator* accumulator); | |
16546 | 16556 |
16547 template void Dictionary<NameDictionary, NameDictionaryShape, | 16557 template void |
16548 Handle<Name>>::CopyEnumKeysTo(FixedArray* storage); | 16558 Dictionary<NameDictionary, NameDictionaryShape, Handle<Name>>::CopyEnumKeysTo( |
16559 Handle<Dictionary<NameDictionary, NameDictionaryShape, Handle<Name>>> | |
16560 dictionary, | |
16561 Handle<FixedArray> storage, KeyCollectionMode mode, | |
16562 KeyAccumulator* accumulator); | |
16549 | 16563 |
16550 template void | 16564 template void |
16551 Dictionary<GlobalDictionary, GlobalDictionaryShape, Handle<Name>>:: | 16565 Dictionary<GlobalDictionary, GlobalDictionaryShape, Handle<Name>>:: |
16552 CollectKeysTo(Handle<Dictionary<GlobalDictionary, GlobalDictionaryShape, | 16566 CollectKeysTo(Handle<Dictionary<GlobalDictionary, GlobalDictionaryShape, |
16553 Handle<Name>>> | 16567 Handle<Name>>> |
16554 dictionary, | 16568 dictionary, |
16555 KeyAccumulator* keys, PropertyFilter filter); | 16569 KeyAccumulator* keys); |
16556 | 16570 |
16557 template void | 16571 template void |
16558 Dictionary<NameDictionary, NameDictionaryShape, Handle<Name>>::CollectKeysTo( | 16572 Dictionary<NameDictionary, NameDictionaryShape, Handle<Name>>::CollectKeysTo( |
16559 Handle<Dictionary<NameDictionary, NameDictionaryShape, Handle<Name>>> | 16573 Handle<Dictionary<NameDictionary, NameDictionaryShape, Handle<Name>>> |
16560 dictionary, | 16574 dictionary, |
16561 KeyAccumulator* keys, PropertyFilter filter); | 16575 KeyAccumulator* keys); |
16562 | 16576 |
16563 Handle<Object> JSObject::PrepareSlowElementsForSort( | 16577 Handle<Object> JSObject::PrepareSlowElementsForSort( |
16564 Handle<JSObject> object, uint32_t limit) { | 16578 Handle<JSObject> object, uint32_t limit) { |
16565 DCHECK(object->HasDictionaryElements()); | 16579 DCHECK(object->HasDictionaryElements()); |
16566 Isolate* isolate = object->GetIsolate(); | 16580 Isolate* isolate = object->GetIsolate(); |
16567 // Must stay in dictionary mode, either because of requires_slow_elements, | 16581 // Must stay in dictionary mode, either because of requires_slow_elements, |
16568 // or because we are not going to sort (and therefore compact) all of the | 16582 // or because we are not going to sort (and therefore compact) all of the |
16569 // elements. | 16583 // elements. |
16570 Handle<SeededNumberDictionary> dict(object->element_dictionary(), isolate); | 16584 Handle<SeededNumberDictionary> dict(object->element_dictionary(), isolate); |
16571 Handle<SeededNumberDictionary> new_dict = | 16585 Handle<SeededNumberDictionary> new_dict = |
(...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
17048 stringset->set(EntryToIndex(entry), *name); | 17062 stringset->set(EntryToIndex(entry), *name); |
17049 stringset->ElementAdded(); | 17063 stringset->ElementAdded(); |
17050 } | 17064 } |
17051 return stringset; | 17065 return stringset; |
17052 } | 17066 } |
17053 | 17067 |
17054 bool StringSet::Has(Handle<String> name) { | 17068 bool StringSet::Has(Handle<String> name) { |
17055 return FindEntry(*name) != kNotFound; | 17069 return FindEntry(*name) != kNotFound; |
17056 } | 17070 } |
17057 | 17071 |
17072 Handle<ObjectHashSet> ObjectHashSet::Add(Handle<ObjectHashSet> set, | |
17073 Handle<Object> key) { | |
17074 Isolate* isolate = set->GetIsolate(); | |
17075 int32_t hash = Object::GetOrCreateHash(isolate, key)->value(); | |
17076 | |
17077 if (!set->Has(isolate, key, hash)) { | |
17078 set = EnsureCapacity(set, 1, key); | |
17079 int entry = set->FindInsertionEntry(hash); | |
17080 set->set(EntryToIndex(entry), *key); | |
17081 set->ElementAdded(); | |
17082 } | |
17083 return set; | |
17084 } | |
17085 | |
17058 Handle<Object> CompilationCacheTable::Lookup(Handle<String> src, | 17086 Handle<Object> CompilationCacheTable::Lookup(Handle<String> src, |
17059 Handle<Context> context, | 17087 Handle<Context> context, |
17060 LanguageMode language_mode) { | 17088 LanguageMode language_mode) { |
17061 Isolate* isolate = GetIsolate(); | 17089 Isolate* isolate = GetIsolate(); |
17062 Handle<SharedFunctionInfo> shared(context->closure()->shared()); | 17090 Handle<SharedFunctionInfo> shared(context->closure()->shared()); |
17063 StringSharedKey key(src, shared, language_mode, RelocInfo::kNoPosition); | 17091 StringSharedKey key(src, shared, language_mode, RelocInfo::kNoPosition); |
17064 int entry = FindEntry(&key); | 17092 int entry = FindEntry(&key); |
17065 if (entry == kNotFound) return isolate->factory()->undefined_value(); | 17093 if (entry == kNotFound) return isolate->factory()->undefined_value(); |
17066 int index = EntryToIndex(entry); | 17094 int index = EntryToIndex(entry); |
17067 if (!get(index)->IsFixedArray()) return isolate->factory()->undefined_value(); | 17095 if (!get(index)->IsFixedArray()) return isolate->factory()->undefined_value(); |
(...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
17503 struct EnumIndexComparator { | 17531 struct EnumIndexComparator { |
17504 explicit EnumIndexComparator(Dictionary* dict) : dict(dict) {} | 17532 explicit EnumIndexComparator(Dictionary* dict) : dict(dict) {} |
17505 bool operator() (Smi* a, Smi* b) { | 17533 bool operator() (Smi* a, Smi* b) { |
17506 PropertyDetails da(dict->DetailsAt(a->value())); | 17534 PropertyDetails da(dict->DetailsAt(a->value())); |
17507 PropertyDetails db(dict->DetailsAt(b->value())); | 17535 PropertyDetails db(dict->DetailsAt(b->value())); |
17508 return da.dictionary_index() < db.dictionary_index(); | 17536 return da.dictionary_index() < db.dictionary_index(); |
17509 } | 17537 } |
17510 Dictionary* dict; | 17538 Dictionary* dict; |
17511 }; | 17539 }; |
17512 | 17540 |
17541 template <typename Derived, typename Shape, typename Key> | |
17542 void Dictionary<Derived, Shape, Key>::CopyEnumKeysTo( | |
17543 Handle<Dictionary<Derived, Shape, Key>> dictionary, | |
17544 Handle<FixedArray> storage, KeyCollectionMode mode, | |
17545 KeyAccumulator* accumulator) { | |
17546 Isolate* isolate = dictionary->GetIsolate(); | |
17547 int length = storage->length(); | |
17548 int capacity = dictionary->Capacity(); | |
17549 int properties = 0; | |
17550 bool is_shadowing_key; | |
adamk
2016/06/27 19:19:33
Again confused as to why this is outside the loop.
| |
17551 for (int i = 0; i < capacity; i++) { | |
17552 Object* key = dictionary->KeyAt(i); | |
17553 is_shadowing_key = false; | |
17554 if (!dictionary->IsKey(isolate, key)) continue; | |
17555 if (key->IsSymbol()) continue; | |
17556 PropertyDetails details = dictionary->DetailsAt(i); | |
17557 if (details.IsDontEnum()) { | |
17558 if (mode == KeyCollectionMode::kIncludePrototypes) { | |
17559 is_shadowing_key = true; | |
17560 } else { | |
17561 continue; | |
17562 } | |
17563 } | |
17564 if (dictionary->IsDeleted(i)) continue; | |
17565 if (is_shadowing_key) { | |
17566 accumulator->AddShadowKey(key); | |
17567 continue; | |
17568 } else { | |
17569 storage->set(properties, Smi::FromInt(i)); | |
17570 } | |
17571 properties++; | |
17572 if (properties == length) break; | |
17573 } | |
17513 | 17574 |
17514 template <typename Derived, typename Shape, typename Key> | |
17515 void Dictionary<Derived, Shape, Key>::CopyEnumKeysTo(FixedArray* storage) { | |
17516 Isolate* isolate = this->GetIsolate(); | |
17517 int length = storage->length(); | |
17518 int capacity = this->Capacity(); | |
17519 int properties = 0; | |
17520 for (int i = 0; i < capacity; i++) { | |
17521 Object* k = this->KeyAt(i); | |
17522 if (this->IsKey(isolate, k) && !k->IsSymbol()) { | |
17523 PropertyDetails details = this->DetailsAt(i); | |
17524 if (details.IsDontEnum() || this->IsDeleted(i)) continue; | |
17525 storage->set(properties, Smi::FromInt(i)); | |
17526 properties++; | |
17527 if (properties == length) break; | |
17528 } | |
17529 } | |
17530 CHECK_EQ(length, properties); | 17575 CHECK_EQ(length, properties); |
17531 EnumIndexComparator<Derived> cmp(static_cast<Derived*>(this)); | 17576 DisallowHeapAllocation no_gc; |
17577 Dictionary<Derived, Shape, Key>* raw_dictionary = *dictionary; | |
17578 FixedArray* raw_storage = *storage; | |
17579 EnumIndexComparator<Derived> cmp(static_cast<Derived*>(*dictionary)); | |
17532 Smi** start = reinterpret_cast<Smi**>(storage->GetFirstElementAddress()); | 17580 Smi** start = reinterpret_cast<Smi**>(storage->GetFirstElementAddress()); |
17533 std::sort(start, start + length, cmp); | 17581 std::sort(start, start + length, cmp); |
17534 for (int i = 0; i < length; i++) { | 17582 for (int i = 0; i < length; i++) { |
17535 int index = Smi::cast(storage->get(i))->value(); | 17583 int index = Smi::cast(raw_storage->get(i))->value(); |
17536 storage->set(i, this->KeyAt(index)); | 17584 raw_storage->set(i, raw_dictionary->KeyAt(index)); |
17537 } | 17585 } |
17538 } | 17586 } |
17539 | 17587 |
17540 template <typename Derived, typename Shape, typename Key> | 17588 template <typename Derived, typename Shape, typename Key> |
17541 void Dictionary<Derived, Shape, Key>::CollectKeysTo( | 17589 void Dictionary<Derived, Shape, Key>::CollectKeysTo( |
17542 Handle<Dictionary<Derived, Shape, Key> > dictionary, KeyAccumulator* keys, | 17590 Handle<Dictionary<Derived, Shape, Key>> dictionary, KeyAccumulator* keys) { |
17543 PropertyFilter filter) { | |
17544 Isolate* isolate = keys->isolate(); | 17591 Isolate* isolate = keys->isolate(); |
17545 int capacity = dictionary->Capacity(); | 17592 int capacity = dictionary->Capacity(); |
17546 Handle<FixedArray> array = | 17593 Handle<FixedArray> array = |
17547 isolate->factory()->NewFixedArray(dictionary->NumberOfElements()); | 17594 isolate->factory()->NewFixedArray(dictionary->NumberOfElements()); |
17548 int array_size = 0; | 17595 int array_size = 0; |
17549 | 17596 PropertyFilter filter = keys->filter(); |
17550 { | 17597 { |
17551 DisallowHeapAllocation no_gc; | 17598 DisallowHeapAllocation no_gc; |
17552 Dictionary<Derived, Shape, Key>* raw_dict = *dictionary; | 17599 Dictionary<Derived, Shape, Key>* raw_dict = *dictionary; |
17553 for (int i = 0; i < capacity; i++) { | 17600 for (int i = 0; i < capacity; i++) { |
17554 Object* k = raw_dict->KeyAt(i); | 17601 Object* k = raw_dict->KeyAt(i); |
17555 if (!raw_dict->IsKey(isolate, k) || k->FilterKey(filter)) continue; | 17602 if (!raw_dict->IsKey(isolate, k) || k->FilterKey(filter)) continue; |
17556 if (raw_dict->IsDeleted(i)) continue; | 17603 if (raw_dict->IsDeleted(i)) continue; |
17557 PropertyDetails details = raw_dict->DetailsAt(i); | 17604 PropertyDetails details = raw_dict->DetailsAt(i); |
17558 if ((details.attributes() & filter) != 0) continue; | 17605 if ((details.attributes() & filter) != 0) { |
17606 keys->AddShadowKey(k); | |
17607 continue; | |
17608 } | |
17559 if (filter & ONLY_ALL_CAN_READ) { | 17609 if (filter & ONLY_ALL_CAN_READ) { |
17560 if (details.kind() != kAccessor) continue; | 17610 if (details.kind() != kAccessor) continue; |
17561 Object* accessors = raw_dict->ValueAt(i); | 17611 Object* accessors = raw_dict->ValueAt(i); |
17562 if (accessors->IsPropertyCell()) { | 17612 if (accessors->IsPropertyCell()) { |
17563 accessors = PropertyCell::cast(accessors)->value(); | 17613 accessors = PropertyCell::cast(accessors)->value(); |
17564 } | 17614 } |
17565 if (!accessors->IsAccessorInfo()) continue; | 17615 if (!accessors->IsAccessorInfo()) continue; |
17566 if (!AccessorInfo::cast(accessors)->all_can_read()) continue; | 17616 if (!AccessorInfo::cast(accessors)->all_can_read()) continue; |
17567 } | 17617 } |
17568 array->set(array_size++, Smi::FromInt(i)); | 17618 array->set(array_size++, Smi::FromInt(i)); |
(...skipping 1318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
18887 } else { | 18937 } else { |
18888 // Old-style generators. | 18938 // Old-style generators. |
18889 int offset = continuation(); | 18939 int offset = continuation(); |
18890 CHECK(0 <= offset && offset < function()->code()->instruction_size()); | 18940 CHECK(0 <= offset && offset < function()->code()->instruction_size()); |
18891 return function()->code()->SourcePosition(offset); | 18941 return function()->code()->SourcePosition(offset); |
18892 } | 18942 } |
18893 } | 18943 } |
18894 | 18944 |
18895 } // namespace internal | 18945 } // namespace internal |
18896 } // namespace v8 | 18946 } // namespace v8 |
OLD | NEW |