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

Side by Side Diff: src/elements.cc

Issue 1207613005: Move reconfiguration into the elements accessor (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 5 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 | « src/elements.h ('k') | src/lookup.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/v8.h" 5 #include "src/v8.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/elements.h" 9 #include "src/elements.h"
10 #include "src/messages.h" 10 #include "src/messages.h"
(...skipping 605 matching lines...) Expand 10 before | Expand all | Expand 10 after
616 virtual void Set(FixedArrayBase* backing_store, uint32_t key, 616 virtual void Set(FixedArrayBase* backing_store, uint32_t key,
617 Object* value) final { 617 Object* value) final {
618 ElementsAccessorSubclass::SetImpl(backing_store, key, value); 618 ElementsAccessorSubclass::SetImpl(backing_store, key, value);
619 } 619 }
620 620
621 static void SetImpl(FixedArrayBase* backing_store, uint32_t key, 621 static void SetImpl(FixedArrayBase* backing_store, uint32_t key,
622 Object* value) { 622 Object* value) {
623 BackingStore::cast(backing_store)->SetValue(key, value); 623 BackingStore::cast(backing_store)->SetValue(key, value);
624 } 624 }
625 625
626 virtual void Reconfigure(Handle<JSObject> object,
627 Handle<FixedArrayBase> store, uint32_t index,
628 Handle<Object> value,
629 PropertyAttributes attributes) final {
630 ElementsAccessorSubclass::ReconfigureImpl(object, store, index, value,
631 attributes);
632 }
633
634 static void ReconfigureImpl(Handle<JSObject> object,
635 Handle<FixedArrayBase> store, uint32_t index,
636 Handle<Object> value,
637 PropertyAttributes attributes) {
638 UNREACHABLE();
639 }
640
626 virtual MaybeHandle<AccessorPair> GetAccessorPair( 641 virtual MaybeHandle<AccessorPair> GetAccessorPair(
627 Handle<JSObject> holder, uint32_t key, 642 Handle<JSObject> holder, uint32_t key,
628 Handle<FixedArrayBase> backing_store) final { 643 Handle<FixedArrayBase> backing_store) final {
629 return ElementsAccessorSubclass::GetAccessorPairImpl(holder, key, 644 return ElementsAccessorSubclass::GetAccessorPairImpl(holder, key,
630 backing_store); 645 backing_store);
631 } 646 }
632 647
633 static MaybeHandle<AccessorPair> GetAccessorPairImpl( 648 static MaybeHandle<AccessorPair> GetAccessorPairImpl(
634 Handle<JSObject> obj, uint32_t key, 649 Handle<JSObject> obj, uint32_t key,
635 Handle<FixedArrayBase> backing_store) { 650 Handle<FixedArrayBase> backing_store) {
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after
896 911
897 // Super class for all fast element arrays. 912 // Super class for all fast element arrays.
898 template<typename FastElementsAccessorSubclass, 913 template<typename FastElementsAccessorSubclass,
899 typename KindTraits> 914 typename KindTraits>
900 class FastElementsAccessor 915 class FastElementsAccessor
901 : public ElementsAccessorBase<FastElementsAccessorSubclass, KindTraits> { 916 : public ElementsAccessorBase<FastElementsAccessorSubclass, KindTraits> {
902 public: 917 public:
903 explicit FastElementsAccessor(const char* name) 918 explicit FastElementsAccessor(const char* name)
904 : ElementsAccessorBase<FastElementsAccessorSubclass, 919 : ElementsAccessorBase<FastElementsAccessorSubclass,
905 KindTraits>(name) {} 920 KindTraits>(name) {}
921
922 static void ReconfigureImpl(Handle<JSObject> object,
923 Handle<FixedArrayBase> store, uint32_t index,
924 Handle<Object> value,
925 PropertyAttributes attributes) {
926 Handle<SeededNumberDictionary> dictionary =
927 JSObject::NormalizeElements(object);
928 index = dictionary->FindEntry(index);
929 object->GetElementsAccessor()->Reconfigure(object, dictionary, index, value,
930 attributes);
931 }
932
906 protected: 933 protected:
907 friend class ElementsAccessorBase<FastElementsAccessorSubclass, KindTraits>; 934 friend class ElementsAccessorBase<FastElementsAccessorSubclass, KindTraits>;
908 friend class SloppyArgumentsElementsAccessor; 935 friend class SloppyArgumentsElementsAccessor;
909 936
910 typedef typename KindTraits::BackingStore BackingStore; 937 typedef typename KindTraits::BackingStore BackingStore;
911 938
912 static void DeleteCommon(Handle<JSObject> obj, uint32_t key, 939 static void DeleteCommon(Handle<JSObject> obj, uint32_t key,
913 LanguageMode language_mode) { 940 LanguageMode language_mode) {
914 DCHECK(obj->HasFastSmiOrObjectElements() || 941 DCHECK(obj->HasFastSmiOrObjectElements() ||
915 obj->HasFastDoubleElements() || 942 obj->HasFastDoubleElements() ||
(...skipping 486 matching lines...) Expand 10 before | Expand all | Expand 10 after
1402 Handle<SeededNumberDictionary>::cast(store); 1429 Handle<SeededNumberDictionary>::cast(store);
1403 Isolate* isolate = backing_store->GetIsolate(); 1430 Isolate* isolate = backing_store->GetIsolate();
1404 int entry = backing_store->FindEntry(key); 1431 int entry = backing_store->FindEntry(key);
1405 if (entry != SeededNumberDictionary::kNotFound) { 1432 if (entry != SeededNumberDictionary::kNotFound) {
1406 return handle(backing_store->ValueAt(entry), isolate); 1433 return handle(backing_store->ValueAt(entry), isolate);
1407 } 1434 }
1408 return isolate->factory()->the_hole_value(); 1435 return isolate->factory()->the_hole_value();
1409 } 1436 }
1410 1437
1411 static void SetImpl(FixedArrayBase* store, uint32_t key, Object* value) { 1438 static void SetImpl(FixedArrayBase* store, uint32_t key, Object* value) {
1412 SeededNumberDictionary* backing_store = SeededNumberDictionary::cast(store); 1439 SeededNumberDictionary* dictionary = SeededNumberDictionary::cast(store);
1413 int entry = backing_store->FindEntry(key); 1440 int entry = dictionary->FindEntry(key);
1414 DCHECK_NE(SeededNumberDictionary::kNotFound, entry); 1441 DCHECK_NE(SeededNumberDictionary::kNotFound, entry);
1415 backing_store->ValueAtPut(entry, value); 1442 dictionary->ValueAtPut(entry, value);
1443 }
1444
1445 static void ReconfigureImpl(Handle<JSObject> object,
1446 Handle<FixedArrayBase> store, uint32_t index,
1447 Handle<Object> value,
1448 PropertyAttributes attributes) {
1449 SeededNumberDictionary* dictionary = SeededNumberDictionary::cast(*store);
1450 if (attributes != NONE) dictionary->set_requires_slow_elements();
1451 dictionary->ValueAtPut(index, *value);
1452 PropertyDetails details = dictionary->DetailsAt(index);
1453 details = PropertyDetails(attributes, DATA, details.dictionary_index(),
1454 PropertyCellType::kNoCell);
1455 dictionary->DetailsAtPut(index, details);
1416 } 1456 }
1417 1457
1418 static MaybeHandle<AccessorPair> GetAccessorPairImpl( 1458 static MaybeHandle<AccessorPair> GetAccessorPairImpl(
1419 Handle<JSObject> obj, uint32_t key, Handle<FixedArrayBase> store) { 1459 Handle<JSObject> obj, uint32_t key, Handle<FixedArrayBase> store) {
1420 Handle<SeededNumberDictionary> backing_store = 1460 Handle<SeededNumberDictionary> backing_store =
1421 Handle<SeededNumberDictionary>::cast(store); 1461 Handle<SeededNumberDictionary>::cast(store);
1422 int entry = backing_store->FindEntry(key); 1462 int entry = backing_store->FindEntry(key);
1423 if (entry != SeededNumberDictionary::kNotFound && 1463 if (entry != SeededNumberDictionary::kNotFound &&
1424 backing_store->DetailsAt(entry).type() == ACCESSOR_CONSTANT && 1464 backing_store->DetailsAt(entry).type() == ACCESSOR_CONSTANT &&
1425 backing_store->ValueAt(entry)->IsAccessorPair()) { 1465 backing_store->ValueAt(entry)->IsAccessorPair()) {
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
1526 Context* context = Context::cast(parameter_map->get(0)); 1566 Context* context = Context::cast(parameter_map->get(0));
1527 int context_index = Smi::cast(probe)->value(); 1567 int context_index = Smi::cast(probe)->value();
1528 DCHECK(!context->get(context_index)->IsTheHole()); 1568 DCHECK(!context->get(context_index)->IsTheHole());
1529 context->set(context_index, value); 1569 context->set(context_index, value);
1530 } else { 1570 } else {
1531 FixedArray* arguments = FixedArray::cast(parameter_map->get(1)); 1571 FixedArray* arguments = FixedArray::cast(parameter_map->get(1));
1532 ElementsAccessor::ForArray(arguments)->Set(arguments, key, value); 1572 ElementsAccessor::ForArray(arguments)->Set(arguments, key, value);
1533 } 1573 }
1534 } 1574 }
1535 1575
1576 static void ReconfigureImpl(Handle<JSObject> object,
1577 Handle<FixedArrayBase> store, uint32_t index,
1578 Handle<Object> value,
1579 PropertyAttributes attributes) {
1580 Handle<FixedArray> parameter_map = Handle<FixedArray>::cast(store);
1581 uint32_t length = parameter_map->length() - 2;
1582 if (index < length) {
1583 Object* probe = parameter_map->get(index + 2);
1584 DCHECK(!probe->IsTheHole());
1585 Context* context = Context::cast(parameter_map->get(0));
1586 int context_index = Smi::cast(probe)->value();
1587 DCHECK(!context->get(context_index)->IsTheHole());
1588 context->set(context_index, *value);
1589
1590 // Redefining attributes of an aliased element destroys fast aliasing.
1591 parameter_map->set_the_hole(index + 2);
1592 // For elements that are still writable we re-establish slow aliasing.
1593 if ((attributes & READ_ONLY) == 0) {
1594 Isolate* isolate = store->GetIsolate();
1595 value = isolate->factory()->NewAliasedArgumentsEntry(context_index);
1596 }
1597
1598 PropertyDetails details(attributes, DATA, 0, PropertyCellType::kNoCell);
1599 Handle<SeededNumberDictionary> arguments =
1600 parameter_map->get(1)->IsSeededNumberDictionary()
1601 ? handle(SeededNumberDictionary::cast(parameter_map->get(1)))
1602 : JSObject::NormalizeElements(object);
1603 arguments = SeededNumberDictionary::AddNumberEntry(arguments, index,
1604 value, details);
1605 parameter_map->set(1, *arguments);
1606 } else {
1607 Handle<FixedArrayBase> arguments(
1608 FixedArrayBase::cast(parameter_map->get(1)));
1609 ElementsAccessor::ForArray(arguments)
1610 ->Reconfigure(object, arguments, index - length, value, attributes);
1611 }
1612 }
1613
1536 static MaybeHandle<AccessorPair> GetAccessorPairImpl( 1614 static MaybeHandle<AccessorPair> GetAccessorPairImpl(
1537 Handle<JSObject> obj, uint32_t key, Handle<FixedArrayBase> parameters) { 1615 Handle<JSObject> obj, uint32_t key, Handle<FixedArrayBase> parameters) {
1538 Handle<FixedArray> parameter_map = Handle<FixedArray>::cast(parameters); 1616 Handle<FixedArray> parameter_map = Handle<FixedArray>::cast(parameters);
1539 Handle<Object> probe(GetParameterMapArg(*parameter_map, key), 1617 Handle<Object> probe(GetParameterMapArg(*parameter_map, key),
1540 obj->GetIsolate()); 1618 obj->GetIsolate());
1541 if (!probe->IsTheHole()) { 1619 if (!probe->IsTheHole()) {
1542 return MaybeHandle<AccessorPair>(); 1620 return MaybeHandle<AccessorPair>();
1543 } else { 1621 } else {
1544 // If not aliased, check the arguments. 1622 // If not aliased, check the arguments.
1545 Handle<FixedArray> arguments(FixedArray::cast(parameter_map->get(1))); 1623 Handle<FixedArray> arguments(FixedArray::cast(parameter_map->get(1)));
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
1820 break; 1898 break;
1821 } 1899 }
1822 1900
1823 array->set_elements(*elms); 1901 array->set_elements(*elms);
1824 array->set_length(Smi::FromInt(number_of_elements)); 1902 array->set_length(Smi::FromInt(number_of_elements));
1825 return array; 1903 return array;
1826 } 1904 }
1827 1905
1828 } // namespace internal 1906 } // namespace internal
1829 } // namespace v8 1907 } // namespace v8
OLDNEW
« no previous file with comments | « src/elements.h ('k') | src/lookup.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698