diff --git a/src/api.cc b/src/api.cc index d180c31a1c..75c67e096a 100644 --- a/src/api.cc +++ b/src/api.cc @@ -3541,10 +3541,9 @@ static Local GetPropertyByLookup(i::Isolate* isolate, // an exception. EXCEPTION_PREAMBLE(isolate); PropertyAttributes ignored; - i::Handle result = - i::Object::GetProperty(receiver, receiver, lookup, name, - &ignored); - has_pending_exception = result.is_null(); + i::Handle result; + has_pending_exception = !i::Object::GetProperty( + receiver, receiver, lookup, name, &ignored).ToHandle(&result); EXCEPTION_BAILOUT_CHECK(isolate, Local()); return Utils::ToLocal(result); diff --git a/src/ic.cc b/src/ic.cc index 1d7a73e14b..8e2d589c1e 100644 --- a/src/ic.cc +++ b/src/ic.cc @@ -598,11 +598,11 @@ MaybeObject* LoadIC::Load(Handle object, PropertyAttributes attr; // Get the property. - Handle result = - Object::GetProperty(object, object, &lookup, name, &attr); - RETURN_IF_EMPTY_HANDLE(isolate(), result); - // If the property is not present, check if we need to throw an - // exception. + Handle result; + ASSIGN_RETURN_FAILURE_ON_EXCEPTION( + isolate(), result, + Object::GetProperty(object, object, &lookup, name, &attr)); + // If the property is not present, check if we need to throw an exception. if ((lookup.IsInterceptor() || lookup.IsHandler()) && attr == ABSENT && IsUndeclaredGlobal(object)) { return ReferenceError("not_defined", name); diff --git a/src/json-stringifier.h b/src/json-stringifier.h index f8bac94d13..c85f0b96d8 100644 --- a/src/json-stringifier.h +++ b/src/json-stringifier.h @@ -81,8 +81,9 @@ class BasicJsonStringifier BASE_EMBEDDED { } } - Handle ApplyToJsonFunction(Handle object, - Handle key); + MUST_USE_RESULT MaybeHandle ApplyToJsonFunction( + Handle object, + Handle key); Result SerializeGeneric(Handle object, Handle key, @@ -361,15 +362,17 @@ void BasicJsonStringifier::Append_(const Char* chars) { } -Handle BasicJsonStringifier::ApplyToJsonFunction( +MaybeHandle BasicJsonStringifier::ApplyToJsonFunction( Handle object, Handle key) { LookupResult lookup(isolate_); JSObject::cast(*object)->LookupRealNamedProperty(*tojson_string_, &lookup); if (!lookup.IsProperty()) return object; PropertyAttributes attr; - Handle fun = - Object::GetProperty(object, object, &lookup, tojson_string_, &attr); - if (fun.is_null()) return Handle::null(); + Handle fun; + ASSIGN_RETURN_ON_EXCEPTION( + isolate_, fun, + Object::GetProperty(object, object, &lookup, tojson_string_, &attr), + Object); if (!fun->IsJSFunction()) return object; // Call toJSON function. @@ -379,7 +382,7 @@ Handle BasicJsonStringifier::ApplyToJsonFunction( HandleScope scope(isolate_); object = Execution::Call(isolate_, fun, object, 1, argv, &has_exception); // Return empty handle to signal an exception. - if (has_exception) return Handle::null(); + if (has_exception) return MaybeHandle(); return scope.CloseAndEscape(object); } @@ -416,8 +419,10 @@ template BasicJsonStringifier::Result BasicJsonStringifier::Serialize_( Handle object, bool comma, Handle key) { if (object->IsJSObject()) { - object = ApplyToJsonFunction(object, key); - if (object.is_null()) return EXCEPTION; + ASSIGN_RETURN_ON_EXCEPTION_VALUE( + isolate_, object, + ApplyToJsonFunction(object, key), + EXCEPTION); } if (object->IsSmi()) { diff --git a/src/objects.cc b/src/objects.cc index 35a38ca3bd..bff4819db4 100644 --- a/src/objects.cc +++ b/src/objects.cc @@ -156,14 +156,14 @@ void Object::Lookup(Name* name, LookupResult* result) { } -Handle Object::GetPropertyWithReceiver( +MaybeHandle Object::GetPropertyWithReceiver( Handle object, Handle receiver, Handle name, PropertyAttributes* attributes) { LookupResult lookup(name->GetIsolate()); object->Lookup(*name, &lookup); - Handle result = + MaybeHandle result = GetProperty(object, receiver, &lookup, name, attributes); ASSERT(*attributes <= ABSENT); return result; @@ -389,10 +389,10 @@ Handle JSObject::EnsureWritableFastElements( } -Handle JSObject::GetPropertyWithCallback(Handle object, - Handle receiver, - Handle structure, - Handle name) { +MaybeHandle JSObject::GetPropertyWithCallback(Handle object, + Handle receiver, + Handle structure, + Handle name) { Isolate* isolate = name->GetIsolate(); // To accommodate both the old and the new api we switch on the // data structure used to store the callbacks. Eventually foreign @@ -415,8 +415,7 @@ Handle JSObject::GetPropertyWithCallback(Handle object, isolate->factory()->NewTypeError("incompatible_method_receiver", HandleVector(args, ARRAY_SIZE(args))); - isolate->Throw(*error); - return Handle::null(); + return isolate->Throw(error); } // TODO(rossberg): Handling symbols in the API requires changing the API, // so we do not support it for now. @@ -443,7 +442,7 @@ Handle JSObject::GetPropertyWithCallback(Handle object, PropertyCallbackArguments args(isolate, data->data(), *self, *object); v8::Handle result = args.Call(call_fun, v8::Utils::ToLocal(key)); - RETURN_HANDLE_IF_SCHEDULED_EXCEPTION(isolate, Object); + RETURN_EXCEPTION_IF_SCHEDULED_EXCEPTION(isolate, Object); if (result.IsEmpty()) { return isolate->factory()->undefined_value(); } @@ -556,7 +555,7 @@ MaybeObject* Object::GetPropertyWithDefinedGetter(Object* receiver, // Only deal with CALLBACKS and INTERCEPTOR -Handle JSObject::GetPropertyWithFailedAccessCheck( +MaybeHandle JSObject::GetPropertyWithFailedAccessCheck( Handle object, Handle receiver, LookupResult* result, @@ -829,11 +828,11 @@ bool JSObject::IsDirty() { } -Handle Object::GetProperty(Handle object, - Handle receiver, - LookupResult* result, - Handle key, - PropertyAttributes* attributes) { +MaybeHandle Object::GetProperty(Handle object, + Handle receiver, + LookupResult* result, + Handle key, + PropertyAttributes* attributes) { Isolate* isolate = result->isolate(); CALL_HEAP_FUNCTION( isolate, @@ -883,13 +882,15 @@ MaybeObject* Object::GetProperty(Object* receiver, JSObject* checked = JSObject::cast(current); if (!isolate->MayNamedAccess(checked, name, v8::ACCESS_GET)) { HandleScope scope(isolate); - Handle value = JSObject::GetPropertyWithFailedAccessCheck( - handle(checked, isolate), - handle(receiver, isolate), - result, - handle(name, isolate), - attributes); - RETURN_IF_EMPTY_HANDLE(isolate, value); + Handle value; + ASSIGN_RETURN_FAILURE_ON_EXCEPTION( + isolate, value, + JSObject::GetPropertyWithFailedAccessCheck( + handle(checked, isolate), + handle(receiver, isolate), + result, + handle(name, isolate), + attributes)); return *value; } } @@ -923,24 +924,28 @@ MaybeObject* Object::GetProperty(Object* receiver, return result->GetConstant(); case CALLBACKS: { HandleScope scope(isolate); - Handle value = JSObject::GetPropertyWithCallback( - handle(result->holder(), isolate), - handle(receiver, isolate), - handle(result->GetCallbackObject(), isolate), - handle(name, isolate)); - RETURN_IF_EMPTY_HANDLE(isolate, value); + Handle value; + ASSIGN_RETURN_FAILURE_ON_EXCEPTION( + isolate, value, + JSObject::GetPropertyWithCallback( + handle(result->holder(), isolate), + handle(receiver, isolate), + handle(result->GetCallbackObject(), isolate), + handle(name, isolate))); return *value; } case HANDLER: return result->proxy()->GetPropertyWithHandler(receiver, name); case INTERCEPTOR: { HandleScope scope(isolate); - Handle value = JSObject::GetPropertyWithInterceptor( - handle(result->holder(), isolate), - handle(receiver, isolate), - handle(name, isolate), - attributes); - RETURN_IF_EMPTY_HANDLE(isolate, value); + Handle value; + ASSIGN_RETURN_FAILURE_ON_EXCEPTION( + isolate, value, + JSObject::GetPropertyWithInterceptor( + handle(result->holder(), isolate), + handle(receiver, isolate), + handle(name, isolate), + attributes)); return *value; } case NONEXISTENT: @@ -13206,7 +13211,7 @@ InterceptorInfo* JSObject::GetIndexedInterceptor() { } -Handle JSObject::GetPropertyPostInterceptor( +MaybeHandle JSObject::GetPropertyPostInterceptor( Handle object, Handle receiver, Handle name, @@ -13215,17 +13220,15 @@ Handle JSObject::GetPropertyPostInterceptor( Isolate* isolate = object->GetIsolate(); LookupResult lookup(isolate); object->LocalLookupRealNamedProperty(*name, &lookup); - Handle result; if (lookup.IsFound()) { - result = GetProperty(object, receiver, &lookup, name, attributes); + return GetProperty(object, receiver, &lookup, name, attributes); } else { // Continue searching via the prototype chain. Handle prototype(object->GetPrototype(), isolate); *attributes = ABSENT; if (prototype->IsNull()) return isolate->factory()->undefined_value(); - result = GetPropertyWithReceiver(prototype, receiver, name, attributes); + return GetPropertyWithReceiver(prototype, receiver, name, attributes); } - return result; } @@ -13243,7 +13246,7 @@ MaybeObject* JSObject::GetLocalPropertyPostInterceptor( } -Handle JSObject::GetPropertyWithInterceptor( +MaybeHandle JSObject::GetPropertyWithInterceptor( Handle object, Handle receiver, Handle name, @@ -13265,7 +13268,7 @@ Handle JSObject::GetPropertyWithInterceptor( args(isolate, interceptor->data(), *receiver, *object); v8::Handle result = args.Call(getter, v8::Utils::ToLocal(name_string)); - RETURN_HANDLE_IF_SCHEDULED_EXCEPTION(isolate, Object); + RETURN_EXCEPTION_IF_SCHEDULED_EXCEPTION(isolate, Object); if (!result.IsEmpty()) { *attributes = NONE; Handle result_internal = v8::Utils::OpenHandle(*result); diff --git a/src/objects.h b/src/objects.h index 6313e53439..1bf090043b 100644 --- a/src/objects.h +++ b/src/objects.h @@ -1536,10 +1536,11 @@ class Object : public MaybeObject { PropertyAttributes* attributes); // TODO(yangguo): this should eventually replace the non-handlified version. - static Handle GetPropertyWithReceiver(Handle object, - Handle receiver, - Handle name, - PropertyAttributes* attributes); + MUST_USE_RESULT static MaybeHandle GetPropertyWithReceiver( + Handle object, + Handle receiver, + Handle name, + PropertyAttributes* attributes); MUST_USE_RESULT MaybeObject* GetPropertyWithReceiver( Object* receiver, Name* key, @@ -1550,11 +1551,12 @@ class Object : public MaybeObject { static Handle GetProperty(Handle object, Handle key); - static Handle GetProperty(Handle object, - Handle receiver, - LookupResult* result, - Handle key, - PropertyAttributes* attributes); + MUST_USE_RESULT static MaybeHandle GetProperty( + Handle object, + Handle receiver, + LookupResult* result, + Handle key, + PropertyAttributes* attributes); MUST_USE_RESULT MaybeObject* GetProperty(Object* receiver, LookupResult* result, @@ -2248,10 +2250,11 @@ class JSObject: public JSReceiver { uint32_t limit); MUST_USE_RESULT MaybeObject* PrepareSlowElementsForSort(uint32_t limit); - static Handle GetPropertyWithCallback(Handle object, - Handle receiver, - Handle structure, - Handle name); + MUST_USE_RESULT static MaybeHandle GetPropertyWithCallback( + Handle object, + Handle receiver, + Handle structure, + Handle name); MUST_USE_RESULT static MaybeHandle SetPropertyWithCallback( Handle object, @@ -2371,12 +2374,12 @@ class JSObject: public JSReceiver { static Handle SetAccessor(Handle object, Handle info); - static Handle GetPropertyWithInterceptor( + MUST_USE_RESULT static MaybeHandle GetPropertyWithInterceptor( Handle object, Handle receiver, Handle name, PropertyAttributes* attributes); - static Handle GetPropertyPostInterceptor( + MUST_USE_RESULT static MaybeHandle GetPropertyPostInterceptor( Handle object, Handle receiver, Handle name, @@ -2774,7 +2777,7 @@ class JSObject: public JSReceiver { ElementsKind to_kind); // Used from Object::GetProperty(). - static Handle GetPropertyWithFailedAccessCheck( + MUST_USE_RESULT static MaybeHandle GetPropertyWithFailedAccessCheck( Handle object, Handle receiver, LookupResult* result, diff --git a/src/runtime.cc b/src/runtime.cc index 6a0f13765d..9a6e4f6ec2 100644 --- a/src/runtime.cc +++ b/src/runtime.cc @@ -10828,18 +10828,17 @@ static MaybeObject* DebugLookupResultValue(Heap* heap, if (structure->IsForeign() || structure->IsAccessorInfo()) { Isolate* isolate = heap->isolate(); HandleScope scope(isolate); - Handle value = JSObject::GetPropertyWithCallback( + MaybeHandle maybe_value = JSObject::GetPropertyWithCallback( handle(result->holder(), isolate), handle(receiver, isolate), handle(structure, isolate), handle(name, isolate)); - if (value.is_null()) { - MaybeObject* exception = heap->isolate()->pending_exception(); - heap->isolate()->clear_pending_exception(); - if (caught_exception != NULL) *caught_exception = true; - return exception; - } - return *value; + Handle value; + if (maybe_value.ToHandle(&value)) return *value; + MaybeObject* exception = heap->isolate()->pending_exception(); + heap->isolate()->clear_pending_exception(); + if (caught_exception != NULL) *caught_exception = true; + return exception; } else { return heap->undefined_value(); } @@ -11022,9 +11021,10 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_DebugNamedInterceptorPropertyValue) { CONVERT_ARG_HANDLE_CHECKED(Name, name, 1); PropertyAttributes attributes; - Handle result = - JSObject::GetPropertyWithInterceptor(obj, obj, name, &attributes); - RETURN_IF_EMPTY_HANDLE(isolate, result); + Handle result; + ASSIGN_RETURN_FAILURE_ON_EXCEPTION( + isolate, result, + JSObject::GetPropertyWithInterceptor(obj, obj, name, &attributes)); return *result; } diff --git a/src/stub-cache.cc b/src/stub-cache.cc index 2a683d8708..4a200b9e3b 100644 --- a/src/stub-cache.cc +++ b/src/stub-cache.cc @@ -569,8 +569,9 @@ static MaybeObject* ThrowReferenceError(Isolate* isolate, Name* name) { } -static Handle LoadWithInterceptor(Arguments* args, - PropertyAttributes* attrs) { +MUST_USE_RESULT static MaybeHandle LoadWithInterceptor( + Arguments* args, + PropertyAttributes* attrs) { ASSERT(args->length() == StubCache::kInterceptorArgsLength); Handle name_handle = args->at(StubCache::kInterceptorArgsNameIndex); @@ -604,7 +605,7 @@ static Handle LoadWithInterceptor(Arguments* args, // Use the interceptor getter. v8::Handle r = callback_args.Call(getter, v8::Utils::ToLocal(name)); - RETURN_HANDLE_IF_SCHEDULED_EXCEPTION(isolate, Object); + RETURN_EXCEPTION_IF_SCHEDULED_EXCEPTION(isolate, Object); if (!r.IsEmpty()) { *attrs = NONE; Handle result = v8::Utils::OpenHandle(*r); @@ -613,9 +614,8 @@ static Handle LoadWithInterceptor(Arguments* args, } } - Handle result = JSObject::GetPropertyPostInterceptor( + return JSObject::GetPropertyPostInterceptor( holder_handle, receiver_handle, name_handle, attrs); - return result; } @@ -626,8 +626,9 @@ static Handle LoadWithInterceptor(Arguments* args, RUNTIME_FUNCTION(MaybeObject*, LoadPropertyWithInterceptorForLoad) { PropertyAttributes attr = NONE; HandleScope scope(isolate); - Handle result = LoadWithInterceptor(&args, &attr); - RETURN_IF_EMPTY_HANDLE(isolate, result); + Handle result; + ASSIGN_RETURN_FAILURE_ON_EXCEPTION( + isolate, result, LoadWithInterceptor(&args, &attr)); // If the property is present, return it. if (attr != ABSENT) return *result; @@ -638,8 +639,9 @@ RUNTIME_FUNCTION(MaybeObject*, LoadPropertyWithInterceptorForLoad) { RUNTIME_FUNCTION(MaybeObject*, LoadPropertyWithInterceptorForCall) { PropertyAttributes attr; HandleScope scope(isolate); - Handle result = LoadWithInterceptor(&args, &attr); - RETURN_IF_EMPTY_HANDLE(isolate, result); + Handle result; + ASSIGN_RETURN_FAILURE_ON_EXCEPTION( + isolate, result, LoadWithInterceptor(&args, &attr)); // This is call IC. In this case, we simply return the undefined result which // will lead to an exception when trying to invoke the result as a // function.