Use an enum for indicating the component of an AccessorPair instead of a boolean flag.

In addition, this CL introduces a tiny new helper, which will come in handy later,
plus some minor cleanup.

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

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@10918 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
svenpanne@chromium.org 2012-03-05 12:11:28 +00:00
parent 9efc76ccbf
commit 371ed3e974
3 changed files with 42 additions and 32 deletions

View File

@ -4367,7 +4367,7 @@ void JSObject::LookupCallback(String* name, LookupResult* result) {
static bool UpdateGetterSetterInDictionary(
SeededNumberDictionary* dictionary,
uint32_t index,
bool is_getter,
AccessorComponent component,
Object* fun,
PropertyAttributes attributes) {
int entry = dictionary->FindEntry(index);
@ -4381,7 +4381,7 @@ static bool UpdateGetterSetterInDictionary(
dictionary->DetailsAtPut(entry,
PropertyDetails(attributes, CALLBACKS, index));
}
AccessorPair::cast(result)->set(is_getter, fun);
AccessorPair::cast(result)->set(component, fun);
return true;
}
}
@ -4390,7 +4390,7 @@ static bool UpdateGetterSetterInDictionary(
MaybeObject* JSObject::DefineElementAccessor(uint32_t index,
bool is_getter,
AccessorComponent component,
Object* fun,
PropertyAttributes attributes) {
switch (GetElementsKind()) {
@ -4412,7 +4412,7 @@ MaybeObject* JSObject::DefineElementAccessor(uint32_t index,
case DICTIONARY_ELEMENTS:
if (UpdateGetterSetterInDictionary(element_dictionary(),
index,
is_getter,
component,
fun,
attributes)) {
return GetHeap()->undefined_value();
@ -4433,7 +4433,7 @@ MaybeObject* JSObject::DefineElementAccessor(uint32_t index,
SeededNumberDictionary::cast(arguments);
if (UpdateGetterSetterInDictionary(dictionary,
index,
is_getter,
component,
fun,
attributes)) {
return GetHeap()->undefined_value();
@ -4448,14 +4448,14 @@ MaybeObject* JSObject::DefineElementAccessor(uint32_t index,
{ MaybeObject* maybe_accessors = GetHeap()->AllocateAccessorPair();
if (!maybe_accessors->To(&accessors)) return maybe_accessors;
}
accessors->set(is_getter, fun);
accessors->set(component, fun);
return SetElementCallback(index, accessors, attributes);
}
MaybeObject* JSObject::DefinePropertyAccessor(String* name,
bool is_getter,
AccessorComponent component,
Object* fun,
PropertyAttributes attributes) {
// Lookup the name.
@ -4473,7 +4473,7 @@ MaybeObject* JSObject::DefinePropertyAccessor(String* name,
AccessorPair::cast(obj)->CopyWithoutTransitions();
if (!maybe_copy->To(&copy)) return maybe_copy;
}
copy->set(is_getter, fun);
copy->set(component, fun);
// Use set to update attributes.
return SetPropertyCallback(name, copy, attributes);
}
@ -4484,7 +4484,7 @@ MaybeObject* JSObject::DefinePropertyAccessor(String* name,
{ MaybeObject* maybe_accessors = GetHeap()->AllocateAccessorPair();
if (!maybe_accessors->To(&accessors)) return maybe_accessors;
}
accessors->set(is_getter, fun);
accessors->set(component, fun);
return SetPropertyCallback(name, accessors, attributes);
}
@ -4593,7 +4593,7 @@ MaybeObject* JSObject::SetPropertyCallback(String* name,
}
MaybeObject* JSObject::DefineAccessor(String* name,
bool is_getter,
AccessorComponent component,
Object* fun,
PropertyAttributes attributes) {
ASSERT(fun->IsSpecFunction() || fun->IsUndefined());
@ -4609,7 +4609,7 @@ MaybeObject* JSObject::DefineAccessor(String* name,
Object* proto = GetPrototype();
if (proto->IsNull()) return this;
ASSERT(proto->IsJSGlobalObject());
return JSObject::cast(proto)->DefineAccessor(name, is_getter,
return JSObject::cast(proto)->DefineAccessor(name, component,
fun, attributes);
}
@ -4624,8 +4624,8 @@ MaybeObject* JSObject::DefineAccessor(String* name,
uint32_t index = 0;
return name->AsArrayIndex(&index) ?
DefineElementAccessor(index, is_getter, fun, attributes) :
DefinePropertyAccessor(name, is_getter, fun, attributes);
DefineElementAccessor(index, component, fun, attributes) :
DefinePropertyAccessor(name, component, fun, attributes);
}
@ -4711,7 +4711,7 @@ MaybeObject* JSObject::DefineAccessor(AccessorInfo* info) {
}
Object* JSObject::LookupAccessor(String* name, bool is_getter) {
Object* JSObject::LookupAccessor(String* name, AccessorComponent component) {
Heap* heap = GetHeap();
// Make sure that the top context does not change when doing callbacks or
@ -4737,12 +4737,9 @@ Object* JSObject::LookupAccessor(String* name, bool is_getter) {
int entry = dictionary->FindEntry(index);
if (entry != SeededNumberDictionary::kNotFound) {
Object* element = dictionary->ValueAt(entry);
PropertyDetails details = dictionary->DetailsAt(entry);
if (details.type() == CALLBACKS) {
if (element->IsAccessorPair()) {
AccessorPair* accessors = AccessorPair::cast(element);
return is_getter ? accessors->getter() : accessors->setter();
}
if (dictionary->DetailsAt(entry).type() == CALLBACKS &&
element->IsAccessorPair()) {
return AccessorPair::cast(element)->get(component);
}
}
}
@ -4758,8 +4755,7 @@ Object* JSObject::LookupAccessor(String* name, bool is_getter) {
if (result.type() == CALLBACKS) {
Object* obj = result.GetCallbackObject();
if (obj->IsAccessorPair()) {
AccessorPair* accessors = AccessorPair::cast(obj);
return is_getter ? accessors->getter() : accessors->setter();
return AccessorPair::cast(obj)->get(component);
}
}
}

View File

@ -1360,6 +1360,13 @@ enum SetPropertyMode {
};
// Indicator for one component of an AccessorPair.
enum AccessorComponent {
ACCESSOR_GETTER,
ACCESSOR_SETTER
};
// JSReceiver includes types on which properties can be defined, i.e.,
// JSObject and JSProxy.
class JSReceiver: public HeapObject {
@ -1612,10 +1619,10 @@ class JSObject: public JSReceiver {
bool continue_search);
MUST_USE_RESULT MaybeObject* DefineAccessor(String* name,
bool is_getter,
AccessorComponent component,
Object* fun,
PropertyAttributes attributes);
Object* LookupAccessor(String* name, bool is_getter);
Object* LookupAccessor(String* name, AccessorComponent component);
MUST_USE_RESULT MaybeObject* DefineAccessor(AccessorInfo* info);
@ -2166,12 +2173,12 @@ class JSObject: public JSReceiver {
PropertyAttributes attributes);
MUST_USE_RESULT MaybeObject* DefineElementAccessor(
uint32_t index,
bool is_getter,
AccessorComponent component,
Object* fun,
PropertyAttributes attributes);
MUST_USE_RESULT MaybeObject* DefinePropertyAccessor(
String* name,
bool is_getter,
AccessorComponent component,
Object* fun,
PropertyAttributes attributes);
void LookupInDescriptor(String* name, LookupResult* result);
@ -7927,9 +7934,14 @@ class AccessorPair: public Struct {
MUST_USE_RESULT MaybeObject* CopyWithoutTransitions();
// TODO(svenpanne) Evil temporary helper, will vanish soon...
void set(bool modify_getter, Object* value) {
if (modify_getter) {
Object* get(AccessorComponent component) {
ASSERT(component == ACCESSOR_GETTER || component == ACCESSOR_SETTER);
return (component == ACCESSOR_GETTER) ? getter() : setter();
}
void set(AccessorComponent component, Object* value) {
ASSERT(component == ACCESSOR_GETTER || component == ACCESSOR_SETTER);
if (component == ACCESSOR_GETTER) {
set_getter(value);
} else {
set_setter(value);

View File

@ -4318,7 +4318,7 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_DefineOrRedefineAccessorProperty) {
HandleScope scope(isolate);
CONVERT_ARG_HANDLE_CHECKED(JSObject, obj, 0);
CONVERT_ARG_CHECKED(String, name, 1);
CONVERT_SMI_ARG_CHECKED(flag_setter, 2);
CONVERT_SMI_ARG_CHECKED(flag, 2);
Object* fun = args[3];
CONVERT_SMI_ARG_CHECKED(unchecked, 4);
@ -4327,7 +4327,8 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_DefineOrRedefineAccessorProperty) {
RUNTIME_ASSERT(!obj->IsNull());
RUNTIME_ASSERT(fun->IsSpecFunction() || fun->IsUndefined());
return obj->DefineAccessor(name, flag_setter == 0, fun, attr);
AccessorComponent component = flag == 0 ? ACCESSOR_GETTER : ACCESSOR_SETTER;
return obj->DefineAccessor(name, component, fun, attr);
}
// Implements part of 8.12.9 DefineOwnProperty.
@ -10292,7 +10293,8 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_LookupAccessor) {
CONVERT_ARG_CHECKED(JSObject, obj, 0);
CONVERT_ARG_CHECKED(String, name, 1);
CONVERT_SMI_ARG_CHECKED(flag, 2);
return obj->LookupAccessor(name, flag == 0);
AccessorComponent component = flag == 0 ? ACCESSOR_GETTER : ACCESSOR_SETTER;
return obj->LookupAccessor(name, component);
}