From 74e7a4ad079859930581781e7724ddf7570a70f9 Mon Sep 17 00:00:00 2001 From: "ishell@chromium.org" Date: Wed, 9 Apr 2014 13:16:19 +0000 Subject: [PATCH] ElementsAccessor::SetLength() maybehandlified. R=yangguo@chromium.org Review URL: https://codereview.chromium.org/229943006 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@20621 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/accessors.cc | 6 ++++-- src/elements.cc | 33 +++++++++++++++++---------------- src/elements.h | 7 ++++--- src/ic.cc | 4 ++-- src/objects.cc | 13 ++++++++----- src/objects.h | 5 +++-- src/runtime.cc | 4 ++-- test/cctest/test-heap.cc | 4 ++-- 8 files changed, 42 insertions(+), 34 deletions(-) diff --git a/src/accessors.cc b/src/accessors.cc index b3bf7c1..8dbd9c9 100644 --- a/src/accessors.cc +++ b/src/accessors.cc @@ -211,8 +211,10 @@ MaybeObject* Accessors::ArraySetLength(Isolate* isolate, if (has_exception) return Failure::Exception(); if (uint32_v->Number() == number_v->Number()) { - Handle result = JSArray::SetElementsLength(array_handle, uint32_v); - RETURN_IF_EMPTY_HANDLE(isolate, result); + Handle result; + ASSIGN_RETURN_FAILURE_ON_EXCEPTION( + isolate, result, + JSArray::SetElementsLength(array_handle, uint32_v)); return *result; } return isolate->Throw( diff --git a/src/elements.cc b/src/elements.cc index db97133..b0761a0 100644 --- a/src/elements.cc +++ b/src/elements.cc @@ -162,11 +162,11 @@ static bool HasKey(Handle array, Handle key_handle) { } -static Handle ThrowArrayLengthRangeError(Isolate* isolate) { - isolate->Throw( - *isolate->factory()->NewRangeError("invalid_array_length", - HandleVector(NULL, 0))); - return Handle(); +MUST_USE_RESULT +static MaybeHandle ThrowArrayLengthRangeError(Isolate* isolate) { + return isolate->Throw( + isolate->factory()->NewRangeError("invalid_array_length", + HandleVector(NULL, 0))); } @@ -727,14 +727,14 @@ class ElementsAccessorBase : public ElementsAccessor { return MaybeHandle(); } - MUST_USE_RESULT virtual Handle SetLength( + MUST_USE_RESULT virtual MaybeHandle SetLength( Handle array, Handle length) V8_FINAL V8_OVERRIDE { return ElementsAccessorSubclass::SetLengthImpl( array, length, handle(array->elements())); } - MUST_USE_RESULT static Handle SetLengthImpl( + MUST_USE_RESULT static MaybeHandle SetLengthImpl( Handle obj, Handle length, Handle backing_store); @@ -1364,7 +1364,7 @@ class TypedElementsAccessor ? FIELD : NONEXISTENT; } - MUST_USE_RESULT static Handle SetLengthImpl( + MUST_USE_RESULT static MaybeHandle SetLengthImpl( Handle obj, Handle length, Handle backing_store) { @@ -1749,7 +1749,7 @@ class SloppyArgumentsElementsAccessor : public ElementsAccessorBase< } } - MUST_USE_RESULT static Handle SetLengthImpl( + MUST_USE_RESULT static MaybeHandle SetLengthImpl( Handle obj, Handle length, Handle parameter_map) { @@ -1867,8 +1867,9 @@ void ElementsAccessor::TearDown() { template -MUST_USE_RESULT Handle ElementsAccessorBase:: +MUST_USE_RESULT +MaybeHandle ElementsAccessorBase:: SetLengthImpl(Handle obj, Handle length, Handle backing_store) { @@ -1883,7 +1884,7 @@ MUST_USE_RESULT Handle ElementsAccessorBase= 0) { Handle new_length = ElementsAccessorSubclass:: SetLengthWithoutNormalize(backing_store, array, smi_length, value); - RETURN_IF_EMPTY_HANDLE_VALUE(isolate, new_length, new_length); + ASSERT(!new_length.is_null()); // even though the proposed length was a smi, new_length could // still be a heap number because SetLengthWithoutNormalize doesn't @@ -1910,11 +1911,11 @@ MUST_USE_RESULT Handle ElementsAccessorBaseToArrayIndex(&value)) { Handle dictionary = JSObject::NormalizeElements(array); - RETURN_IF_EMPTY_HANDLE_VALUE(isolate, dictionary, dictionary); + ASSERT(!dictionary.is_null()); Handle new_length = DictionaryElementsAccessor:: SetLengthWithoutNormalize(dictionary, array, length, value); - RETURN_IF_EMPTY_HANDLE_VALUE(isolate, new_length, new_length); + ASSERT(!new_length.is_null()); ASSERT(new_length->IsNumber()); array->set_length(*new_length); @@ -1933,8 +1934,8 @@ MUST_USE_RESULT Handle ElementsAccessorBase ArrayConstructInitializeElements(Handle array, - Arguments* args) { +MaybeHandle ArrayConstructInitializeElements(Handle array, + Arguments* args) { // Optimize the case where there is one argument and the argument is a // small smi. if (args->length() == 1) { diff --git a/src/elements.h b/src/elements.h index 76b2b0e..ea06b6b 100644 --- a/src/elements.h +++ b/src/elements.h @@ -145,7 +145,7 @@ class ElementsAccessor { // changing array sizes as defined in EcmaScript 5.1 15.4.5.2, i.e. array that // have non-deletable elements can only be shrunk to the size of highest // element that is non-deletable. - MUST_USE_RESULT virtual Handle SetLength( + MUST_USE_RESULT virtual MaybeHandle SetLength( Handle holder, Handle new_length) = 0; @@ -257,8 +257,9 @@ class ElementsAccessor { void CheckArrayAbuse(Handle obj, const char* op, uint32_t key, bool allow_appending = false); -Handle ArrayConstructInitializeElements(Handle array, - Arguments* args); +MUST_USE_RESULT MaybeHandle ArrayConstructInitializeElements( + Handle array, + Arguments* args); } } // namespace v8::internal diff --git a/src/ic.cc b/src/ic.cc index a00df85..9195f72 100644 --- a/src/ic.cc +++ b/src/ic.cc @@ -1833,8 +1833,8 @@ RUNTIME_FUNCTION(MaybeObject*, StoreIC_ArrayLength) { ASSERT(debug_lookup.IsPropertyCallbacks() && !debug_lookup.IsReadOnly()); #endif - RETURN_IF_EMPTY_HANDLE(isolate, - JSArray::SetElementsLength(receiver, len)); + RETURN_FAILURE_ON_EXCEPTION( + isolate, JSArray::SetElementsLength(receiver, len)); return *len; } diff --git a/src/objects.cc b/src/objects.cc index 73046dd..4a988e3 100644 --- a/src/objects.cc +++ b/src/objects.cc @@ -11439,8 +11439,9 @@ static void EndPerformSplice(Handle object) { } -Handle JSArray::SetElementsLength(Handle array, - Handle new_length_handle) { +MaybeHandle JSArray::SetElementsLength( + Handle array, + Handle new_length_handle) { // We should never end in here with a pixel or external array. ASSERT(array->AllowsSetElementsLength()); if (!array->map()->is_observed()) { @@ -11478,9 +11479,11 @@ Handle JSArray::SetElementsLength(Handle array, } } - Handle hresult = - array->GetElementsAccessor()->SetLength(array, new_length_handle); - RETURN_IF_EMPTY_HANDLE_VALUE(isolate, hresult, hresult); + Handle hresult; + ASSIGN_RETURN_ON_EXCEPTION( + isolate, hresult, + array->GetElementsAccessor()->SetLength(array, new_length_handle), + Object); CHECK(array->length()->ToArrayIndex(&new_length)); if (old_length == new_length) return hresult; diff --git a/src/objects.h b/src/objects.h index e7e8e02..6365a94 100644 --- a/src/objects.h +++ b/src/objects.h @@ -10232,8 +10232,9 @@ class JSArray: public JSObject { // Initializes the array to a certain length. inline bool AllowsSetElementsLength(); // Can cause GC. - static Handle SetElementsLength(Handle array, - Handle length); + MUST_USE_RESULT static MaybeHandle SetElementsLength( + Handle array, + Handle length); // Set the content of the array to the content of storage. static inline void SetContent(Handle array, diff --git a/src/runtime.cc b/src/runtime.cc index 557bfb0..cae4aff 100644 --- a/src/runtime.cc +++ b/src/runtime.cc @@ -15034,8 +15034,8 @@ static MaybeObject* ArrayConstructorCommon(Isolate* isolate, factory->NewJSArrayStorage(array, 0, 0, DONT_INITIALIZE_ARRAY_ELEMENTS); ElementsKind old_kind = array->GetElementsKind(); - RETURN_IF_EMPTY_HANDLE(isolate, - ArrayConstructInitializeElements(array, caller_args)); + RETURN_FAILURE_ON_EXCEPTION( + isolate, ArrayConstructInitializeElements(array, caller_args)); if (!site.is_null() && (old_kind != array->GetElementsKind() || !can_use_type_feedback)) { diff --git a/test/cctest/test-heap.cc b/test/cctest/test-heap.cc index 83cafed..aa28d4f 100644 --- a/test/cctest/test-heap.cc +++ b/test/cctest/test-heap.cc @@ -767,7 +767,7 @@ TEST(JSArray) { JSArray::Initialize(array, 0); // Set array length to 0. - *JSArray::SetElementsLength(array, handle(Smi::FromInt(0), isolate)); + JSArray::SetElementsLength(array, handle(Smi::FromInt(0), isolate)).Check(); CHECK_EQ(Smi::FromInt(0), array->length()); // Must be in fast mode. CHECK(array->HasFastSmiOrObjectElements()); @@ -780,7 +780,7 @@ TEST(JSArray) { // Set array length with larger than smi value. Handle length = factory->NewNumberFromUint(static_cast(Smi::kMaxValue) + 1); - *JSArray::SetElementsLength(array, length); + JSArray::SetElementsLength(array, length).Check(); uint32_t int_length = 0; CHECK(length->ToArrayIndex(&int_length)); -- 2.7.4