From ef0c647c495dfb100a9e0a2a06723fb92b6cb48d Mon Sep 17 00:00:00 2001 From: "rafaelw@chromium.org" Date: Thu, 7 Nov 2013 12:35:57 +0000 Subject: [PATCH] Handlify Runtime::SetObjectProperty BUG= R=mstarzinger@chromium.org Review URL: https://codereview.chromium.org/62333002 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@17560 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/api.cc | 2 +- src/handles.cc | 14 ---- src/handles.h | 7 -- src/ic.cc | 53 +++++++----- src/runtime.cc | 186 ++++++++++++++++++------------------------- src/runtime.h | 10 +-- src/scopeinfo.cc | 15 ++-- test/cctest/test-compiler.cc | 3 +- test/cctest/test-debug.cc | 8 +- 9 files changed, 125 insertions(+), 173 deletions(-) diff --git a/src/api.cc b/src/api.cc index b90e693..401007b 100644 --- a/src/api.cc +++ b/src/api.cc @@ -3136,7 +3136,7 @@ bool v8::Object::Set(v8::Handle key, v8::Handle value, i::Handle key_obj = Utils::OpenHandle(*key); i::Handle value_obj = Utils::OpenHandle(*value); EXCEPTION_PREAMBLE(isolate); - i::Handle obj = i::SetProperty( + i::Handle obj = i::Runtime::SetObjectProperty( isolate, self, key_obj, diff --git a/src/handles.cc b/src/handles.cc index 42e53c6..6fd047b 100644 --- a/src/handles.cc +++ b/src/handles.cc @@ -160,20 +160,6 @@ Handle FlattenGetString(Handle string) { } -Handle SetProperty(Isolate* isolate, - Handle object, - Handle key, - Handle value, - PropertyAttributes attributes, - StrictModeFlag strict_mode) { - CALL_HEAP_FUNCTION( - isolate, - Runtime::SetObjectProperty( - isolate, object, key, value, attributes, strict_mode), - Object); -} - - Handle ForceSetProperty(Handle object, Handle key, Handle value, diff --git a/src/handles.h b/src/handles.h index 890f4f5..5bc5779 100644 --- a/src/handles.h +++ b/src/handles.h @@ -228,13 +228,6 @@ void FlattenString(Handle str); // string. Handle FlattenGetString(Handle str); -Handle SetProperty(Isolate* isolate, - Handle object, - Handle key, - Handle value, - PropertyAttributes attributes, - StrictModeFlag strict_mode); - Handle ForceSetProperty(Handle object, Handle key, Handle value, diff --git a/src/ic.cc b/src/ic.cc index e608d5b..640b188 100644 --- a/src/ic.cc +++ b/src/ic.cc @@ -1920,8 +1920,13 @@ MaybeObject* KeyedStoreIC::Store(Handle object, Handle value, ICMissMode miss_mode) { if (MigrateDeprecated(object)) { - return Runtime::SetObjectPropertyOrFail( - isolate(), object , key, value, NONE, strict_mode()); + Handle result = Runtime::SetObjectProperty(isolate(), object, + key, + value, + NONE, + strict_mode()); + RETURN_IF_EMPTY_HANDLE(isolate(), result); + return *result; } // Check for values that can be converted into an internalized string directly @@ -1986,8 +1991,12 @@ MaybeObject* KeyedStoreIC::Store(Handle object, } if (maybe_object) return maybe_object; - return Runtime::SetObjectPropertyOrFail( - isolate(), object , key, value, NONE, strict_mode()); + Handle result = Runtime::SetObjectProperty(isolate(), object, key, + value, + NONE, + strict_mode()); + RETURN_IF_EMPTY_HANDLE(isolate(), result); + return *result; } @@ -2218,12 +2227,12 @@ RUNTIME_FUNCTION(MaybeObject*, StoreIC_Slow) { Handle key = args.at(1); Handle value = args.at(2); StrictModeFlag strict_mode = ic.strict_mode(); - return Runtime::SetObjectProperty(isolate, - object, - key, - value, - NONE, - strict_mode); + Handle result = Runtime::SetObjectProperty(isolate, object, key, + value, + NONE, + strict_mode); + RETURN_IF_EMPTY_HANDLE(isolate, result); + return *result; } @@ -2235,12 +2244,12 @@ RUNTIME_FUNCTION(MaybeObject*, KeyedStoreIC_Slow) { Handle key = args.at(1); Handle value = args.at(2); StrictModeFlag strict_mode = ic.strict_mode(); - return Runtime::SetObjectProperty(isolate, - object, - key, - value, - NONE, - strict_mode); + Handle result = Runtime::SetObjectProperty(isolate, object, key, + value, + NONE, + strict_mode); + RETURN_IF_EMPTY_HANDLE(isolate, result); + return *result; } @@ -2268,12 +2277,12 @@ RUNTIME_FUNCTION(MaybeObject*, ElementsTransitionAndStoreIC_Miss) { JSObject::TransitionElementsKind(Handle::cast(object), map->elements_kind()); } - return Runtime::SetObjectProperty(isolate, - object, - key, - value, - NONE, - strict_mode); + Handle result = Runtime::SetObjectProperty(isolate, object, key, + value, + NONE, + strict_mode); + RETURN_IF_EMPTY_HANDLE(isolate, result); + return *result; } diff --git a/src/runtime.cc b/src/runtime.cc index ed22f1f..2f344ec 100644 --- a/src/runtime.cc +++ b/src/runtime.cc @@ -5122,49 +5122,36 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_GetDataProperty) { } -MaybeObject* Runtime::SetObjectPropertyOrFail( - Isolate* isolate, - Handle object, - Handle key, - Handle value, - PropertyAttributes attr, - StrictModeFlag strict_mode) { - CALL_HEAP_FUNCTION_PASS_EXCEPTION(isolate, - SetObjectProperty(isolate, object, key, value, attr, strict_mode)); -} - - -MaybeObject* Runtime::SetObjectProperty(Isolate* isolate, - Handle object, - Handle key, - Handle value, - PropertyAttributes attr, - StrictModeFlag strict_mode) { +Handle Runtime::SetObjectProperty(Isolate* isolate, + Handle object, + Handle key, + Handle value, + PropertyAttributes attr, + StrictModeFlag strict_mode) { SetPropertyMode set_mode = attr == NONE ? SET_PROPERTY : DEFINE_PROPERTY; - HandleScope scope(isolate); if (object->IsUndefined() || object->IsNull()) { Handle args[2] = { key, object }; Handle error = isolate->factory()->NewTypeError("non_object_property_store", HandleVector(args, 2)); - return isolate->Throw(*error); + isolate->Throw(*error); + return Handle(); } if (object->IsJSProxy()) { bool has_pending_exception = false; Handle name_object = key->IsSymbol() ? key : Execution::ToString(isolate, key, &has_pending_exception); - if (has_pending_exception) return Failure::Exception(); + if (has_pending_exception) return Handle(); // exception Handle name = Handle::cast(name_object); - Handle result = JSReceiver::SetProperty( - Handle::cast(object), name, value, attr, strict_mode); - RETURN_IF_EMPTY_HANDLE(isolate, result); - return *result; + return JSReceiver::SetProperty(Handle::cast(object), name, value, + attr, + strict_mode); } // If the object isn't a JavaScript object, we ignore the store. - if (!object->IsJSObject()) return *value; + if (!object->IsJSObject()) return value; Handle js_object = Handle::cast(object); @@ -5179,7 +5166,7 @@ MaybeObject* Runtime::SetObjectProperty(Isolate* isolate, // string does nothing with the assignment then we can ignore such // assignments. if (js_object->IsStringObjectWithCharacterAt(index)) { - return *value; + return value; } js_object->ValidateElements(); @@ -5188,15 +5175,16 @@ MaybeObject* Runtime::SetObjectProperty(Isolate* isolate, bool has_exception; Handle number = Execution::ToNumber(isolate, value, &has_exception); - if (has_exception) return Failure::Exception(); + if (has_exception) return Handle(); // exception value = number; } } - MaybeObject* result = js_object->SetElement( - index, *value, attr, strict_mode, true, set_mode); + Handle result = JSObject::SetElement(js_object, index, value, attr, + strict_mode, + true, + set_mode); js_object->ValidateElements(); - if (result->IsFailure()) return result; - return *value; + return result.is_null() ? result : value; } if (key->IsName()) { @@ -5207,37 +5195,32 @@ MaybeObject* Runtime::SetObjectProperty(Isolate* isolate, bool has_exception; Handle number = Execution::ToNumber(isolate, value, &has_exception); - if (has_exception) return Failure::Exception(); + if (has_exception) return Handle(); // exception value = number; } } - MaybeObject* result = js_object->SetElement( - index, *value, attr, strict_mode, true, set_mode); - if (result->IsFailure()) return result; + return JSObject::SetElement(js_object, index, value, attr, strict_mode, + true, + set_mode); } else { if (name->IsString()) Handle::cast(name)->TryFlatten(); - Handle result = - JSReceiver::SetProperty(js_object, name, value, attr, strict_mode); - RETURN_IF_EMPTY_HANDLE(isolate, result); + return JSReceiver::SetProperty(js_object, name, value, attr, strict_mode); } - return *value; } // Call-back into JavaScript to convert the key to a string. bool has_pending_exception = false; Handle converted = Execution::ToString(isolate, key, &has_pending_exception); - if (has_pending_exception) return Failure::Exception(); + if (has_pending_exception) return Handle(); // exception Handle name = Handle::cast(converted); if (name->AsArrayIndex(&index)) { - return js_object->SetElement( - index, *value, attr, strict_mode, true, set_mode); + return JSObject::SetElement(js_object, index, value, attr, strict_mode, + true, + set_mode); } else { - Handle result = - JSReceiver::SetProperty(js_object, name, value, attr, strict_mode); - RETURN_IF_EMPTY_HANDLE(isolate, result); - return *result; + return JSReceiver::SetProperty(js_object, name, value, attr, strict_mode); } } @@ -5341,12 +5324,12 @@ MaybeObject* Runtime::DeleteObjectProperty(Isolate* isolate, RUNTIME_FUNCTION(MaybeObject*, Runtime_SetProperty) { - SealHandleScope shs(isolate); + HandleScope scope(isolate); RUNTIME_ASSERT(args.length() == 4 || args.length() == 5); - Handle object = args.at(0); - Handle key = args.at(1); - Handle value = args.at(2); + CONVERT_ARG_HANDLE_CHECKED(Object, object, 0); + CONVERT_ARG_HANDLE_CHECKED(Object, key, 1); + CONVERT_ARG_HANDLE_CHECKED(Object, value, 2); CONVERT_SMI_ARG_CHECKED(unchecked_attributes, 3); RUNTIME_ASSERT( (unchecked_attributes & ~(READ_ONLY | DONT_ENUM | DONT_DELETE)) == 0); @@ -5360,12 +5343,12 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_SetProperty) { strict_mode = strict_mode_flag; } - return Runtime::SetObjectProperty(isolate, - object, - key, - value, - attributes, - strict_mode); + Handle result = Runtime::SetObjectProperty(isolate, object, key, + value, + attributes, + strict_mode); + RETURN_IF_EMPTY_HANDLE(isolate, result); + return *result; } @@ -5386,10 +5369,10 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_SetNativeFlag) { SealHandleScope shs(isolate); RUNTIME_ASSERT(args.length() == 1); - Handle object = args.at(0); + CONVERT_ARG_CHECKED(Object, object, 0); if (object->IsJSFunction()) { - JSFunction* func = JSFunction::cast(*object); + JSFunction* func = JSFunction::cast(object); func->shared()->set_native(true); } return isolate->heap()->undefined_value(); @@ -11348,12 +11331,12 @@ static Handle MaterializeStackLocalsWithFrameInspector( RETURN_IF_EMPTY_HANDLE_VALUE( isolate, - SetProperty(isolate, - target, - Handle(scope_info->ParameterName(i)), - value, - NONE, - kNonStrictMode), + Runtime::SetObjectProperty(isolate, + target, + Handle(scope_info->ParameterName(i)), + value, + NONE, + kNonStrictMode), Handle()); } @@ -11364,12 +11347,13 @@ static Handle MaterializeStackLocalsWithFrameInspector( RETURN_IF_EMPTY_HANDLE_VALUE( isolate, - SetProperty(isolate, - target, - Handle(scope_info->StackLocalName(i)), - value, - NONE, - kNonStrictMode), + Runtime::SetObjectProperty( + isolate, + target, + Handle(scope_info->StackLocalName(i)), + value, + NONE, + kNonStrictMode), Handle()); } @@ -11447,12 +11431,12 @@ static Handle MaterializeLocalContext(Isolate* isolate, Handle key(String::cast(keys->get(i))); RETURN_IF_EMPTY_HANDLE_VALUE( isolate, - SetProperty(isolate, - target, - key, - GetProperty(isolate, ext, key), - NONE, - kNonStrictMode), + Runtime::SetObjectProperty(isolate, + target, + key, + GetProperty(isolate, ext, key), + NONE, + kNonStrictMode), Handle()); } } @@ -11552,12 +11536,9 @@ static bool SetLocalVariableValue(Isolate* isolate, if (JSReceiver::HasProperty(ext, variable_name)) { // We don't expect this to do anything except replacing // property value. - SetProperty(isolate, - ext, - variable_name, - new_value, - NONE, - kNonStrictMode); + Runtime::SetObjectProperty(isolate, ext, variable_name, new_value, + NONE, + kNonStrictMode); return true; } } @@ -11603,12 +11584,10 @@ static Handle MaterializeClosure(Isolate* isolate, Handle key(String::cast(keys->get(i))); RETURN_IF_EMPTY_HANDLE_VALUE( isolate, - SetProperty(isolate, - closure_scope, - key, - GetProperty(isolate, ext, key), - NONE, - kNonStrictMode), + Runtime::SetObjectProperty(isolate, closure_scope, key, + GetProperty(isolate, ext, key), + NONE, + kNonStrictMode), Handle()); } } @@ -11639,12 +11618,9 @@ static bool SetClosureVariableValue(Isolate* isolate, Handle ext(JSObject::cast(context->extension())); if (JSReceiver::HasProperty(ext, variable_name)) { // We don't expect this to do anything except replacing property value. - SetProperty(isolate, - ext, - variable_name, - new_value, - NONE, - kNonStrictMode); + Runtime::SetObjectProperty(isolate, ext, variable_name, new_value, + NONE, + kNonStrictMode); return true; } } @@ -11665,12 +11641,9 @@ static Handle MaterializeCatchScope(Isolate* isolate, isolate->factory()->NewJSObject(isolate->object_function()); RETURN_IF_EMPTY_HANDLE_VALUE( isolate, - SetProperty(isolate, - catch_scope, - name, - thrown_object, - NONE, - kNonStrictMode), + Runtime::SetObjectProperty(isolate, catch_scope, name, thrown_object, + NONE, + kNonStrictMode), Handle()); return catch_scope; } @@ -12688,12 +12661,11 @@ static Handle MaterializeArgumentsObject( // FunctionGetArguments can't throw an exception. Handle arguments = Handle::cast( Accessors::FunctionGetArguments(function)); - SetProperty(isolate, - target, - isolate->factory()->arguments_string(), - arguments, - ::NONE, - kNonStrictMode); + Runtime::SetObjectProperty(isolate, target, + isolate->factory()->arguments_string(), + arguments, + ::NONE, + kNonStrictMode); return target; } diff --git a/src/runtime.h b/src/runtime.h index 07aa0b4..c316d40 100644 --- a/src/runtime.h +++ b/src/runtime.h @@ -776,15 +776,7 @@ class Runtime : public AllStatic { Handle object, uint32_t index); - MUST_USE_RESULT static MaybeObject* SetObjectProperty( - Isolate* isolate, - Handle object, - Handle key, - Handle value, - PropertyAttributes attr, - StrictModeFlag strict_mode); - - MUST_USE_RESULT static MaybeObject* SetObjectPropertyOrFail( + static Handle SetObjectProperty( Isolate* isolate, Handle object, Handle key, diff --git a/src/scopeinfo.cc b/src/scopeinfo.cc index f1ae876..04c0044 100644 --- a/src/scopeinfo.cc +++ b/src/scopeinfo.cc @@ -374,15 +374,14 @@ bool ScopeInfo::CopyContextLocalsToScopeObject(Handle scope_info, int end = start + local_count; for (int i = start; i < end; ++i) { int context_index = Context::MIN_CONTEXT_SLOTS + i - start; - RETURN_IF_EMPTY_HANDLE_VALUE( + Handle result = Runtime::SetObjectProperty( isolate, - SetProperty(isolate, - scope_object, - Handle(String::cast(scope_info->get(i))), - Handle(context->get(context_index), isolate), - ::NONE, - kNonStrictMode), - false); + scope_object, + Handle(String::cast(scope_info->get(i))), + Handle(context->get(context_index), isolate), + ::NONE, + kNonStrictMode); + RETURN_IF_EMPTY_HANDLE_VALUE(isolate, result, false); } return true; } diff --git a/test/cctest/test-compiler.cc b/test/cctest/test-compiler.cc index 9fd68e5..3cef716 100644 --- a/test/cctest/test-compiler.cc +++ b/test/cctest/test-compiler.cc @@ -92,7 +92,8 @@ static void SetGlobalProperty(const char* name, Object* value) { Handle internalized_name = isolate->factory()->InternalizeUtf8String(name); Handle global(isolate->context()->global_object()); - SetProperty(isolate, global, internalized_name, object, NONE, kNonStrictMode); + Runtime::SetObjectProperty(isolate, global, internalized_name, object, NONE, + kNonStrictMode); } diff --git a/test/cctest/test-debug.cc b/test/cctest/test-debug.cc index 1bd1dc3..0c8a02b 100644 --- a/test/cctest/test-debug.cc +++ b/test/cctest/test-debug.cc @@ -169,10 +169,10 @@ class DebugLocalContext { v8::Utils::OpenHandle(*context_->Global()))); Handle debug_string = factory->InternalizeOneByteString(STATIC_ASCII_VECTOR("debug")); - SetProperty(isolate, global, debug_string, - Handle(debug->debug_context()->global_proxy(), isolate), - DONT_ENUM, - ::v8::internal::kNonStrictMode); + v8::internal::Runtime::SetObjectProperty(isolate, global, debug_string, + Handle(debug->debug_context()->global_proxy(), isolate), + DONT_ENUM, + ::v8::internal::kNonStrictMode); } private: -- 2.7.4