Return MaybeHandle from GetProperty.

R=ishell@chromium.org

Review URL: https://codereview.chromium.org/225673003

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@20510 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
yangguo@chromium.org 2014-04-04 12:25:45 +00:00
parent dd7bb01688
commit b0def354bc
7 changed files with 107 additions and 95 deletions

View File

@ -3541,10 +3541,9 @@ static Local<Value> GetPropertyByLookup(i::Isolate* isolate,
// an exception.
EXCEPTION_PREAMBLE(isolate);
PropertyAttributes ignored;
i::Handle<i::Object> result =
i::Object::GetProperty(receiver, receiver, lookup, name,
&ignored);
has_pending_exception = result.is_null();
i::Handle<i::Object> result;
has_pending_exception = !i::Object::GetProperty(
receiver, receiver, lookup, name, &ignored).ToHandle(&result);
EXCEPTION_BAILOUT_CHECK(isolate, Local<Value>());
return Utils::ToLocal(result);

View File

@ -598,11 +598,11 @@ MaybeObject* LoadIC::Load(Handle<Object> object,
PropertyAttributes attr;
// Get the property.
Handle<Object> 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<Object> 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);

View File

@ -81,8 +81,9 @@ class BasicJsonStringifier BASE_EMBEDDED {
}
}
Handle<Object> ApplyToJsonFunction(Handle<Object> object,
Handle<Object> key);
MUST_USE_RESULT MaybeHandle<Object> ApplyToJsonFunction(
Handle<Object> object,
Handle<Object> key);
Result SerializeGeneric(Handle<Object> object,
Handle<Object> key,
@ -361,15 +362,17 @@ void BasicJsonStringifier::Append_(const Char* chars) {
}
Handle<Object> BasicJsonStringifier::ApplyToJsonFunction(
MaybeHandle<Object> BasicJsonStringifier::ApplyToJsonFunction(
Handle<Object> object, Handle<Object> key) {
LookupResult lookup(isolate_);
JSObject::cast(*object)->LookupRealNamedProperty(*tojson_string_, &lookup);
if (!lookup.IsProperty()) return object;
PropertyAttributes attr;
Handle<Object> fun =
Object::GetProperty(object, object, &lookup, tojson_string_, &attr);
if (fun.is_null()) return Handle<Object>::null();
Handle<Object> 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<Object> 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<Object>::null();
if (has_exception) return MaybeHandle<Object>();
return scope.CloseAndEscape(object);
}
@ -416,8 +419,10 @@ template <bool deferred_string_key>
BasicJsonStringifier::Result BasicJsonStringifier::Serialize_(
Handle<Object> object, bool comma, Handle<Object> 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()) {

View File

@ -156,14 +156,14 @@ void Object::Lookup(Name* name, LookupResult* result) {
}
Handle<Object> Object::GetPropertyWithReceiver(
MaybeHandle<Object> Object::GetPropertyWithReceiver(
Handle<Object> object,
Handle<Object> receiver,
Handle<Name> name,
PropertyAttributes* attributes) {
LookupResult lookup(name->GetIsolate());
object->Lookup(*name, &lookup);
Handle<Object> result =
MaybeHandle<Object> result =
GetProperty(object, receiver, &lookup, name, attributes);
ASSERT(*attributes <= ABSENT);
return result;
@ -389,10 +389,10 @@ Handle<FixedArray> JSObject::EnsureWritableFastElements(
}
Handle<Object> JSObject::GetPropertyWithCallback(Handle<JSObject> object,
Handle<Object> receiver,
Handle<Object> structure,
Handle<Name> name) {
MaybeHandle<Object> JSObject::GetPropertyWithCallback(Handle<JSObject> object,
Handle<Object> receiver,
Handle<Object> structure,
Handle<Name> 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<Object> JSObject::GetPropertyWithCallback(Handle<JSObject> object,
isolate->factory()->NewTypeError("incompatible_method_receiver",
HandleVector(args,
ARRAY_SIZE(args)));
isolate->Throw(*error);
return Handle<Object>::null();
return isolate->Throw<Object>(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<Object> JSObject::GetPropertyWithCallback(Handle<JSObject> object,
PropertyCallbackArguments args(isolate, data->data(), *self, *object);
v8::Handle<v8::Value> 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<Object> JSObject::GetPropertyWithFailedAccessCheck(
MaybeHandle<Object> JSObject::GetPropertyWithFailedAccessCheck(
Handle<JSObject> object,
Handle<Object> receiver,
LookupResult* result,
@ -829,11 +828,11 @@ bool JSObject::IsDirty() {
}
Handle<Object> Object::GetProperty(Handle<Object> object,
Handle<Object> receiver,
LookupResult* result,
Handle<Name> key,
PropertyAttributes* attributes) {
MaybeHandle<Object> Object::GetProperty(Handle<Object> object,
Handle<Object> receiver,
LookupResult* result,
Handle<Name> 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<Object> value = JSObject::GetPropertyWithFailedAccessCheck(
handle(checked, isolate),
handle(receiver, isolate),
result,
handle(name, isolate),
attributes);
RETURN_IF_EMPTY_HANDLE(isolate, value);
Handle<Object> 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<Object> value = JSObject::GetPropertyWithCallback(
handle(result->holder(), isolate),
handle(receiver, isolate),
handle(result->GetCallbackObject(), isolate),
handle(name, isolate));
RETURN_IF_EMPTY_HANDLE(isolate, value);
Handle<Object> 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<Object> value = JSObject::GetPropertyWithInterceptor(
handle(result->holder(), isolate),
handle(receiver, isolate),
handle(name, isolate),
attributes);
RETURN_IF_EMPTY_HANDLE(isolate, value);
Handle<Object> 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<Object> JSObject::GetPropertyPostInterceptor(
MaybeHandle<Object> JSObject::GetPropertyPostInterceptor(
Handle<JSObject> object,
Handle<Object> receiver,
Handle<Name> name,
@ -13215,17 +13220,15 @@ Handle<Object> JSObject::GetPropertyPostInterceptor(
Isolate* isolate = object->GetIsolate();
LookupResult lookup(isolate);
object->LocalLookupRealNamedProperty(*name, &lookup);
Handle<Object> 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<Object> 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<Object> JSObject::GetPropertyWithInterceptor(
MaybeHandle<Object> JSObject::GetPropertyWithInterceptor(
Handle<JSObject> object,
Handle<Object> receiver,
Handle<Name> name,
@ -13265,7 +13268,7 @@ Handle<Object> JSObject::GetPropertyWithInterceptor(
args(isolate, interceptor->data(), *receiver, *object);
v8::Handle<v8::Value> 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<Object> result_internal = v8::Utils::OpenHandle(*result);

View File

@ -1536,10 +1536,11 @@ class Object : public MaybeObject {
PropertyAttributes* attributes);
// TODO(yangguo): this should eventually replace the non-handlified version.
static Handle<Object> GetPropertyWithReceiver(Handle<Object> object,
Handle<Object> receiver,
Handle<Name> name,
PropertyAttributes* attributes);
MUST_USE_RESULT static MaybeHandle<Object> GetPropertyWithReceiver(
Handle<Object> object,
Handle<Object> receiver,
Handle<Name> name,
PropertyAttributes* attributes);
MUST_USE_RESULT MaybeObject* GetPropertyWithReceiver(
Object* receiver,
Name* key,
@ -1550,11 +1551,12 @@ class Object : public MaybeObject {
static Handle<Object> GetProperty(Handle<Object> object,
Handle<Name> key);
static Handle<Object> GetProperty(Handle<Object> object,
Handle<Object> receiver,
LookupResult* result,
Handle<Name> key,
PropertyAttributes* attributes);
MUST_USE_RESULT static MaybeHandle<Object> GetProperty(
Handle<Object> object,
Handle<Object> receiver,
LookupResult* result,
Handle<Name> 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<Object> GetPropertyWithCallback(Handle<JSObject> object,
Handle<Object> receiver,
Handle<Object> structure,
Handle<Name> name);
MUST_USE_RESULT static MaybeHandle<Object> GetPropertyWithCallback(
Handle<JSObject> object,
Handle<Object> receiver,
Handle<Object> structure,
Handle<Name> name);
MUST_USE_RESULT static MaybeHandle<Object> SetPropertyWithCallback(
Handle<JSObject> object,
@ -2371,12 +2374,12 @@ class JSObject: public JSReceiver {
static Handle<Object> SetAccessor(Handle<JSObject> object,
Handle<AccessorInfo> info);
static Handle<Object> GetPropertyWithInterceptor(
MUST_USE_RESULT static MaybeHandle<Object> GetPropertyWithInterceptor(
Handle<JSObject> object,
Handle<Object> receiver,
Handle<Name> name,
PropertyAttributes* attributes);
static Handle<Object> GetPropertyPostInterceptor(
MUST_USE_RESULT static MaybeHandle<Object> GetPropertyPostInterceptor(
Handle<JSObject> object,
Handle<Object> receiver,
Handle<Name> name,
@ -2774,7 +2777,7 @@ class JSObject: public JSReceiver {
ElementsKind to_kind);
// Used from Object::GetProperty().
static Handle<Object> GetPropertyWithFailedAccessCheck(
MUST_USE_RESULT static MaybeHandle<Object> GetPropertyWithFailedAccessCheck(
Handle<JSObject> object,
Handle<Object> receiver,
LookupResult* result,

View File

@ -10828,18 +10828,17 @@ static MaybeObject* DebugLookupResultValue(Heap* heap,
if (structure->IsForeign() || structure->IsAccessorInfo()) {
Isolate* isolate = heap->isolate();
HandleScope scope(isolate);
Handle<Object> value = JSObject::GetPropertyWithCallback(
MaybeHandle<Object> 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<Object> 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<Object> result =
JSObject::GetPropertyWithInterceptor(obj, obj, name, &attributes);
RETURN_IF_EMPTY_HANDLE(isolate, result);
Handle<Object> result;
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
isolate, result,
JSObject::GetPropertyWithInterceptor(obj, obj, name, &attributes));
return *result;
}

View File

@ -569,8 +569,9 @@ static MaybeObject* ThrowReferenceError(Isolate* isolate, Name* name) {
}
static Handle<Object> LoadWithInterceptor(Arguments* args,
PropertyAttributes* attrs) {
MUST_USE_RESULT static MaybeHandle<Object> LoadWithInterceptor(
Arguments* args,
PropertyAttributes* attrs) {
ASSERT(args->length() == StubCache::kInterceptorArgsLength);
Handle<Name> name_handle =
args->at<Name>(StubCache::kInterceptorArgsNameIndex);
@ -604,7 +605,7 @@ static Handle<Object> LoadWithInterceptor(Arguments* args,
// Use the interceptor getter.
v8::Handle<v8::Value> 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<Object> result = v8::Utils::OpenHandle(*r);
@ -613,9 +614,8 @@ static Handle<Object> LoadWithInterceptor(Arguments* args,
}
}
Handle<Object> result = JSObject::GetPropertyPostInterceptor(
return JSObject::GetPropertyPostInterceptor(
holder_handle, receiver_handle, name_handle, attrs);
return result;
}
@ -626,8 +626,9 @@ static Handle<Object> LoadWithInterceptor(Arguments* args,
RUNTIME_FUNCTION(MaybeObject*, LoadPropertyWithInterceptorForLoad) {
PropertyAttributes attr = NONE;
HandleScope scope(isolate);
Handle<Object> result = LoadWithInterceptor(&args, &attr);
RETURN_IF_EMPTY_HANDLE(isolate, result);
Handle<Object> 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<Object> result = LoadWithInterceptor(&args, &attr);
RETURN_IF_EMPTY_HANDLE(isolate, result);
Handle<Object> 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.