OLD | NEW |
---|---|
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 617 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
628 | 628 |
629 virtual bool HasElement( | 629 virtual bool HasElement( |
630 Handle<Object> receiver, | 630 Handle<Object> receiver, |
631 Handle<JSObject> holder, | 631 Handle<JSObject> holder, |
632 uint32_t key, | 632 uint32_t key, |
633 Handle<FixedArrayBase> backing_store) V8_FINAL V8_OVERRIDE { | 633 Handle<FixedArrayBase> backing_store) V8_FINAL V8_OVERRIDE { |
634 return ElementsAccessorSubclass::HasElementImpl( | 634 return ElementsAccessorSubclass::HasElementImpl( |
635 receiver, holder, key, backing_store); | 635 receiver, holder, key, backing_store); |
636 } | 636 } |
637 | 637 |
638 // TODO(ishell): Temporary wrapper until handlified. | 638 MUST_USE_RESULT virtual MaybeHandle<Object> Get( |
639 MUST_USE_RESULT virtual Handle<Object> Get( | |
640 Handle<Object> receiver, | 639 Handle<Object> receiver, |
641 Handle<JSObject> holder, | 640 Handle<JSObject> holder, |
642 uint32_t key, | 641 uint32_t key, |
643 Handle<FixedArrayBase> backing_store) V8_FINAL V8_OVERRIDE { | 642 Handle<FixedArrayBase> backing_store) V8_FINAL V8_OVERRIDE { |
644 if (!IsExternalArrayElementsKind(ElementsTraits::Kind) && | 643 if (!IsExternalArrayElementsKind(ElementsTraits::Kind) && |
645 FLAG_trace_js_array_abuse) { | 644 FLAG_trace_js_array_abuse) { |
646 CheckArrayAbuse(holder, "elements read", key); | 645 CheckArrayAbuse(holder, "elements read", key); |
647 } | 646 } |
648 | 647 |
649 if (IsExternalArrayElementsKind(ElementsTraits::Kind) && | 648 if (IsExternalArrayElementsKind(ElementsTraits::Kind) && |
650 FLAG_trace_external_array_abuse) { | 649 FLAG_trace_external_array_abuse) { |
651 CheckArrayAbuse(holder, "external elements read", key); | 650 CheckArrayAbuse(holder, "external elements read", key); |
652 } | 651 } |
653 | 652 |
654 return ElementsAccessorSubclass::GetImpl( | 653 return ElementsAccessorSubclass::GetImpl( |
655 receiver, holder, key, backing_store); | 654 receiver, holder, key, backing_store); |
656 } | 655 } |
657 | 656 |
658 static Handle<Object> GetImpl(Handle<Object> receiver, | 657 MUST_USE_RESULT static MaybeHandle<Object> GetImpl( |
659 Handle<JSObject> obj, | 658 Handle<Object> receiver, |
660 uint32_t key, | 659 Handle<JSObject> obj, |
661 Handle<FixedArrayBase> backing_store) { | 660 uint32_t key, |
661 Handle<FixedArrayBase> backing_store) { | |
662 if (key < ElementsAccessorSubclass::GetCapacityImpl(backing_store)) { | 662 if (key < ElementsAccessorSubclass::GetCapacityImpl(backing_store)) { |
663 return BackingStore::get(Handle<BackingStore>::cast(backing_store), key); | 663 return BackingStore::get(Handle<BackingStore>::cast(backing_store), key); |
664 } else { | 664 } else { |
665 return backing_store->GetIsolate()->factory()->the_hole_value(); | 665 return backing_store->GetIsolate()->factory()->the_hole_value(); |
666 } | 666 } |
667 } | 667 } |
668 | 668 |
669 MUST_USE_RESULT virtual PropertyAttributes GetAttributes( | 669 MUST_USE_RESULT virtual PropertyAttributes GetAttributes( |
670 Handle<Object> receiver, | 670 Handle<Object> receiver, |
671 Handle<JSObject> holder, | 671 Handle<JSObject> holder, |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
797 Smi::cast(JSArray::cast(from_holder)->length())->value(); | 797 Smi::cast(JSArray::cast(from_holder)->length())->value(); |
798 if (copy_size >= 0 && packed_size > copy_size) { | 798 if (copy_size >= 0 && packed_size > copy_size) { |
799 packed_size = copy_size; | 799 packed_size = copy_size; |
800 } | 800 } |
801 } | 801 } |
802 Handle<FixedArrayBase> from(from_holder->elements()); | 802 Handle<FixedArrayBase> from(from_holder->elements()); |
803 ElementsAccessorSubclass::CopyElementsImpl( | 803 ElementsAccessorSubclass::CopyElementsImpl( |
804 from, from_start, to, from_kind, to_start, packed_size, copy_size); | 804 from, from_start, to, from_kind, to_start, packed_size, copy_size); |
805 } | 805 } |
806 | 806 |
807 virtual Handle<FixedArray> AddElementsToFixedArray( | 807 virtual MaybeHandle<FixedArray> AddElementsToFixedArray( |
808 Handle<Object> receiver, | 808 Handle<Object> receiver, |
809 Handle<JSObject> holder, | 809 Handle<JSObject> holder, |
810 Handle<FixedArray> to, | 810 Handle<FixedArray> to, |
811 Handle<FixedArrayBase> from) V8_FINAL V8_OVERRIDE { | 811 Handle<FixedArrayBase> from) V8_FINAL V8_OVERRIDE { |
812 int len0 = to->length(); | 812 int len0 = to->length(); |
813 #ifdef ENABLE_SLOW_ASSERTS | 813 #ifdef ENABLE_SLOW_ASSERTS |
814 if (FLAG_enable_slow_asserts) { | 814 if (FLAG_enable_slow_asserts) { |
815 for (int i = 0; i < len0; i++) { | 815 for (int i = 0; i < len0; i++) { |
816 ASSERT(!to->get(i)->IsTheHole()); | 816 ASSERT(!to->get(i)->IsTheHole()); |
817 } | 817 } |
818 } | 818 } |
819 #endif | 819 #endif |
820 | 820 |
821 // Optimize if 'other' is empty. | 821 // Optimize if 'other' is empty. |
822 // We cannot optimize if 'this' is empty, as other may have holes. | 822 // We cannot optimize if 'this' is empty, as other may have holes. |
823 uint32_t len1 = ElementsAccessorSubclass::GetCapacityImpl(from); | 823 uint32_t len1 = ElementsAccessorSubclass::GetCapacityImpl(from); |
824 if (len1 == 0) return to; | 824 if (len1 == 0) return to; |
825 | 825 |
826 Isolate* isolate = from->GetIsolate(); | |
827 | |
826 // Compute how many elements are not in other. | 828 // Compute how many elements are not in other. |
827 uint32_t extra = 0; | 829 uint32_t extra = 0; |
828 for (uint32_t y = 0; y < len1; y++) { | 830 for (uint32_t y = 0; y < len1; y++) { |
829 uint32_t key = ElementsAccessorSubclass::GetKeyForIndexImpl(from, y); | 831 uint32_t key = ElementsAccessorSubclass::GetKeyForIndexImpl(from, y); |
830 if (ElementsAccessorSubclass::HasElementImpl( | 832 if (ElementsAccessorSubclass::HasElementImpl( |
831 receiver, holder, key, from)) { | 833 receiver, holder, key, from)) { |
832 Handle<Object> value = | 834 Handle<Object> value; |
833 ElementsAccessorSubclass::GetImpl(receiver, holder, key, from); | 835 ASSIGN_RETURN_ON_EXCEPTION( |
836 isolate, value, | |
837 ElementsAccessorSubclass::GetImpl(receiver, holder, key, from), | |
838 FixedArray); | |
834 | 839 |
835 ASSERT(!value->IsTheHole()); | 840 ASSERT(!value->IsTheHole()); |
836 if (!HasKey(to, value)) { | 841 if (!HasKey(to, value)) { |
837 extra++; | 842 extra++; |
838 } | 843 } |
839 } | 844 } |
840 } | 845 } |
841 | 846 |
842 if (extra == 0) return to; | 847 if (extra == 0) return to; |
843 | 848 |
844 // Allocate the result | 849 // Allocate the result |
845 Isolate* isolate = from->GetIsolate(); | |
846 Handle<FixedArray> result = isolate->factory()->NewFixedArray(len0 + extra); | 850 Handle<FixedArray> result = isolate->factory()->NewFixedArray(len0 + extra); |
847 | 851 |
848 // Fill in the content | 852 // Fill in the content |
849 { | 853 { |
850 DisallowHeapAllocation no_gc; | 854 DisallowHeapAllocation no_gc; |
851 WriteBarrierMode mode = result->GetWriteBarrierMode(no_gc); | 855 WriteBarrierMode mode = result->GetWriteBarrierMode(no_gc); |
852 for (int i = 0; i < len0; i++) { | 856 for (int i = 0; i < len0; i++) { |
853 Object* e = to->get(i); | 857 Object* e = to->get(i); |
854 ASSERT(e->IsString() || e->IsNumber()); | 858 ASSERT(e->IsString() || e->IsNumber()); |
855 result->set(i, e, mode); | 859 result->set(i, e, mode); |
856 } | 860 } |
857 } | 861 } |
858 // Fill in the extra values. | 862 // Fill in the extra values. |
859 uint32_t index = 0; | 863 uint32_t index = 0; |
860 for (uint32_t y = 0; y < len1; y++) { | 864 for (uint32_t y = 0; y < len1; y++) { |
861 uint32_t key = | 865 uint32_t key = |
862 ElementsAccessorSubclass::GetKeyForIndexImpl(from, y); | 866 ElementsAccessorSubclass::GetKeyForIndexImpl(from, y); |
863 if (ElementsAccessorSubclass::HasElementImpl( | 867 if (ElementsAccessorSubclass::HasElementImpl( |
864 receiver, holder, key, from)) { | 868 receiver, holder, key, from)) { |
865 Handle<Object> value = | 869 Handle<Object> value; |
866 ElementsAccessorSubclass::GetImpl(receiver, holder, key, from); | 870 ASSIGN_RETURN_ON_EXCEPTION( |
871 isolate, value, | |
872 ElementsAccessorSubclass::GetImpl(receiver, holder, key, from), | |
873 FixedArray); | |
867 if (!value->IsTheHole() && !HasKey(to, value)) { | 874 if (!value->IsTheHole() && !HasKey(to, value)) { |
868 result->set(len0 + index, *value); | 875 result->set(len0 + index, *value); |
869 index++; | 876 index++; |
870 } | 877 } |
871 } | 878 } |
872 } | 879 } |
873 ASSERT(extra == index); | 880 ASSERT(extra == index); |
874 return result; | 881 return result; |
875 } | 882 } |
876 | 883 |
(...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1326 : ElementsAccessorBase<AccessorClass, | 1333 : ElementsAccessorBase<AccessorClass, |
1327 ElementsKindTraits<Kind> >(name) {} | 1334 ElementsKindTraits<Kind> >(name) {} |
1328 | 1335 |
1329 protected: | 1336 protected: |
1330 typedef typename ElementsKindTraits<Kind>::BackingStore BackingStore; | 1337 typedef typename ElementsKindTraits<Kind>::BackingStore BackingStore; |
1331 typedef TypedElementsAccessor<Kind> AccessorClass; | 1338 typedef TypedElementsAccessor<Kind> AccessorClass; |
1332 | 1339 |
1333 friend class ElementsAccessorBase<AccessorClass, | 1340 friend class ElementsAccessorBase<AccessorClass, |
1334 ElementsKindTraits<Kind> >; | 1341 ElementsKindTraits<Kind> >; |
1335 | 1342 |
1336 static Handle<Object> GetImpl(Handle<Object> receiver, | 1343 MUST_USE_RESULT static MaybeHandle<Object> GetImpl( |
1337 Handle<JSObject> obj, | 1344 Handle<Object> receiver, |
1338 uint32_t key, | 1345 Handle<JSObject> obj, |
1339 Handle<FixedArrayBase> backing_store) { | 1346 uint32_t key, |
1347 Handle<FixedArrayBase> backing_store) { | |
1340 if (key < AccessorClass::GetCapacityImpl(backing_store)) { | 1348 if (key < AccessorClass::GetCapacityImpl(backing_store)) { |
1341 return BackingStore::get(Handle<BackingStore>::cast(backing_store), key); | 1349 return BackingStore::get(Handle<BackingStore>::cast(backing_store), key); |
1342 } else { | 1350 } else { |
1343 return backing_store->GetIsolate()->factory()->undefined_value(); | 1351 return backing_store->GetIsolate()->factory()->undefined_value(); |
1344 } | 1352 } |
1345 } | 1353 } |
1346 | 1354 |
1347 MUST_USE_RESULT static PropertyAttributes GetAttributesImpl( | 1355 MUST_USE_RESULT static PropertyAttributes GetAttributesImpl( |
1348 Handle<Object> receiver, | 1356 Handle<Object> receiver, |
1349 Handle<JSObject> obj, | 1357 Handle<JSObject> obj, |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1533 friend class ElementsAccessorBase<DictionaryElementsAccessor, | 1541 friend class ElementsAccessorBase<DictionaryElementsAccessor, |
1534 ElementsKindTraits<DICTIONARY_ELEMENTS> >; | 1542 ElementsKindTraits<DICTIONARY_ELEMENTS> >; |
1535 | 1543 |
1536 MUST_USE_RESULT virtual MaybeHandle<Object> Delete( | 1544 MUST_USE_RESULT virtual MaybeHandle<Object> Delete( |
1537 Handle<JSObject> obj, | 1545 Handle<JSObject> obj, |
1538 uint32_t key, | 1546 uint32_t key, |
1539 JSReceiver::DeleteMode mode) V8_FINAL V8_OVERRIDE { | 1547 JSReceiver::DeleteMode mode) V8_FINAL V8_OVERRIDE { |
1540 return DeleteCommon(obj, key, mode); | 1548 return DeleteCommon(obj, key, mode); |
1541 } | 1549 } |
1542 | 1550 |
1543 static Handle<Object> GetImpl( | 1551 MUST_USE_RESULT static MaybeHandle<Object> GetImpl( |
1544 Handle<Object> receiver, | 1552 Handle<Object> receiver, |
1545 Handle<JSObject> obj, | 1553 Handle<JSObject> obj, |
1546 uint32_t key, | 1554 uint32_t key, |
1547 Handle<FixedArrayBase> store) { | 1555 Handle<FixedArrayBase> store) { |
1548 Handle<SeededNumberDictionary> backing_store = | 1556 Handle<SeededNumberDictionary> backing_store = |
1549 Handle<SeededNumberDictionary>::cast(store); | 1557 Handle<SeededNumberDictionary>::cast(store); |
1550 Isolate* isolate = backing_store->GetIsolate(); | 1558 Isolate* isolate = backing_store->GetIsolate(); |
1551 int entry = backing_store->FindEntry(key); | 1559 int entry = backing_store->FindEntry(key); |
1552 if (entry != SeededNumberDictionary::kNotFound) { | 1560 if (entry != SeededNumberDictionary::kNotFound) { |
1553 Handle<Object> element(backing_store->ValueAt(entry), isolate); | 1561 Handle<Object> element(backing_store->ValueAt(entry), isolate); |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1632 public: | 1640 public: |
1633 explicit SloppyArgumentsElementsAccessor(const char* name) | 1641 explicit SloppyArgumentsElementsAccessor(const char* name) |
1634 : ElementsAccessorBase< | 1642 : ElementsAccessorBase< |
1635 SloppyArgumentsElementsAccessor, | 1643 SloppyArgumentsElementsAccessor, |
1636 ElementsKindTraits<SLOPPY_ARGUMENTS_ELEMENTS> >(name) {} | 1644 ElementsKindTraits<SLOPPY_ARGUMENTS_ELEMENTS> >(name) {} |
1637 protected: | 1645 protected: |
1638 friend class ElementsAccessorBase< | 1646 friend class ElementsAccessorBase< |
1639 SloppyArgumentsElementsAccessor, | 1647 SloppyArgumentsElementsAccessor, |
1640 ElementsKindTraits<SLOPPY_ARGUMENTS_ELEMENTS> >; | 1648 ElementsKindTraits<SLOPPY_ARGUMENTS_ELEMENTS> >; |
1641 | 1649 |
1642 MUST_USE_RESULT static Handle<Object> GetImpl( | 1650 MUST_USE_RESULT static MaybeHandle<Object> GetImpl( |
1643 Handle<Object> receiver, | 1651 Handle<Object> receiver, |
1644 Handle<JSObject> obj, | 1652 Handle<JSObject> obj, |
1645 uint32_t key, | 1653 uint32_t key, |
1646 Handle<FixedArrayBase> parameters) { | 1654 Handle<FixedArrayBase> parameters) { |
1647 Isolate* isolate = obj->GetIsolate(); | 1655 Isolate* isolate = obj->GetIsolate(); |
1648 Handle<FixedArray> parameter_map = Handle<FixedArray>::cast(parameters); | 1656 Handle<FixedArray> parameter_map = Handle<FixedArray>::cast(parameters); |
1649 Handle<Object> probe = GetParameterMapArg(obj, parameter_map, key); | 1657 Handle<Object> probe = GetParameterMapArg(obj, parameter_map, key); |
1650 if (!probe->IsTheHole()) { | 1658 if (!probe->IsTheHole()) { |
1651 DisallowHeapAllocation no_gc; | 1659 DisallowHeapAllocation no_gc; |
1652 Context* context = Context::cast(parameter_map->get(0)); | 1660 Context* context = Context::cast(parameter_map->get(0)); |
1653 int context_index = Handle<Smi>::cast(probe)->value(); | 1661 int context_index = Handle<Smi>::cast(probe)->value(); |
1654 ASSERT(!context->get(context_index)->IsTheHole()); | 1662 ASSERT(!context->get(context_index)->IsTheHole()); |
1655 return handle(context->get(context_index), isolate); | 1663 return handle(context->get(context_index), isolate); |
1656 } else { | 1664 } else { |
1657 // Object is not mapped, defer to the arguments. | 1665 // Object is not mapped, defer to the arguments. |
1658 Handle<FixedArray> arguments(FixedArray::cast(parameter_map->get(1)), | 1666 Handle<FixedArray> arguments(FixedArray::cast(parameter_map->get(1)), |
1659 isolate); | 1667 isolate); |
1660 Handle<Object> result = ElementsAccessor::ForArray(arguments)->Get( | 1668 Handle<Object> result; |
1661 receiver, obj, key, arguments); | 1669 ASSIGN_RETURN_ON_EXCEPTION( |
1670 isolate, result, | |
1671 ElementsAccessor::ForArray(arguments)->Get( | |
1672 receiver, obj, key, arguments), | |
1673 Object); | |
1662 // Elements of the arguments object in slow mode might be slow aliases. | 1674 // Elements of the arguments object in slow mode might be slow aliases. |
1663 if (result->IsAliasedArgumentsEntry()) { | 1675 if (result->IsAliasedArgumentsEntry()) { |
1664 DisallowHeapAllocation no_gc; | 1676 DisallowHeapAllocation no_gc; |
1665 AliasedArgumentsEntry* entry = AliasedArgumentsEntry::cast(*result); | 1677 AliasedArgumentsEntry* entry = AliasedArgumentsEntry::cast(*result); |
1666 Context* context = Context::cast(parameter_map->get(0)); | 1678 Context* context = Context::cast(parameter_map->get(0)); |
1667 int context_index = entry->aliased_context_slot(); | 1679 int context_index = entry->aliased_context_slot(); |
1668 ASSERT(!context->get(context_index)->IsTheHole()); | 1680 ASSERT(!context->get(context_index)->IsTheHole()); |
1669 return handle(context->get(context_index), isolate); | 1681 return handle(context->get(context_index), isolate); |
1670 } else { | 1682 } else { |
1671 return result; | 1683 return result; |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1785 | 1797 |
1786 static bool HasElementImpl(Handle<Object> receiver, | 1798 static bool HasElementImpl(Handle<Object> receiver, |
1787 Handle<JSObject> holder, | 1799 Handle<JSObject> holder, |
1788 uint32_t key, | 1800 uint32_t key, |
1789 Handle<FixedArrayBase> parameters) { | 1801 Handle<FixedArrayBase> parameters) { |
1790 Handle<FixedArray> parameter_map = Handle<FixedArray>::cast(parameters); | 1802 Handle<FixedArray> parameter_map = Handle<FixedArray>::cast(parameters); |
1791 Handle<Object> probe = GetParameterMapArg(holder, parameter_map, key); | 1803 Handle<Object> probe = GetParameterMapArg(holder, parameter_map, key); |
1792 if (!probe->IsTheHole()) { | 1804 if (!probe->IsTheHole()) { |
1793 return true; | 1805 return true; |
1794 } else { | 1806 } else { |
1807 Isolate* isolate = holder->GetIsolate(); | |
1795 Handle<FixedArrayBase> arguments(FixedArrayBase::cast( | 1808 Handle<FixedArrayBase> arguments(FixedArrayBase::cast( |
1796 Handle<FixedArray>::cast(parameter_map)->get(1))); | 1809 Handle<FixedArray>::cast(parameter_map)->get(1)), isolate); |
1797 ElementsAccessor* accessor = ElementsAccessor::ForArray(arguments); | 1810 ElementsAccessor* accessor = ElementsAccessor::ForArray(arguments); |
1798 return !accessor->Get(receiver, holder, key, arguments)->IsTheHole(); | 1811 Handle<Object> value; |
1812 ASSIGN_RETURN_ON_EXCEPTION_VALUE( | |
1813 isolate, value, | |
1814 accessor->Get(receiver, holder, key, arguments), | |
1815 true); | |
Igor Sheludko
2014/04/09 16:12:09
I'm returning true in case of exception.
Yang
2014/04/10 07:05:22
I think we usually return false in those cases, se
Igor Sheludko
2014/04/10 08:27:54
Done.
| |
1816 return !value->IsTheHole(); | |
1799 } | 1817 } |
1800 } | 1818 } |
1801 | 1819 |
1802 private: | 1820 private: |
1803 static Handle<Object> GetParameterMapArg(Handle<JSObject> holder, | 1821 static Handle<Object> GetParameterMapArg(Handle<JSObject> holder, |
1804 Handle<FixedArray> parameter_map, | 1822 Handle<FixedArray> parameter_map, |
1805 uint32_t key) { | 1823 uint32_t key) { |
1806 Isolate* isolate = holder->GetIsolate(); | 1824 Isolate* isolate = holder->GetIsolate(); |
1807 uint32_t length = holder->IsJSArray() | 1825 uint32_t length = holder->IsJSArray() |
1808 ? Smi::cast(Handle<JSArray>::cast(holder)->length())->value() | 1826 ? Smi::cast(Handle<JSArray>::cast(holder)->length())->value() |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1995 UNREACHABLE(); | 2013 UNREACHABLE(); |
1996 break; | 2014 break; |
1997 } | 2015 } |
1998 | 2016 |
1999 array->set_elements(*elms); | 2017 array->set_elements(*elms); |
2000 array->set_length(Smi::FromInt(number_of_elements)); | 2018 array->set_length(Smi::FromInt(number_of_elements)); |
2001 return array; | 2019 return array; |
2002 } | 2020 } |
2003 | 2021 |
2004 } } // namespace v8::internal | 2022 } } // namespace v8::internal |
OLD | NEW |