From 95dfa17c34f542ef46ae62cc656959a8cf4e5965 Mon Sep 17 00:00:00 2001 From: "yangguo@chromium.org" Date: Tue, 25 Mar 2014 13:02:03 +0000 Subject: [PATCH] Handlify Runtime::GetElementOrCharAt. R=ishell@chromium.org Review URL: https://codereview.chromium.org/210723004 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@20243 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/ic.cc | 5 ++++- src/runtime.cc | 44 +++++++++++++++++--------------------------- src/runtime.h | 11 +++-------- 3 files changed, 24 insertions(+), 36 deletions(-) diff --git a/src/ic.cc b/src/ic.cc index 89bd87a..da8afca 100644 --- a/src/ic.cc +++ b/src/ic.cc @@ -564,7 +564,10 @@ MaybeObject* LoadIC::Load(Handle object, if (kind() == Code::KEYED_LOAD_IC && name->AsArrayIndex(&index)) { // Rewrite to the generic keyed load stub. if (FLAG_use_ic) set_target(*generic_stub()); - return Runtime::GetElementOrCharAtOrFail(isolate(), object, index); + Handle result = + Runtime::GetElementOrCharAt(isolate(), object, index); + RETURN_IF_EMPTY_HANDLE(isolate(), result); + return *result; } bool use_ic = MigrateDeprecated(object) ? false : FLAG_use_ic; diff --git a/src/runtime.cc b/src/runtime.cc index 05d378a..2e4c993 100644 --- a/src/runtime.cc +++ b/src/runtime.cc @@ -4865,21 +4865,13 @@ static Handle GetCharAt(Handle string, uint32_t index) { } -MaybeObject* Runtime::GetElementOrCharAtOrFail(Isolate* isolate, - Handle object, - uint32_t index) { - CALL_HEAP_FUNCTION_PASS_EXCEPTION(isolate, - GetElementOrCharAt(isolate, object, index)); -} - - -MaybeObject* Runtime::GetElementOrCharAt(Isolate* isolate, - Handle object, - uint32_t index) { +Handle Runtime::GetElementOrCharAt(Isolate* isolate, + Handle object, + uint32_t index) { // Handle [] indexing on Strings if (object->IsString()) { Handle result = GetCharAt(Handle::cast(object), index); - if (!result->IsUndefined()) return *result; + if (!result->IsUndefined()) return result; } // Handle [] indexing on String objects @@ -4887,18 +4879,16 @@ MaybeObject* Runtime::GetElementOrCharAt(Isolate* isolate, Handle js_value = Handle::cast(object); Handle result = GetCharAt(Handle(String::cast(js_value->value())), index); - if (!result->IsUndefined()) return *result; + if (!result->IsUndefined()) return result; } Handle result; if (object->IsString() || object->IsNumber() || object->IsBoolean()) { Handle proto(object->GetPrototype(isolate), isolate); - result = Object::GetElement(isolate, proto, index); + return Object::GetElement(isolate, proto, index); } else { - result = Object::GetElement(isolate, object, index); + return Object::GetElement(isolate, object, index); } - RETURN_IF_EMPTY_HANDLE(isolate, result); - return *result; } @@ -4957,7 +4947,9 @@ MaybeObject* Runtime::GetObjectProperty(Isolate* isolate, // Check if the given key is an array index. uint32_t index; if (key->ToArrayIndex(&index)) { - return GetElementOrCharAt(isolate, object, index); + Handle result = GetElementOrCharAt(isolate, object, index); + RETURN_IF_EMPTY_HANDLE(isolate, result); + return *result; } // Convert the key to a name - possibly by calling back into JavaScript. @@ -4967,7 +4959,9 @@ MaybeObject* Runtime::GetObjectProperty(Isolate* isolate, // Check if the name is trivially convertible to an index and get // the element if so. if (name->AsArrayIndex(&index)) { - return GetElementOrCharAt(isolate, object, index); + Handle result = GetElementOrCharAt(isolate, object, index); + RETURN_IF_EMPTY_HANDLE(isolate, result); + return *result; } else { return object->GetProperty(*name); } @@ -10894,14 +10888,10 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_DebugGetPropertyDetails) { uint32_t index; if (name->AsArrayIndex(&index)) { Handle details = isolate->factory()->NewFixedArray(2); - Object* element_or_char; - { MaybeObject* maybe_element_or_char = - Runtime::GetElementOrCharAt(isolate, obj, index); - if (!maybe_element_or_char->ToObject(&element_or_char)) { - return maybe_element_or_char; - } - } - details->set(0, element_or_char); + Handle element_or_char = + Runtime::GetElementOrCharAt(isolate, obj, index); + RETURN_IF_EMPTY_HANDLE(isolate, element_or_char); + details->set(0, *element_or_char); details->set( 1, PropertyDetails(NONE, NORMAL, Representation::None()).AsSmi()); return *isolate->factory()->NewJSArrayWithElements(details); diff --git a/src/runtime.h b/src/runtime.h index e66403e..d70afd9 100644 --- a/src/runtime.h +++ b/src/runtime.h @@ -775,14 +775,9 @@ class Runtime : public AllStatic { // Support getting the characters in a string using [] notation as // in Firefox/SpiderMonkey, Safari and Opera. - MUST_USE_RESULT static MaybeObject* GetElementOrCharAt(Isolate* isolate, - Handle object, - uint32_t index); - - MUST_USE_RESULT static MaybeObject* GetElementOrCharAtOrFail( - Isolate* isolate, - Handle object, - uint32_t index); + static Handle GetElementOrCharAt(Isolate* isolate, + Handle object, + uint32_t index); static Handle SetObjectProperty( Isolate* isolate, -- 2.7.4