Reviewers: Michael Starzinger,
Description:
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.
Please review this at http://codereview.chromium.org/9600013/
SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge
Affected files:
M src/objects.h
M src/objects.cc
M src/runtime.cc
Index: src/objects.cc
diff --git a/src/objects.cc b/src/objects.cc
index
a27cc67ce3d6850053cfbb96d00ba3d29ebc33a4..9e93b28127b69ba1520362623e8fa8ec394c57ac
100644
--- a/src/objects.cc
+++ b/src/objects.cc
@@ -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(©)) 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);
}
}
}
Index: src/objects.h
diff --git a/src/objects.h b/src/objects.h
index
482b7944644361cd50f0728cc064b5a6dcd0e5fa..7d1457f50e24523ab6f111e8baaa0952ae66c7bd
100644
--- a/src/objects.h
+++ b/src/objects.h
@@ -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,12 @@ 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) {
+ return (component == ACCESSOR_GETTER) ? getter() : setter();
+ }
+
+ void set(AccessorComponent component, Object* value) {
+ if (component == ACCESSOR_GETTER) {
set_getter(value);
} else {
set_setter(value);
Index: src/runtime.cc
diff --git a/src/runtime.cc b/src/runtime.cc
index
d9c5bedc8ba216c5792bd9faed371f235bf174f5..34a47c5d00574cbf8eaf8d4c5a92edef4379f778
100644
--- a/src/runtime.cc
+++ b/src/runtime.cc
@@ -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);
}
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev