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

Side by Side Diff: src/elements.cc

Issue 229943006: ElementsAccessor::SetLength() maybehandlified. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « src/elements.h ('k') | src/ic.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 // 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 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 if (element->IsSmi() && element == key) return true; 155 if (element->IsSmi() && element == key) return true;
156 if (element->IsString() && 156 if (element->IsString() &&
157 key->IsString() && String::cast(element)->Equals(String::cast(key))) { 157 key->IsString() && String::cast(element)->Equals(String::cast(key))) {
158 return true; 158 return true;
159 } 159 }
160 } 160 }
161 return false; 161 return false;
162 } 162 }
163 163
164 164
165 static Handle<Object> ThrowArrayLengthRangeError(Isolate* isolate) { 165 MUST_USE_RESULT
166 isolate->Throw( 166 static MaybeHandle<Object> ThrowArrayLengthRangeError(Isolate* isolate) {
167 *isolate->factory()->NewRangeError("invalid_array_length", 167 return isolate->Throw<Object>(
168 HandleVector<Object>(NULL, 0))); 168 isolate->factory()->NewRangeError("invalid_array_length",
169 return Handle<Object>(); 169 HandleVector<Object>(NULL, 0)));
170 } 170 }
171 171
172 172
173 static void CopyObjectToObjectElements(Handle<FixedArrayBase> from_base, 173 static void CopyObjectToObjectElements(Handle<FixedArrayBase> from_base,
174 ElementsKind from_kind, 174 ElementsKind from_kind,
175 uint32_t from_start, 175 uint32_t from_start,
176 Handle<FixedArrayBase> to_base, 176 Handle<FixedArrayBase> to_base,
177 ElementsKind to_kind, 177 ElementsKind to_kind,
178 uint32_t to_start, 178 uint32_t to_start,
179 int raw_copy_size) { 179 int raw_copy_size) {
(...skipping 540 matching lines...) Expand 10 before | Expand all | Expand 10 after
720 } 720 }
721 721
722 MUST_USE_RESULT static MaybeHandle<AccessorPair> GetAccessorPairImpl( 722 MUST_USE_RESULT static MaybeHandle<AccessorPair> GetAccessorPairImpl(
723 Handle<Object> receiver, 723 Handle<Object> receiver,
724 Handle<JSObject> obj, 724 Handle<JSObject> obj,
725 uint32_t key, 725 uint32_t key,
726 Handle<FixedArrayBase> backing_store) { 726 Handle<FixedArrayBase> backing_store) {
727 return MaybeHandle<AccessorPair>(); 727 return MaybeHandle<AccessorPair>();
728 } 728 }
729 729
730 MUST_USE_RESULT virtual Handle<Object> SetLength( 730 MUST_USE_RESULT virtual MaybeHandle<Object> SetLength(
731 Handle<JSArray> array, 731 Handle<JSArray> array,
732 Handle<Object> length) V8_FINAL V8_OVERRIDE { 732 Handle<Object> length) V8_FINAL V8_OVERRIDE {
733 return ElementsAccessorSubclass::SetLengthImpl( 733 return ElementsAccessorSubclass::SetLengthImpl(
734 array, length, handle(array->elements())); 734 array, length, handle(array->elements()));
735 } 735 }
736 736
737 MUST_USE_RESULT static Handle<Object> SetLengthImpl( 737 MUST_USE_RESULT static MaybeHandle<Object> SetLengthImpl(
738 Handle<JSObject> obj, 738 Handle<JSObject> obj,
739 Handle<Object> length, 739 Handle<Object> length,
740 Handle<FixedArrayBase> backing_store); 740 Handle<FixedArrayBase> backing_store);
741 741
742 virtual void SetCapacityAndLength( 742 virtual void SetCapacityAndLength(
743 Handle<JSArray> array, 743 Handle<JSArray> array,
744 int capacity, 744 int capacity,
745 int length) V8_FINAL V8_OVERRIDE { 745 int length) V8_FINAL V8_OVERRIDE {
746 ElementsAccessorSubclass:: 746 ElementsAccessorSubclass::
747 SetFastElementsCapacityAndLength(array, capacity, length); 747 SetFastElementsCapacityAndLength(array, capacity, length);
(...skipping 609 matching lines...) Expand 10 before | Expand all | Expand 10 after
1357 MUST_USE_RESULT static PropertyType GetTypeImpl( 1357 MUST_USE_RESULT static PropertyType GetTypeImpl(
1358 Handle<Object> receiver, 1358 Handle<Object> receiver,
1359 Handle<JSObject> obj, 1359 Handle<JSObject> obj,
1360 uint32_t key, 1360 uint32_t key,
1361 Handle<FixedArrayBase> backing_store) { 1361 Handle<FixedArrayBase> backing_store) {
1362 return 1362 return
1363 key < AccessorClass::GetCapacityImpl(backing_store) 1363 key < AccessorClass::GetCapacityImpl(backing_store)
1364 ? FIELD : NONEXISTENT; 1364 ? FIELD : NONEXISTENT;
1365 } 1365 }
1366 1366
1367 MUST_USE_RESULT static Handle<Object> SetLengthImpl( 1367 MUST_USE_RESULT static MaybeHandle<Object> SetLengthImpl(
1368 Handle<JSObject> obj, 1368 Handle<JSObject> obj,
1369 Handle<Object> length, 1369 Handle<Object> length,
1370 Handle<FixedArrayBase> backing_store) { 1370 Handle<FixedArrayBase> backing_store) {
1371 // External arrays do not support changing their length. 1371 // External arrays do not support changing their length.
1372 UNREACHABLE(); 1372 UNREACHABLE();
1373 return obj; 1373 return obj;
1374 } 1374 }
1375 1375
1376 MUST_USE_RESULT virtual Handle<Object> Delete( 1376 MUST_USE_RESULT virtual Handle<Object> Delete(
1377 Handle<JSObject> obj, 1377 Handle<JSObject> obj,
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after
1742 if (!probe->IsTheHole()) { 1742 if (!probe->IsTheHole()) {
1743 return MaybeHandle<AccessorPair>(); 1743 return MaybeHandle<AccessorPair>();
1744 } else { 1744 } else {
1745 // If not aliased, check the arguments. 1745 // If not aliased, check the arguments.
1746 Handle<FixedArray> arguments(FixedArray::cast(parameter_map->get(1))); 1746 Handle<FixedArray> arguments(FixedArray::cast(parameter_map->get(1)));
1747 return ElementsAccessor::ForArray(arguments)->GetAccessorPair( 1747 return ElementsAccessor::ForArray(arguments)->GetAccessorPair(
1748 receiver, obj, key, arguments); 1748 receiver, obj, key, arguments);
1749 } 1749 }
1750 } 1750 }
1751 1751
1752 MUST_USE_RESULT static Handle<Object> SetLengthImpl( 1752 MUST_USE_RESULT static MaybeHandle<Object> SetLengthImpl(
1753 Handle<JSObject> obj, 1753 Handle<JSObject> obj,
1754 Handle<Object> length, 1754 Handle<Object> length,
1755 Handle<FixedArrayBase> parameter_map) { 1755 Handle<FixedArrayBase> parameter_map) {
1756 // TODO(mstarzinger): This was never implemented but will be used once we 1756 // TODO(mstarzinger): This was never implemented but will be used once we
1757 // correctly implement [[DefineOwnProperty]] on arrays. 1757 // correctly implement [[DefineOwnProperty]] on arrays.
1758 UNIMPLEMENTED(); 1758 UNIMPLEMENTED();
1759 return obj; 1759 return obj;
1760 } 1760 }
1761 1761
1762 MUST_USE_RESULT virtual Handle<Object> Delete( 1762 MUST_USE_RESULT virtual Handle<Object> Delete(
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
1860 1860
1861 void ElementsAccessor::TearDown() { 1861 void ElementsAccessor::TearDown() {
1862 #define ACCESSOR_DELETE(Class, Kind, Store) delete elements_accessors_[Kind]; 1862 #define ACCESSOR_DELETE(Class, Kind, Store) delete elements_accessors_[Kind];
1863 ELEMENTS_LIST(ACCESSOR_DELETE) 1863 ELEMENTS_LIST(ACCESSOR_DELETE)
1864 #undef ACCESSOR_DELETE 1864 #undef ACCESSOR_DELETE
1865 elements_accessors_ = NULL; 1865 elements_accessors_ = NULL;
1866 } 1866 }
1867 1867
1868 1868
1869 template <typename ElementsAccessorSubclass, typename ElementsKindTraits> 1869 template <typename ElementsAccessorSubclass, typename ElementsKindTraits>
1870 MUST_USE_RESULT Handle<Object> ElementsAccessorBase<ElementsAccessorSubclass, 1870 MUST_USE_RESULT
1871 ElementsKindTraits>:: 1871 MaybeHandle<Object> ElementsAccessorBase<ElementsAccessorSubclass,
1872 ElementsKindTraits>::
1872 SetLengthImpl(Handle<JSObject> obj, 1873 SetLengthImpl(Handle<JSObject> obj,
1873 Handle<Object> length, 1874 Handle<Object> length,
1874 Handle<FixedArrayBase> backing_store) { 1875 Handle<FixedArrayBase> backing_store) {
1875 Isolate* isolate = obj->GetIsolate(); 1876 Isolate* isolate = obj->GetIsolate();
1876 Handle<JSArray> array = Handle<JSArray>::cast(obj); 1877 Handle<JSArray> array = Handle<JSArray>::cast(obj);
1877 1878
1878 // Fast case: The new length fits into a Smi. 1879 // Fast case: The new length fits into a Smi.
1879 Handle<Object> smi_length = Object::ToSmi(isolate, length); 1880 Handle<Object> smi_length = Object::ToSmi(isolate, length);
1880 1881
1881 if (!smi_length.is_null() && smi_length->IsSmi()) { 1882 if (!smi_length.is_null() && smi_length->IsSmi()) {
1882 const int value = Handle<Smi>::cast(smi_length)->value(); 1883 const int value = Handle<Smi>::cast(smi_length)->value();
1883 if (value >= 0) { 1884 if (value >= 0) {
1884 Handle<Object> new_length = ElementsAccessorSubclass:: 1885 Handle<Object> new_length = ElementsAccessorSubclass::
1885 SetLengthWithoutNormalize(backing_store, array, smi_length, value); 1886 SetLengthWithoutNormalize(backing_store, array, smi_length, value);
1886 RETURN_IF_EMPTY_HANDLE_VALUE(isolate, new_length, new_length); 1887 ASSERT(!new_length.is_null());
1887 1888
1888 // even though the proposed length was a smi, new_length could 1889 // even though the proposed length was a smi, new_length could
1889 // still be a heap number because SetLengthWithoutNormalize doesn't 1890 // still be a heap number because SetLengthWithoutNormalize doesn't
1890 // allow the array length property to drop below the index of 1891 // allow the array length property to drop below the index of
1891 // non-deletable elements. 1892 // non-deletable elements.
1892 ASSERT(new_length->IsSmi() || new_length->IsHeapNumber() || 1893 ASSERT(new_length->IsSmi() || new_length->IsHeapNumber() ||
1893 new_length->IsUndefined()); 1894 new_length->IsUndefined());
1894 if (new_length->IsSmi()) { 1895 if (new_length->IsSmi()) {
1895 array->set_length(*Handle<Smi>::cast(new_length)); 1896 array->set_length(*Handle<Smi>::cast(new_length));
1896 return array; 1897 return array;
1897 } else if (new_length->IsHeapNumber()) { 1898 } else if (new_length->IsHeapNumber()) {
1898 array->set_length(*new_length); 1899 array->set_length(*new_length);
1899 return array; 1900 return array;
1900 } 1901 }
1901 } else { 1902 } else {
1902 return ThrowArrayLengthRangeError(isolate); 1903 return ThrowArrayLengthRangeError(isolate);
1903 } 1904 }
1904 } 1905 }
1905 1906
1906 // Slow case: The new length does not fit into a Smi or conversion 1907 // Slow case: The new length does not fit into a Smi or conversion
1907 // to slow elements is needed for other reasons. 1908 // to slow elements is needed for other reasons.
1908 if (length->IsNumber()) { 1909 if (length->IsNumber()) {
1909 uint32_t value; 1910 uint32_t value;
1910 if (length->ToArrayIndex(&value)) { 1911 if (length->ToArrayIndex(&value)) {
1911 Handle<SeededNumberDictionary> dictionary = 1912 Handle<SeededNumberDictionary> dictionary =
1912 JSObject::NormalizeElements(array); 1913 JSObject::NormalizeElements(array);
1913 RETURN_IF_EMPTY_HANDLE_VALUE(isolate, dictionary, dictionary); 1914 ASSERT(!dictionary.is_null());
1914 1915
1915 Handle<Object> new_length = DictionaryElementsAccessor:: 1916 Handle<Object> new_length = DictionaryElementsAccessor::
1916 SetLengthWithoutNormalize(dictionary, array, length, value); 1917 SetLengthWithoutNormalize(dictionary, array, length, value);
1917 RETURN_IF_EMPTY_HANDLE_VALUE(isolate, new_length, new_length); 1918 ASSERT(!new_length.is_null());
1918 1919
1919 ASSERT(new_length->IsNumber()); 1920 ASSERT(new_length->IsNumber());
1920 array->set_length(*new_length); 1921 array->set_length(*new_length);
1921 return array; 1922 return array;
1922 } else { 1923 } else {
1923 return ThrowArrayLengthRangeError(isolate); 1924 return ThrowArrayLengthRangeError(isolate);
1924 } 1925 }
1925 } 1926 }
1926 1927
1927 // Fall-back case: The new length is not a number so make the array 1928 // Fall-back case: The new length is not a number so make the array
1928 // size one and set only element to length. 1929 // size one and set only element to length.
1929 Handle<FixedArray> new_backing_store = isolate->factory()->NewFixedArray(1); 1930 Handle<FixedArray> new_backing_store = isolate->factory()->NewFixedArray(1);
1930 new_backing_store->set(0, *length); 1931 new_backing_store->set(0, *length);
1931 JSArray::SetContent(array, new_backing_store); 1932 JSArray::SetContent(array, new_backing_store);
1932 return array; 1933 return array;
1933 } 1934 }
1934 1935
1935 1936
1936 Handle<Object> ArrayConstructInitializeElements(Handle<JSArray> array, 1937 MaybeHandle<Object> ArrayConstructInitializeElements(Handle<JSArray> array,
1937 Arguments* args) { 1938 Arguments* args) {
1938 // Optimize the case where there is one argument and the argument is a 1939 // Optimize the case where there is one argument and the argument is a
1939 // small smi. 1940 // small smi.
1940 if (args->length() == 1) { 1941 if (args->length() == 1) {
1941 Handle<Object> obj = args->at<Object>(0); 1942 Handle<Object> obj = args->at<Object>(0);
1942 if (obj->IsSmi()) { 1943 if (obj->IsSmi()) {
1943 int len = Handle<Smi>::cast(obj)->value(); 1944 int len = Handle<Smi>::cast(obj)->value();
1944 if (len > 0 && len < JSObject::kInitialMaxFastElementArray) { 1945 if (len > 0 && len < JSObject::kInitialMaxFastElementArray) {
1945 ElementsKind elements_kind = array->GetElementsKind(); 1946 ElementsKind elements_kind = array->GetElementsKind();
1946 JSArray::Initialize(array, len, len); 1947 JSArray::Initialize(array, len, len);
1947 1948
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
2019 UNREACHABLE(); 2020 UNREACHABLE();
2020 break; 2021 break;
2021 } 2022 }
2022 2023
2023 array->set_elements(*elms); 2024 array->set_elements(*elms);
2024 array->set_length(Smi::FromInt(number_of_elements)); 2025 array->set_length(Smi::FromInt(number_of_elements));
2025 return array; 2026 return array;
2026 } 2027 }
2027 2028
2028 } } // namespace v8::internal 2029 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/elements.h ('k') | src/ic.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698