summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@digia.com>2013-04-09 09:48:21 +0200
committerSimon Hausmann <simon.hausmann@digia.com>2013-04-12 14:27:11 +0200
commit6c14ede1dd54f189fc461267e6671cb0f690c629 (patch)
tree868f04bb74641c13c16b088eb3d8223c18ef1f31
parent1e87e39a1987da9f0ad454b8b4f6c40055e50799 (diff)
Make the PropertyAttributes a proper class
Change-Id: Ia81236136aedcddaad303187b353cfcf03d792c6 Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
-rw-r--r--src/v4/qv4global.h60
-rw-r--r--src/v4/qv4internalclass.cpp2
-rw-r--r--src/v4/qv4propertydescriptor.h14
-rw-r--r--src/v4/qv4v8.cpp34
4 files changed, 76 insertions, 34 deletions
diff --git a/src/v4/qv4global.h b/src/v4/qv4global.h
index 43409b26..11a74bbd 100644
--- a/src/v4/qv4global.h
+++ b/src/v4/qv4global.h
@@ -59,7 +59,8 @@ QT_BEGIN_NAMESPACE
namespace QQmlJS {
namespace VM {
-enum {
+
+enum PropertyFlag {
Attr_Default = 0,
Attr_Accessor = 0x1,
Attr_NotWritable = 0x2,
@@ -69,7 +70,62 @@ enum {
Attr_Invalid = 0xff
};
-typedef uchar PropertyAttributes;
+Q_DECLARE_FLAGS(PropertyFlags, PropertyFlag);
+Q_DECLARE_OPERATORS_FOR_FLAGS(PropertyFlags);
+
+struct PropertyAttributes
+{
+ union {
+ uchar m_all;
+ struct {
+ uchar m_flags : 4;
+ uchar m_mask : 4;
+ };
+ struct {
+ uchar m_type : 1;
+ uchar m_writable : 1;
+ uchar m_enumerable : 1;
+ uchar m_configurable : 1;
+ uchar type_set : 1;
+ uchar writable_set : 1;
+ uchar enumerable_set : 1;
+ uchar configurable_set : 1;
+ };
+ };
+
+ enum Type {
+ Data = 0,
+ Accessor = 1,
+ Generic = 2
+ };
+
+ PropertyAttributes() : m_all(0) {}
+ PropertyAttributes(PropertyFlag f) : m_all(0) {
+ setType(f & Attr_Accessor ? Accessor : Data);
+ setWritable(!(f & Attr_NotWritable));
+ setEnumberable(!(f & Attr_NotEnumerable));
+ setConfigurable(!(f & Attr_NotConfigurable));
+ }
+ PropertyAttributes(PropertyFlags f) : m_all(0) {
+ setType(f & Attr_Accessor ? Accessor : Data);
+ setWritable(!(f & Attr_NotWritable));
+ setEnumberable(!(f & Attr_NotEnumerable));
+ setConfigurable(!(f & Attr_NotConfigurable));
+ }
+ PropertyAttributes(const PropertyAttributes &other) : m_all(other.m_all) {}
+ PropertyAttributes & operator=(const PropertyAttributes &other) { m_all = other.m_all; return *this; }
+
+ void setType(Type t) { m_type = t; type_set = true; }
+ Type type() const { return type_set ? (Type)m_type : Generic; }
+
+ void setWritable(bool b) { m_writable = b; writable_set = true; }
+ void setConfigurable(bool b) { m_configurable = b; configurable_set = true; }
+ void setEnumberable(bool b) { m_enumerable = b; enumerable_set = true; }
+
+ bool writable() const { return m_writable; }
+ bool enumerable() const { return m_enumerable; }
+ bool configurable() const { return m_configurable; }
+};
}
}
diff --git a/src/v4/qv4internalclass.cpp b/src/v4/qv4internalclass.cpp
index 0f4a9452..b040aba6 100644
--- a/src/v4/qv4internalclass.cpp
+++ b/src/v4/qv4internalclass.cpp
@@ -61,7 +61,7 @@ InternalClass::InternalClass(const QQmlJS::VM::InternalClass &other)
InternalClass *InternalClass::addMember(String *string, PropertyAttributes data, uint *index)
{
engine->identifierCache->toIdentifier(string);
- uint id = string->identifier | ((uint)data << 24);
+ uint id = string->identifier | ((uint)data.m_flags << 23);
assert(propertyTable.constFind(id) == propertyTable.constEnd());
diff --git a/src/v4/qv4propertydescriptor.h b/src/v4/qv4propertydescriptor.h
index 7bde67b3..56f63016 100644
--- a/src/v4/qv4propertydescriptor.h
+++ b/src/v4/qv4propertydescriptor.h
@@ -100,15 +100,11 @@ struct PropertyDescriptor : public Property
}
PropertyAttributes toPropertyAttributes() const {
- PropertyAttributes attrs = 0;
- if (type == Accessor)
- attrs |= Attr_Accessor;
- else if (writable != Enabled)
- attrs |= Attr_NotWritable;
- if (enumerable != Enabled)
- attrs |= Attr_NotEnumerable;
- if (configurable != Enabled)
- attrs |= Attr_NotConfigurable;
+ PropertyAttributes attrs;
+ attrs.setType(type == Accessor ? PropertyAttributes::Accessor : PropertyAttributes::Data);
+ attrs.setWritable(writable == Enabled);
+ attrs.setEnumberable(enumerable == Enabled);
+ attrs.setConfigurable(configurable == Enabled);
return attrs;
}
diff --git a/src/v4/qv4v8.cpp b/src/v4/qv4v8.cpp
index 56acd114..337a3850 100644
--- a/src/v4/qv4v8.cpp
+++ b/src/v4/qv4v8.cpp
@@ -921,10 +921,8 @@ bool Object::SetAccessor(Handle<String> name, AccessorGetter getter, AccessorSet
QQmlJS::VM::Object *o = ConstValuePtr(this)->asObject();
assert(o);
PropertyAttributes attrs = Attr_Accessor;
- if (attribute & DontDelete)
- attrs |= Attr_NotConfigurable;
- if (attribute & DontEnum)
- attrs |= Attr_NotEnumerable;
+ attrs.setConfigurable(!(attribute & DontDelete));
+ attrs.setEnumberable(!(attribute & DontEnum));
VM::PropertyDescriptor *pd = o->insertMember(name->asVMString(), attrs);
*pd = VM::PropertyDescriptor::fromAccessor(wrappedGetter, wrappedSetter);
pd->writable = VM::PropertyDescriptor::Undefined;
@@ -1430,10 +1428,8 @@ public:
foreach (const ObjectTemplate::Accessor &acc, m_template->m_accessors) {
PropertyAttributes attrs = Attr_Accessor;
- if (acc.attribute & DontDelete)
- attrs |= Attr_NotConfigurable;
- if (acc.attribute & DontEnum)
- attrs |= Attr_NotEnumerable;
+ attrs.setConfigurable(!(acc.attribute & DontDelete));
+ attrs.setEnumberable(!(acc.attribute & DontEnum));
VM::PropertyDescriptor *pd = this->insertMember(acc.name->asVMString(), attrs);
*pd = VM::PropertyDescriptor::fromAccessor(acc.getter->vmValue().asFunctionObject(),
acc.setter->vmValue().asFunctionObject());
@@ -1449,12 +1445,9 @@ public:
{
foreach (const Template::Property &p, tmpl->m_properties) {
PropertyAttributes attrs = Attr_Default;
- if (p.attributes & DontDelete)
- attrs |= Attr_NotConfigurable;
- if (p.attributes & DontEnum)
- attrs |= Attr_NotEnumerable;
- if (p.attributes & ReadOnly)
- attrs |= Attr_NotWritable;
+ attrs.setConfigurable(!(p.attributes & DontDelete));
+ attrs.setEnumberable(!(p.attributes & DontEnum));
+ attrs.setWritable(!(p.attributes & ReadOnly));
VM::PropertyDescriptor *pd = this->insertMember(p.name->asVMString(), attrs);
*pd = VM::PropertyDescriptor::fromValue(p.value->vmValue());
pd->writable = p.attributes & ReadOnly ? VM::PropertyDescriptor::Disabled : VM::PropertyDescriptor::Enabled;
@@ -1558,14 +1551,11 @@ protected:
static PropertyAttributes propertyAttributesToFlags(const Handle<Value> &attr)
{
- PropertyAttributes flags = 0;
+ PropertyAttributes flags;
int intAttr = attr->ToInt32()->Value();
- if (intAttr & ReadOnly)
- flags |= VM::Attr_NotWritable;
- if (intAttr & DontDelete)
- flags |= VM::Attr_NotConfigurable;
- if (intAttr & DontEnum)
- flags |= VM::Attr_NotEnumerable;
+ flags.setWritable(!(intAttr & ReadOnly));
+ flags.setEnumberable(!(intAttr & DontEnum));
+ flags.setConfigurable(!(intAttr & DontDelete));
return flags;
}
@@ -1578,7 +1568,7 @@ protected:
return propertyAttributesToFlags(result);
}
PropertyAttributes flags = BaseClass::query(m, ctx, name);
- if (flags == 0 && that->m_template->m_fallbackPropertySetter) {
+ if (flags.type() == PropertyAttributes::Generic && that->m_template->m_fallbackPropertySetter) {
Handle<Value> result = that->m_template->m_fallbackPropertyQuery(String::New(name), that->fallbackAccessorInfo());
if (!result.IsEmpty())
return propertyAttributesToFlags(result);