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.

Review URL: https://chromiumcodereview.appspot.com/10071009

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@11305 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 07301d7d
...@@ -4410,37 +4410,29 @@ MaybeObject* JSObject::DefineElementAccessor(uint32_t index, ...@@ -4410,37 +4410,29 @@ MaybeObject* JSObject::DefineElementAccessor(uint32_t index,
} }
MaybeObject* JSObject::DefinePropertyAccessor(String* name, MaybeObject* JSObject::CreateAccessorPairFor(String* name) {
Object* getter,
Object* setter,
PropertyAttributes attributes) {
// Lookup the name.
LookupResult result(GetHeap()->isolate()); LookupResult result(GetHeap()->isolate());
LocalLookupRealNamedProperty(name, &result); LocalLookupRealNamedProperty(name, &result);
if (result.IsFound()) { if (result.IsProperty() && result.type() == CALLBACKS) {
if (result.type() == CALLBACKS) { ASSERT(!result.IsDontDelete());
ASSERT(!result.IsDontDelete()); Object* obj = result.GetCallbackObject();
Object* obj = result.GetCallbackObject(); if (obj->IsAccessorPair()) {
// Need to preserve old getters/setters. return AccessorPair::cast(obj)->CopyWithoutTransitions();
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);
}
} }
} }
return GetHeap()->AllocateAccessorPair();
}
MaybeObject* JSObject::DefinePropertyAccessor(String* name,
Object* getter,
Object* setter,
PropertyAttributes attributes) {
AccessorPair* accessors; AccessorPair* accessors;
{ MaybeObject* maybe_accessors = GetHeap()->AllocateAccessorPair(); { MaybeObject* maybe_accessors = CreateAccessorPairFor(name);
if (!maybe_accessors->To(&accessors)) return maybe_accessors; if (!maybe_accessors->To(&accessors)) return maybe_accessors;
} }
accessors->SetComponents(getter, setter); accessors->SetComponents(getter, setter);
return SetPropertyCallback(name, accessors, attributes); return SetPropertyCallback(name, accessors, attributes);
} }
......
...@@ -2186,6 +2186,7 @@ class JSObject: public JSReceiver { ...@@ -2186,6 +2186,7 @@ class JSObject: public JSReceiver {
Object* getter, Object* getter,
Object* setter, Object* setter,
PropertyAttributes attributes); PropertyAttributes attributes);
MUST_USE_RESULT MaybeObject* CreateAccessorPairFor(String* name);
MUST_USE_RESULT MaybeObject* DefinePropertyAccessor( MUST_USE_RESULT MaybeObject* DefinePropertyAccessor(
String* name, String* name,
Object* getter, Object* getter,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment