Revision: 20510
Author:   [email protected]
Date:     Fri Apr  4 12:25:45 2014 UTC
Log:      Return MaybeHandle from GetProperty.

[email protected]

Review URL: https://codereview.chromium.org/225673003
http://code.google.com/p/v8/source/detail?r=20510

Modified:
 /branches/bleeding_edge/src/api.cc
 /branches/bleeding_edge/src/ic.cc
 /branches/bleeding_edge/src/json-stringifier.h
 /branches/bleeding_edge/src/objects.cc
 /branches/bleeding_edge/src/objects.h
 /branches/bleeding_edge/src/runtime.cc
 /branches/bleeding_edge/src/stub-cache.cc

=======================================
--- /branches/bleeding_edge/src/api.cc  Fri Apr  4 12:06:11 2014 UTC
+++ /branches/bleeding_edge/src/api.cc  Fri Apr  4 12:25:45 2014 UTC
@@ -3541,10 +3541,9 @@
   // 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);
=======================================
--- /branches/bleeding_edge/src/ic.cc   Fri Apr  4 12:06:11 2014 UTC
+++ /branches/bleeding_edge/src/ic.cc   Fri Apr  4 12:25:45 2014 UTC
@@ -598,11 +598,11 @@

   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);
=======================================
--- /branches/bleeding_edge/src/json-stringifier.h Thu Apr 3 12:30:37 2014 UTC +++ /branches/bleeding_edge/src/json-stringifier.h Fri Apr 4 12:25:45 2014 UTC
@@ -81,8 +81,9 @@
     }
   }

-  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 @@
 }


-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 @@
   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 @@
 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()) {
=======================================
--- /branches/bleeding_edge/src/objects.cc      Fri Apr  4 12:06:11 2014 UTC
+++ /branches/bleeding_edge/src/objects.cc      Fri Apr  4 12:25:45 2014 UTC
@@ -156,14 +156,14 @@
 }


-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<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 @@
           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 @@
     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 @@


 // 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 @@
 }


-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 @@
         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 @@
       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 @@
 }


-Handle<Object> JSObject::GetPropertyPostInterceptor(
+MaybeHandle<Object> JSObject::GetPropertyPostInterceptor(
     Handle<JSObject> object,
     Handle<Object> receiver,
     Handle<Name> name,
@@ -13215,17 +13220,15 @@
   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 @@
 }


-Handle<Object> JSObject::GetPropertyWithInterceptor(
+MaybeHandle<Object> JSObject::GetPropertyWithInterceptor(
     Handle<JSObject> object,
     Handle<Object> receiver,
     Handle<Name> name,
@@ -13265,7 +13268,7 @@
         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);
=======================================
--- /branches/bleeding_edge/src/objects.h       Fri Apr  4 12:06:11 2014 UTC
+++ /branches/bleeding_edge/src/objects.h       Fri Apr  4 12:25:45 2014 UTC
@@ -1536,10 +1536,11 @@
       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 @@

   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 @@
                                                    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 @@
   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 @@
                                    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,
=======================================
--- /branches/bleeding_edge/src/runtime.cc      Fri Apr  4 12:06:11 2014 UTC
+++ /branches/bleeding_edge/src/runtime.cc      Fri Apr  4 12:25:45 2014 UTC
@@ -10828,18 +10828,17 @@
       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 @@
   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;
 }

=======================================
--- /branches/bleeding_edge/src/stub-cache.cc   Fri Apr  4 12:06:11 2014 UTC
+++ /branches/bleeding_edge/src/stub-cache.cc   Fri Apr  4 12:25:45 2014 UTC
@@ -569,8 +569,9 @@
 }


-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 @@
     // 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 @@
     }
   }

-  Handle<Object> result = JSObject::GetPropertyPostInterceptor(
+  return JSObject::GetPropertyPostInterceptor(
       holder_handle, receiver_handle, name_handle, attrs);
-  return result;
 }


@@ -626,8 +626,9 @@
 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*, 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.

--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to