Reviewers: Michael Starzinger,

Description:
Prepare DefinePropertyAccessor for callback transitions.

Although things are currently OK here, in the future it won't be enough to check
for the existence of a CALLBACKS result, we must additionally check that it
actually contains an accessor. In a nutshell: 'sed s/IsFound/IsProperty/' once
again...

Additionally, the control flow in DefinePropertyAccessor has been simplified by
using a helper function.


Please review this at http://codereview.chromium.org/10071009/

SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge

Affected files:
  M src/objects.h
  M src/objects.cc


Index: src/objects.cc
diff --git a/src/objects.cc b/src/objects.cc
index a4f63a1ca2d79698c96e2f7d6cdec554a884dd5f..961876b7d08e0fc1548c390b20b61be837e150c1 100644
--- a/src/objects.cc
+++ b/src/objects.cc
@@ -4410,37 +4410,29 @@ MaybeObject* JSObject::DefineElementAccessor(uint32_t index,
 }


-MaybeObject* JSObject::DefinePropertyAccessor(String* name,
-                                              Object* getter,
-                                              Object* setter,
- PropertyAttributes attributes) {
-  // Lookup the name.
+MaybeObject* JSObject::CreateAccessorPairFor(String* name) {
   LookupResult result(GetHeap()->isolate());
   LocalLookupRealNamedProperty(name, &result);
-  if (result.IsFound()) {
-    if (result.type() == CALLBACKS) {
-      ASSERT(!result.IsDontDelete());
-      Object* obj = result.GetCallbackObject();
-      // Need to preserve old getters/setters.
-      if (obj->IsAccessorPair()) {
-        AccessorPair* copy;
-        { MaybeObject* maybe_copy =
-              AccessorPair::cast(obj)->CopyWithoutTransitions();
-          if (!maybe_copy->To(&copy)) return maybe_copy;
-        }
-        copy->SetComponents(getter, setter);
-        // Use set to update attributes.
-        return SetPropertyCallback(name, copy, attributes);
-      }
+  if (result.IsProperty() && result.type() == CALLBACKS) {
+    ASSERT(!result.IsDontDelete());
+    Object* obj = result.GetCallbackObject();
+    if (obj->IsAccessorPair()) {
+      return AccessorPair::cast(obj)->CopyWithoutTransitions();
     }
   }
+  return GetHeap()->AllocateAccessorPair();
+}

+
+MaybeObject* JSObject::DefinePropertyAccessor(String* name,
+                                              Object* getter,
+                                              Object* setter,
+ PropertyAttributes attributes) {
   AccessorPair* accessors;
-  { MaybeObject* maybe_accessors = GetHeap()->AllocateAccessorPair();
+  { MaybeObject* maybe_accessors = CreateAccessorPairFor(name);
     if (!maybe_accessors->To(&accessors)) return maybe_accessors;
   }
   accessors->SetComponents(getter, setter);
-
   return SetPropertyCallback(name, accessors, attributes);
 }

Index: src/objects.h
diff --git a/src/objects.h b/src/objects.h
index 147dc00d4c70e52da5f3469a114b2d940d4cc67d..b728d0ce274d1975b7d8f80bddb2177ef7d7955a 100644
--- a/src/objects.h
+++ b/src/objects.h
@@ -2186,6 +2186,7 @@ class JSObject: public JSReceiver {
       Object* getter,
       Object* setter,
       PropertyAttributes attributes);
+  MUST_USE_RESULT MaybeObject* CreateAccessorPairFor(String* name);
   MUST_USE_RESULT MaybeObject* DefinePropertyAccessor(
       String* name,
       Object* getter,


--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev

Reply via email to