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

Side by Side Diff: src/elements.cc

Issue 932693003: Revert of Remove handle wrappers from basic elements accessors (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 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 | « 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/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/objects.h" 10 #include "src/objects.h"
(...skipping 569 matching lines...) Expand 10 before | Expand all | Expand 10 after
580 length = fixed_array_base->length(); 580 length = fixed_array_base->length();
581 } 581 }
582 ElementsAccessorSubclass::ValidateContents(holder, length); 582 ElementsAccessorSubclass::ValidateContents(holder, length);
583 } 583 }
584 584
585 void Validate(Handle<JSObject> holder) FINAL { 585 void Validate(Handle<JSObject> holder) FINAL {
586 DisallowHeapAllocation no_gc; 586 DisallowHeapAllocation no_gc;
587 ElementsAccessorSubclass::ValidateImpl(holder); 587 ElementsAccessorSubclass::ValidateImpl(holder);
588 } 588 }
589 589
590 static bool HasElementImpl(JSObject* holder, uint32_t key, 590 static bool HasElementImpl(Handle<JSObject> holder, uint32_t key,
591 FixedArrayBase* backing_store) { 591 Handle<FixedArrayBase> backing_store) {
592 return ElementsAccessorSubclass::GetAttributesImpl(holder, key, 592 return ElementsAccessorSubclass::GetAttributesImpl(holder, key,
593 backing_store) != ABSENT; 593 backing_store) != ABSENT;
594 } 594 }
595 595
596 virtual bool HasElement(JSObject* holder, uint32_t key, 596 virtual bool HasElement(Handle<JSObject> holder, uint32_t key,
597 FixedArrayBase* backing_store) FINAL { 597 Handle<FixedArrayBase> backing_store) FINAL {
598 return ElementsAccessorSubclass::HasElementImpl(holder, key, backing_store); 598 return ElementsAccessorSubclass::HasElementImpl(holder, key, backing_store);
599 } 599 }
600 600
601 MUST_USE_RESULT virtual MaybeHandle<Object> Get( 601 MUST_USE_RESULT virtual MaybeHandle<Object> Get(
602 Handle<Object> receiver, Handle<JSObject> holder, uint32_t key, 602 Handle<Object> receiver, Handle<JSObject> holder, uint32_t key,
603 Handle<FixedArrayBase> backing_store) FINAL { 603 Handle<FixedArrayBase> backing_store) FINAL {
604 if (!IsExternalArrayElementsKind(ElementsTraits::Kind) && 604 if (!IsExternalArrayElementsKind(ElementsTraits::Kind) &&
605 FLAG_trace_js_array_abuse) { 605 FLAG_trace_js_array_abuse) {
606 CheckArrayAbuse(holder, "elements read", key); 606 CheckArrayAbuse(holder, "elements read", key);
607 } 607 }
608 608
609 if (IsExternalArrayElementsKind(ElementsTraits::Kind) && 609 if (IsExternalArrayElementsKind(ElementsTraits::Kind) &&
610 FLAG_trace_external_array_abuse) { 610 FLAG_trace_external_array_abuse) {
611 CheckArrayAbuse(holder, "external elements read", key); 611 CheckArrayAbuse(holder, "external elements read", key);
612 } 612 }
613 613
614 return ElementsAccessorSubclass::GetImpl( 614 return ElementsAccessorSubclass::GetImpl(
615 receiver, holder, key, backing_store); 615 receiver, holder, key, backing_store);
616 } 616 }
617 617
618 MUST_USE_RESULT static MaybeHandle<Object> GetImpl( 618 MUST_USE_RESULT static MaybeHandle<Object> GetImpl(
619 Handle<Object> receiver, 619 Handle<Object> receiver,
620 Handle<JSObject> obj, 620 Handle<JSObject> obj,
621 uint32_t key, 621 uint32_t key,
622 Handle<FixedArrayBase> backing_store) { 622 Handle<FixedArrayBase> backing_store) {
623 if (key < ElementsAccessorSubclass::GetCapacityImpl(*backing_store)) { 623 if (key < ElementsAccessorSubclass::GetCapacityImpl(backing_store)) {
624 return BackingStore::get(Handle<BackingStore>::cast(backing_store), key); 624 return BackingStore::get(Handle<BackingStore>::cast(backing_store), key);
625 } else { 625 } else {
626 return backing_store->GetIsolate()->factory()->the_hole_value(); 626 return backing_store->GetIsolate()->factory()->the_hole_value();
627 } 627 }
628 } 628 }
629 629
630 MUST_USE_RESULT virtual PropertyAttributes GetAttributes( 630 MUST_USE_RESULT virtual PropertyAttributes GetAttributes(
631 JSObject* holder, uint32_t key, FixedArrayBase* backing_store) FINAL { 631 Handle<JSObject> holder, uint32_t key,
632 Handle<FixedArrayBase> backing_store) FINAL {
632 return ElementsAccessorSubclass::GetAttributesImpl(holder, key, 633 return ElementsAccessorSubclass::GetAttributesImpl(holder, key,
633 backing_store); 634 backing_store);
634 } 635 }
635 636
636 MUST_USE_RESULT static PropertyAttributes GetAttributesImpl( 637 MUST_USE_RESULT static PropertyAttributes GetAttributesImpl(
637 JSObject* obj, uint32_t key, FixedArrayBase* backing_store) { 638 Handle<JSObject> obj,
639 uint32_t key,
640 Handle<FixedArrayBase> backing_store) {
638 if (key >= ElementsAccessorSubclass::GetCapacityImpl(backing_store)) { 641 if (key >= ElementsAccessorSubclass::GetCapacityImpl(backing_store)) {
639 return ABSENT; 642 return ABSENT;
640 } 643 }
641 return BackingStore::cast(backing_store)->is_the_hole(key) ? ABSENT : NONE; 644 return
645 Handle<BackingStore>::cast(backing_store)->is_the_hole(key)
646 ? ABSENT : NONE;
642 } 647 }
643 648
644 MUST_USE_RESULT virtual MaybeHandle<AccessorPair> GetAccessorPair( 649 MUST_USE_RESULT virtual MaybeHandle<AccessorPair> GetAccessorPair(
645 Handle<JSObject> holder, uint32_t key, 650 Handle<JSObject> holder, uint32_t key,
646 Handle<FixedArrayBase> backing_store) FINAL { 651 Handle<FixedArrayBase> backing_store) FINAL {
647 return ElementsAccessorSubclass::GetAccessorPairImpl(holder, key, 652 return ElementsAccessorSubclass::GetAccessorPairImpl(holder, key,
648 backing_store); 653 backing_store);
649 } 654 }
650 655
651 MUST_USE_RESULT static MaybeHandle<AccessorPair> GetAccessorPairImpl( 656 MUST_USE_RESULT static MaybeHandle<AccessorPair> GetAccessorPairImpl(
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
739 #ifdef ENABLE_SLOW_DCHECKS 744 #ifdef ENABLE_SLOW_DCHECKS
740 if (FLAG_enable_slow_asserts) { 745 if (FLAG_enable_slow_asserts) {
741 for (int i = 0; i < len0; i++) { 746 for (int i = 0; i < len0; i++) {
742 DCHECK(!to->get(i)->IsTheHole()); 747 DCHECK(!to->get(i)->IsTheHole());
743 } 748 }
744 } 749 }
745 #endif 750 #endif
746 751
747 // Optimize if 'other' is empty. 752 // Optimize if 'other' is empty.
748 // We cannot optimize if 'this' is empty, as other may have holes. 753 // We cannot optimize if 'this' is empty, as other may have holes.
749 uint32_t len1 = ElementsAccessorSubclass::GetCapacityImpl(*from); 754 uint32_t len1 = ElementsAccessorSubclass::GetCapacityImpl(from);
750 if (len1 == 0) return to; 755 if (len1 == 0) return to;
751 756
752 Isolate* isolate = from->GetIsolate(); 757 Isolate* isolate = from->GetIsolate();
753 758
754 // Compute how many elements are not in other. 759 // Compute how many elements are not in other.
755 uint32_t extra = 0; 760 uint32_t extra = 0;
756 for (uint32_t y = 0; y < len1; y++) { 761 for (uint32_t y = 0; y < len1; y++) {
757 uint32_t key = ElementsAccessorSubclass::GetKeyForIndexImpl(from, y); 762 uint32_t key = ElementsAccessorSubclass::GetKeyForIndexImpl(from, y);
758 if (ElementsAccessorSubclass::HasElementImpl(*holder, key, *from)) { 763 if (ElementsAccessorSubclass::HasElementImpl(holder, key, from)) {
759 Handle<Object> value; 764 Handle<Object> value;
760 ASSIGN_RETURN_ON_EXCEPTION( 765 ASSIGN_RETURN_ON_EXCEPTION(
761 isolate, value, 766 isolate, value,
762 ElementsAccessorSubclass::GetImpl(receiver, holder, key, from), 767 ElementsAccessorSubclass::GetImpl(receiver, holder, key, from),
763 FixedArray); 768 FixedArray);
764 769
765 DCHECK(!value->IsTheHole()); 770 DCHECK(!value->IsTheHole());
766 if (filter == FixedArray::NON_SYMBOL_KEYS && value->IsSymbol()) { 771 if (filter == FixedArray::NON_SYMBOL_KEYS && value->IsSymbol()) {
767 continue; 772 continue;
768 } 773 }
(...skipping 16 matching lines...) Expand all
785 Object* e = to->get(i); 790 Object* e = to->get(i);
786 DCHECK(e->IsString() || e->IsNumber()); 791 DCHECK(e->IsString() || e->IsNumber());
787 result->set(i, e, mode); 792 result->set(i, e, mode);
788 } 793 }
789 } 794 }
790 // Fill in the extra values. 795 // Fill in the extra values.
791 uint32_t index = 0; 796 uint32_t index = 0;
792 for (uint32_t y = 0; y < len1; y++) { 797 for (uint32_t y = 0; y < len1; y++) {
793 uint32_t key = 798 uint32_t key =
794 ElementsAccessorSubclass::GetKeyForIndexImpl(from, y); 799 ElementsAccessorSubclass::GetKeyForIndexImpl(from, y);
795 if (ElementsAccessorSubclass::HasElementImpl(*holder, key, *from)) { 800 if (ElementsAccessorSubclass::HasElementImpl(holder, key, from)) {
796 Handle<Object> value; 801 Handle<Object> value;
797 ASSIGN_RETURN_ON_EXCEPTION( 802 ASSIGN_RETURN_ON_EXCEPTION(
798 isolate, value, 803 isolate, value,
799 ElementsAccessorSubclass::GetImpl(receiver, holder, key, from), 804 ElementsAccessorSubclass::GetImpl(receiver, holder, key, from),
800 FixedArray); 805 FixedArray);
801 if (filter == FixedArray::NON_SYMBOL_KEYS && value->IsSymbol()) { 806 if (filter == FixedArray::NON_SYMBOL_KEYS && value->IsSymbol()) {
802 continue; 807 continue;
803 } 808 }
804 if (!value->IsTheHole() && !HasKey(to, value)) { 809 if (!value->IsTheHole() && !HasKey(to, value)) {
805 result->set(len0 + index, *value); 810 result->set(len0 + index, *value);
806 index++; 811 index++;
807 } 812 }
808 } 813 }
809 } 814 }
810 DCHECK(extra == index); 815 DCHECK(extra == index);
811 return result; 816 return result;
812 } 817 }
813 818
814 protected: 819 protected:
815 static uint32_t GetCapacityImpl(FixedArrayBase* backing_store) { 820 static uint32_t GetCapacityImpl(Handle<FixedArrayBase> backing_store) {
816 return backing_store->length(); 821 return backing_store->length();
817 } 822 }
818 823
819 uint32_t GetCapacity(FixedArrayBase* backing_store) FINAL { 824 uint32_t GetCapacity(Handle<FixedArrayBase> backing_store) FINAL {
820 return ElementsAccessorSubclass::GetCapacityImpl(backing_store); 825 return ElementsAccessorSubclass::GetCapacityImpl(backing_store);
821 } 826 }
822 827
823 static uint32_t GetKeyForIndexImpl(Handle<FixedArrayBase> backing_store, 828 static uint32_t GetKeyForIndexImpl(Handle<FixedArrayBase> backing_store,
824 uint32_t index) { 829 uint32_t index) {
825 return index; 830 return index;
826 } 831 }
827 832
828 virtual uint32_t GetKeyForIndex(Handle<FixedArrayBase> backing_store, 833 virtual uint32_t GetKeyForIndex(Handle<FixedArrayBase> backing_store,
829 uint32_t index) FINAL { 834 uint32_t index) FINAL {
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
957 } 962 }
958 } 963 }
959 return isolate->factory()->true_value(); 964 return isolate->factory()->true_value();
960 } 965 }
961 966
962 virtual MaybeHandle<Object> Delete(Handle<JSObject> obj, uint32_t key, 967 virtual MaybeHandle<Object> Delete(Handle<JSObject> obj, uint32_t key,
963 LanguageMode language_mode) FINAL { 968 LanguageMode language_mode) FINAL {
964 return DeleteCommon(obj, key, language_mode); 969 return DeleteCommon(obj, key, language_mode);
965 } 970 }
966 971
967 static bool HasElementImpl(JSObject* holder, uint32_t key, 972 static bool HasElementImpl(
968 FixedArrayBase* backing_store) { 973 Handle<JSObject> holder,
974 uint32_t key,
975 Handle<FixedArrayBase> backing_store) {
969 if (key >= static_cast<uint32_t>(backing_store->length())) { 976 if (key >= static_cast<uint32_t>(backing_store->length())) {
970 return false; 977 return false;
971 } 978 }
972 return !BackingStore::cast(backing_store)->is_the_hole(key); 979 return !Handle<BackingStore>::cast(backing_store)->is_the_hole(key);
973 } 980 }
974 981
975 static void ValidateContents(Handle<JSObject> holder, int length) { 982 static void ValidateContents(Handle<JSObject> holder, int length) {
976 #if DEBUG 983 #if DEBUG
977 Isolate* isolate = holder->GetIsolate(); 984 Isolate* isolate = holder->GetIsolate();
978 HandleScope scope(isolate); 985 HandleScope scope(isolate);
979 Handle<FixedArrayBase> elements(holder->elements(), isolate); 986 Handle<FixedArrayBase> elements(holder->elements(), isolate);
980 Map* map = elements->map(); 987 Map* map = elements->map();
981 DCHECK((IsFastSmiOrObjectElementsKind(KindTraits::Kind) && 988 DCHECK((IsFastSmiOrObjectElementsKind(KindTraits::Kind) &&
982 (map == isolate->heap()->fixed_array_map() || 989 (map == isolate->heap()->fixed_array_map() ||
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
1246 typedef TypedElementsAccessor<Kind> AccessorClass; 1253 typedef TypedElementsAccessor<Kind> AccessorClass;
1247 1254
1248 friend class ElementsAccessorBase<AccessorClass, 1255 friend class ElementsAccessorBase<AccessorClass,
1249 ElementsKindTraits<Kind> >; 1256 ElementsKindTraits<Kind> >;
1250 1257
1251 MUST_USE_RESULT static MaybeHandle<Object> GetImpl( 1258 MUST_USE_RESULT static MaybeHandle<Object> GetImpl(
1252 Handle<Object> receiver, 1259 Handle<Object> receiver,
1253 Handle<JSObject> obj, 1260 Handle<JSObject> obj,
1254 uint32_t key, 1261 uint32_t key,
1255 Handle<FixedArrayBase> backing_store) { 1262 Handle<FixedArrayBase> backing_store) {
1256 if (key < AccessorClass::GetCapacityImpl(*backing_store)) { 1263 if (key < AccessorClass::GetCapacityImpl(backing_store)) {
1257 return BackingStore::get(Handle<BackingStore>::cast(backing_store), key); 1264 return BackingStore::get(Handle<BackingStore>::cast(backing_store), key);
1258 } else { 1265 } else {
1259 return backing_store->GetIsolate()->factory()->undefined_value(); 1266 return backing_store->GetIsolate()->factory()->undefined_value();
1260 } 1267 }
1261 } 1268 }
1262 1269
1263 MUST_USE_RESULT static PropertyAttributes GetAttributesImpl( 1270 MUST_USE_RESULT static PropertyAttributes GetAttributesImpl(
1264 JSObject* obj, uint32_t key, FixedArrayBase* backing_store) { 1271 Handle<JSObject> obj,
1272 uint32_t key,
1273 Handle<FixedArrayBase> backing_store) {
1265 return 1274 return
1266 key < AccessorClass::GetCapacityImpl(backing_store) 1275 key < AccessorClass::GetCapacityImpl(backing_store)
1267 ? NONE : ABSENT; 1276 ? NONE : ABSENT;
1268 } 1277 }
1269 1278
1270 MUST_USE_RESULT static MaybeHandle<Object> SetLengthImpl( 1279 MUST_USE_RESULT static MaybeHandle<Object> SetLengthImpl(
1271 Handle<JSObject> obj, 1280 Handle<JSObject> obj,
1272 Handle<Object> length, 1281 Handle<Object> length,
1273 Handle<FixedArrayBase> backing_store) { 1282 Handle<FixedArrayBase> backing_store) {
1274 // External arrays do not support changing their length. 1283 // External arrays do not support changing their length.
1275 UNREACHABLE(); 1284 UNREACHABLE();
1276 return obj; 1285 return obj;
1277 } 1286 }
1278 1287
1279 MUST_USE_RESULT virtual MaybeHandle<Object> Delete( 1288 MUST_USE_RESULT virtual MaybeHandle<Object> Delete(
1280 Handle<JSObject> obj, uint32_t key, LanguageMode language_mode) FINAL { 1289 Handle<JSObject> obj, uint32_t key, LanguageMode language_mode) FINAL {
1281 // External arrays always ignore deletes. 1290 // External arrays always ignore deletes.
1282 return obj->GetIsolate()->factory()->true_value(); 1291 return obj->GetIsolate()->factory()->true_value();
1283 } 1292 }
1284 1293
1285 static bool HasElementImpl(JSObject* holder, uint32_t key, 1294 static bool HasElementImpl(Handle<JSObject> holder, uint32_t key,
1286 FixedArrayBase* backing_store) { 1295 Handle<FixedArrayBase> backing_store) {
1287 uint32_t capacity = 1296 uint32_t capacity =
1288 AccessorClass::GetCapacityImpl(backing_store); 1297 AccessorClass::GetCapacityImpl(backing_store);
1289 return key < capacity; 1298 return key < capacity;
1290 } 1299 }
1291 }; 1300 };
1292 1301
1293 1302
1294 1303
1295 #define EXTERNAL_ELEMENTS_ACCESSOR(Type, type, TYPE, ctype, size) \ 1304 #define EXTERNAL_ELEMENTS_ACCESSOR(Type, type, TYPE, ctype, size) \
1296 typedef TypedElementsAccessor<EXTERNAL_##TYPE##_ELEMENTS> \ 1305 typedef TypedElementsAccessor<EXTERNAL_##TYPE##_ELEMENTS> \
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
1445 return JSObject::GetElementWithCallback( 1454 return JSObject::GetElementWithCallback(
1446 obj, receiver, element, key, obj); 1455 obj, receiver, element, key, obj);
1447 } else { 1456 } else {
1448 return element; 1457 return element;
1449 } 1458 }
1450 } 1459 }
1451 return isolate->factory()->the_hole_value(); 1460 return isolate->factory()->the_hole_value();
1452 } 1461 }
1453 1462
1454 MUST_USE_RESULT static PropertyAttributes GetAttributesImpl( 1463 MUST_USE_RESULT static PropertyAttributes GetAttributesImpl(
1455 JSObject* obj, uint32_t key, FixedArrayBase* backing_store) { 1464 Handle<JSObject> obj,
1456 SeededNumberDictionary* dictionary = 1465 uint32_t key,
1457 SeededNumberDictionary::cast(backing_store); 1466 Handle<FixedArrayBase> backing_store) {
1467 Handle<SeededNumberDictionary> dictionary =
1468 Handle<SeededNumberDictionary>::cast(backing_store);
1458 int entry = dictionary->FindEntry(key); 1469 int entry = dictionary->FindEntry(key);
1459 if (entry != SeededNumberDictionary::kNotFound) { 1470 if (entry != SeededNumberDictionary::kNotFound) {
1460 return dictionary->DetailsAt(entry).attributes(); 1471 return dictionary->DetailsAt(entry).attributes();
1461 } 1472 }
1462 return ABSENT; 1473 return ABSENT;
1463 } 1474 }
1464 1475
1465 MUST_USE_RESULT static MaybeHandle<AccessorPair> GetAccessorPairImpl( 1476 MUST_USE_RESULT static MaybeHandle<AccessorPair> GetAccessorPairImpl(
1466 Handle<JSObject> obj, 1477 Handle<JSObject> obj,
1467 uint32_t key, 1478 uint32_t key,
1468 Handle<FixedArrayBase> store) { 1479 Handle<FixedArrayBase> store) {
1469 Handle<SeededNumberDictionary> backing_store = 1480 Handle<SeededNumberDictionary> backing_store =
1470 Handle<SeededNumberDictionary>::cast(store); 1481 Handle<SeededNumberDictionary>::cast(store);
1471 int entry = backing_store->FindEntry(key); 1482 int entry = backing_store->FindEntry(key);
1472 if (entry != SeededNumberDictionary::kNotFound && 1483 if (entry != SeededNumberDictionary::kNotFound &&
1473 backing_store->DetailsAt(entry).type() == ACCESSOR_CONSTANT && 1484 backing_store->DetailsAt(entry).type() == ACCESSOR_CONSTANT &&
1474 backing_store->ValueAt(entry)->IsAccessorPair()) { 1485 backing_store->ValueAt(entry)->IsAccessorPair()) {
1475 return handle(AccessorPair::cast(backing_store->ValueAt(entry))); 1486 return handle(AccessorPair::cast(backing_store->ValueAt(entry)));
1476 } 1487 }
1477 return MaybeHandle<AccessorPair>(); 1488 return MaybeHandle<AccessorPair>();
1478 } 1489 }
1479 1490
1480 static bool HasElementImpl(JSObject* holder, uint32_t key, 1491 static bool HasElementImpl(Handle<JSObject> holder, uint32_t key,
1481 FixedArrayBase* store) { 1492 Handle<FixedArrayBase> store) {
1482 SeededNumberDictionary* backing_store = SeededNumberDictionary::cast(store); 1493 Handle<SeededNumberDictionary> backing_store =
1494 Handle<SeededNumberDictionary>::cast(store);
1483 return backing_store->FindEntry(key) != SeededNumberDictionary::kNotFound; 1495 return backing_store->FindEntry(key) != SeededNumberDictionary::kNotFound;
1484 } 1496 }
1485 1497
1486 static uint32_t GetKeyForIndexImpl(Handle<FixedArrayBase> store, 1498 static uint32_t GetKeyForIndexImpl(Handle<FixedArrayBase> store,
1487 uint32_t index) { 1499 uint32_t index) {
1488 DisallowHeapAllocation no_gc; 1500 DisallowHeapAllocation no_gc;
1489 Handle<SeededNumberDictionary> dict = 1501 Handle<SeededNumberDictionary> dict =
1490 Handle<SeededNumberDictionary>::cast(store); 1502 Handle<SeededNumberDictionary>::cast(store);
1491 Object* key = dict->KeyAt(index); 1503 Object* key = dict->KeyAt(index);
1492 return Smi::cast(key)->value(); 1504 return Smi::cast(key)->value();
(...skipping 14 matching lines...) Expand all
1507 SloppyArgumentsElementsAccessor, 1519 SloppyArgumentsElementsAccessor,
1508 ElementsKindTraits<SLOPPY_ARGUMENTS_ELEMENTS> >; 1520 ElementsKindTraits<SLOPPY_ARGUMENTS_ELEMENTS> >;
1509 1521
1510 MUST_USE_RESULT static MaybeHandle<Object> GetImpl( 1522 MUST_USE_RESULT static MaybeHandle<Object> GetImpl(
1511 Handle<Object> receiver, 1523 Handle<Object> receiver,
1512 Handle<JSObject> obj, 1524 Handle<JSObject> obj,
1513 uint32_t key, 1525 uint32_t key,
1514 Handle<FixedArrayBase> parameters) { 1526 Handle<FixedArrayBase> parameters) {
1515 Isolate* isolate = obj->GetIsolate(); 1527 Isolate* isolate = obj->GetIsolate();
1516 Handle<FixedArray> parameter_map = Handle<FixedArray>::cast(parameters); 1528 Handle<FixedArray> parameter_map = Handle<FixedArray>::cast(parameters);
1517 Object* probe = GetParameterMapArg(*obj, *parameter_map, key); 1529 Handle<Object> probe = GetParameterMapArg(obj, parameter_map, key);
1518 if (!probe->IsTheHole()) { 1530 if (!probe->IsTheHole()) {
1519 DisallowHeapAllocation no_gc; 1531 DisallowHeapAllocation no_gc;
1520 Context* context = Context::cast(parameter_map->get(0)); 1532 Context* context = Context::cast(parameter_map->get(0));
1521 int context_index = Smi::cast(probe)->value(); 1533 int context_index = Handle<Smi>::cast(probe)->value();
1522 DCHECK(!context->get(context_index)->IsTheHole()); 1534 DCHECK(!context->get(context_index)->IsTheHole());
1523 return handle(context->get(context_index), isolate); 1535 return handle(context->get(context_index), isolate);
1524 } else { 1536 } else {
1525 // Object is not mapped, defer to the arguments. 1537 // Object is not mapped, defer to the arguments.
1526 Handle<FixedArray> arguments(FixedArray::cast(parameter_map->get(1)), 1538 Handle<FixedArray> arguments(FixedArray::cast(parameter_map->get(1)),
1527 isolate); 1539 isolate);
1528 Handle<Object> result; 1540 Handle<Object> result;
1529 ASSIGN_RETURN_ON_EXCEPTION(isolate, result, 1541 ASSIGN_RETURN_ON_EXCEPTION(
1530 ElementsAccessor::ForArray(*arguments) 1542 isolate, result,
1531 ->Get(receiver, obj, key, arguments), 1543 ElementsAccessor::ForArray(arguments)->Get(
1532 Object); 1544 receiver, obj, key, arguments),
1545 Object);
1533 // Elements of the arguments object in slow mode might be slow aliases. 1546 // Elements of the arguments object in slow mode might be slow aliases.
1534 if (result->IsAliasedArgumentsEntry()) { 1547 if (result->IsAliasedArgumentsEntry()) {
1535 DisallowHeapAllocation no_gc; 1548 DisallowHeapAllocation no_gc;
1536 AliasedArgumentsEntry* entry = AliasedArgumentsEntry::cast(*result); 1549 AliasedArgumentsEntry* entry = AliasedArgumentsEntry::cast(*result);
1537 Context* context = Context::cast(parameter_map->get(0)); 1550 Context* context = Context::cast(parameter_map->get(0));
1538 int context_index = entry->aliased_context_slot(); 1551 int context_index = entry->aliased_context_slot();
1539 DCHECK(!context->get(context_index)->IsTheHole()); 1552 DCHECK(!context->get(context_index)->IsTheHole());
1540 return handle(context->get(context_index), isolate); 1553 return handle(context->get(context_index), isolate);
1541 } else { 1554 } else {
1542 return result; 1555 return result;
1543 } 1556 }
1544 } 1557 }
1545 } 1558 }
1546 1559
1547 MUST_USE_RESULT static PropertyAttributes GetAttributesImpl( 1560 MUST_USE_RESULT static PropertyAttributes GetAttributesImpl(
1548 JSObject* obj, uint32_t key, FixedArrayBase* backing_store) { 1561 Handle<JSObject> obj,
1549 FixedArray* parameter_map = FixedArray::cast(backing_store); 1562 uint32_t key,
1550 Object* probe = GetParameterMapArg(obj, parameter_map, key); 1563 Handle<FixedArrayBase> backing_store) {
1564 Handle<FixedArray> parameter_map = Handle<FixedArray>::cast(backing_store);
1565 Handle<Object> probe = GetParameterMapArg(obj, parameter_map, key);
1551 if (!probe->IsTheHole()) { 1566 if (!probe->IsTheHole()) {
1552 return NONE; 1567 return NONE;
1553 } else { 1568 } else {
1554 // If not aliased, check the arguments. 1569 // If not aliased, check the arguments.
1555 FixedArray* arguments = FixedArray::cast(parameter_map->get(1)); 1570 Handle<FixedArray> arguments(FixedArray::cast(parameter_map->get(1)));
1556 return ElementsAccessor::ForArray(arguments) 1571 return ElementsAccessor::ForArray(arguments)
1557 ->GetAttributes(obj, key, arguments); 1572 ->GetAttributes(obj, key, arguments);
1558 } 1573 }
1559 } 1574 }
1560 1575
1561 MUST_USE_RESULT static MaybeHandle<AccessorPair> GetAccessorPairImpl( 1576 MUST_USE_RESULT static MaybeHandle<AccessorPair> GetAccessorPairImpl(
1562 Handle<JSObject> obj, 1577 Handle<JSObject> obj,
1563 uint32_t key, 1578 uint32_t key,
1564 Handle<FixedArrayBase> parameters) { 1579 Handle<FixedArrayBase> parameters) {
1565 Handle<FixedArray> parameter_map = Handle<FixedArray>::cast(parameters); 1580 Handle<FixedArray> parameter_map = Handle<FixedArray>::cast(parameters);
1566 Object* probe = GetParameterMapArg(*obj, *parameter_map, key); 1581 Handle<Object> probe = GetParameterMapArg(obj, parameter_map, key);
1567 if (!probe->IsTheHole()) { 1582 if (!probe->IsTheHole()) {
1568 return MaybeHandle<AccessorPair>(); 1583 return MaybeHandle<AccessorPair>();
1569 } else { 1584 } else {
1570 // If not aliased, check the arguments. 1585 // If not aliased, check the arguments.
1571 Handle<FixedArray> arguments(FixedArray::cast(parameter_map->get(1))); 1586 Handle<FixedArray> arguments(FixedArray::cast(parameter_map->get(1)));
1572 return ElementsAccessor::ForArray(*arguments) 1587 return ElementsAccessor::ForArray(arguments)
1573 ->GetAccessorPair(obj, key, arguments); 1588 ->GetAccessorPair(obj, key, arguments);
1574 } 1589 }
1575 } 1590 }
1576 1591
1577 MUST_USE_RESULT static MaybeHandle<Object> SetLengthImpl( 1592 MUST_USE_RESULT static MaybeHandle<Object> SetLengthImpl(
1578 Handle<JSObject> obj, 1593 Handle<JSObject> obj,
1579 Handle<Object> length, 1594 Handle<Object> length,
1580 Handle<FixedArrayBase> parameter_map) { 1595 Handle<FixedArrayBase> parameter_map) {
1581 // TODO(mstarzinger): This was never implemented but will be used once we 1596 // TODO(mstarzinger): This was never implemented but will be used once we
1582 // correctly implement [[DefineOwnProperty]] on arrays. 1597 // correctly implement [[DefineOwnProperty]] on arrays.
1583 UNIMPLEMENTED(); 1598 UNIMPLEMENTED();
1584 return obj; 1599 return obj;
1585 } 1600 }
1586 1601
1587 MUST_USE_RESULT virtual MaybeHandle<Object> Delete( 1602 MUST_USE_RESULT virtual MaybeHandle<Object> Delete(
1588 Handle<JSObject> obj, uint32_t key, LanguageMode language_mode) FINAL { 1603 Handle<JSObject> obj, uint32_t key, LanguageMode language_mode) FINAL {
1589 Isolate* isolate = obj->GetIsolate(); 1604 Isolate* isolate = obj->GetIsolate();
1590 Handle<FixedArray> parameter_map(FixedArray::cast(obj->elements())); 1605 Handle<FixedArray> parameter_map(FixedArray::cast(obj->elements()));
1591 Handle<Object> probe(GetParameterMapArg(*obj, *parameter_map, key), 1606 Handle<Object> probe = GetParameterMapArg(obj, parameter_map, key);
1592 isolate);
1593 if (!probe->IsTheHole()) { 1607 if (!probe->IsTheHole()) {
1594 // TODO(kmillikin): We could check if this was the last aliased 1608 // TODO(kmillikin): We could check if this was the last aliased
1595 // parameter, and revert to normal elements in that case. That 1609 // parameter, and revert to normal elements in that case. That
1596 // would enable GC of the context. 1610 // would enable GC of the context.
1597 parameter_map->set_the_hole(key + 2); 1611 parameter_map->set_the_hole(key + 2);
1598 } else { 1612 } else {
1599 Handle<FixedArray> arguments(FixedArray::cast(parameter_map->get(1))); 1613 Handle<FixedArray> arguments(FixedArray::cast(parameter_map->get(1)));
1600 if (arguments->IsDictionary()) { 1614 if (arguments->IsDictionary()) {
1601 return DictionaryElementsAccessor::DeleteCommon(obj, key, 1615 return DictionaryElementsAccessor::DeleteCommon(obj, key,
1602 language_mode); 1616 language_mode);
1603 } else { 1617 } else {
1604 // It's difficult to access the version of DeleteCommon that is declared 1618 // It's difficult to access the version of DeleteCommon that is declared
1605 // in the templatized super class, call the concrete implementation in 1619 // in the templatized super class, call the concrete implementation in
1606 // the class for the most generalized ElementsKind subclass. 1620 // the class for the most generalized ElementsKind subclass.
1607 return FastHoleyObjectElementsAccessor::DeleteCommon(obj, key, 1621 return FastHoleyObjectElementsAccessor::DeleteCommon(obj, key,
1608 language_mode); 1622 language_mode);
1609 } 1623 }
1610 } 1624 }
1611 return isolate->factory()->true_value(); 1625 return isolate->factory()->true_value();
1612 } 1626 }
1613 1627
1614 static void CopyElementsImpl(FixedArrayBase* from, uint32_t from_start, 1628 static void CopyElementsImpl(FixedArrayBase* from, uint32_t from_start,
1615 FixedArrayBase* to, ElementsKind from_kind, 1629 FixedArrayBase* to, ElementsKind from_kind,
1616 uint32_t to_start, int packed_size, 1630 uint32_t to_start, int packed_size,
1617 int copy_size) { 1631 int copy_size) {
1618 UNREACHABLE(); 1632 UNREACHABLE();
1619 } 1633 }
1620 1634
1621 static uint32_t GetCapacityImpl(FixedArrayBase* backing_store) { 1635 static uint32_t GetCapacityImpl(Handle<FixedArrayBase> backing_store) {
1622 FixedArray* parameter_map = FixedArray::cast(backing_store); 1636 Handle<FixedArray> parameter_map = Handle<FixedArray>::cast(backing_store);
1623 FixedArrayBase* arguments = FixedArrayBase::cast(parameter_map->get(1)); 1637 Handle<FixedArrayBase> arguments(
1638 FixedArrayBase::cast(parameter_map->get(1)));
1624 return Max(static_cast<uint32_t>(parameter_map->length() - 2), 1639 return Max(static_cast<uint32_t>(parameter_map->length() - 2),
1625 ForArray(arguments)->GetCapacity(arguments)); 1640 ForArray(arguments)->GetCapacity(arguments));
1626 } 1641 }
1627 1642
1628 static uint32_t GetKeyForIndexImpl(Handle<FixedArrayBase> dict, 1643 static uint32_t GetKeyForIndexImpl(Handle<FixedArrayBase> dict,
1629 uint32_t index) { 1644 uint32_t index) {
1630 return index; 1645 return index;
1631 } 1646 }
1632 1647
1633 private: 1648 private:
1634 static Object* GetParameterMapArg(JSObject* holder, FixedArray* parameter_map, 1649 static Handle<Object> GetParameterMapArg(Handle<JSObject> holder,
1635 uint32_t key) { 1650 Handle<FixedArray> parameter_map,
1651 uint32_t key) {
1636 Isolate* isolate = holder->GetIsolate(); 1652 Isolate* isolate = holder->GetIsolate();
1637 uint32_t length = holder->IsJSArray() 1653 uint32_t length = holder->IsJSArray()
1638 ? Smi::cast(JSArray::cast(holder)->length())->value() 1654 ? Smi::cast(Handle<JSArray>::cast(holder)->length())->value()
1639 : parameter_map->length(); 1655 : parameter_map->length();
1640 return key < (length - 2) ? parameter_map->get(key + 2) 1656 return key < (length - 2)
1641 : isolate->heap()->the_hole_value(); 1657 ? handle(parameter_map->get(key + 2), isolate)
1658 : Handle<Object>::cast(isolate->factory()->the_hole_value());
1642 } 1659 }
1643 }; 1660 };
1644 1661
1645 1662
1646 ElementsAccessor* ElementsAccessor::ForArray(FixedArrayBase* array) { 1663 ElementsAccessor* ElementsAccessor::ForArray(Handle<FixedArrayBase> array) {
1647 return elements_accessors_[ElementsKindForArray(array)]; 1664 return elements_accessors_[ElementsKindForArray(*array)];
1648 } 1665 }
1649 1666
1650 1667
1651 void ElementsAccessor::InitializeOncePerProcess() { 1668 void ElementsAccessor::InitializeOncePerProcess() {
1652 static ElementsAccessor* accessor_array[] = { 1669 static ElementsAccessor* accessor_array[] = {
1653 #define ACCESSOR_ARRAY(Class, Kind, Store) new Class(#Kind), 1670 #define ACCESSOR_ARRAY(Class, Kind, Store) new Class(#Kind),
1654 ELEMENTS_LIST(ACCESSOR_ARRAY) 1671 ELEMENTS_LIST(ACCESSOR_ARRAY)
1655 #undef ACCESSOR_ARRAY 1672 #undef ACCESSOR_ARRAY
1656 }; 1673 };
1657 1674
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
1826 UNREACHABLE(); 1843 UNREACHABLE();
1827 break; 1844 break;
1828 } 1845 }
1829 1846
1830 array->set_elements(*elms); 1847 array->set_elements(*elms);
1831 array->set_length(Smi::FromInt(number_of_elements)); 1848 array->set_length(Smi::FromInt(number_of_elements));
1832 return array; 1849 return array;
1833 } 1850 }
1834 1851
1835 } } // namespace v8::internal 1852 } } // namespace v8::internal
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