From 6c14ede1dd54f189fc461267e6671cb0f690c629 Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Tue, 9 Apr 2013 09:48:21 +0200 Subject: [PATCH] Make the PropertyAttributes a proper class Change-Id: Ia81236136aedcddaad303187b353cfcf03d792c6 Reviewed-by: Simon Hausmann --- src/v4/qv4global.h | 60 ++++++++++++++++++++++++++++++++++++++++-- src/v4/qv4internalclass.cpp | 2 +- src/v4/qv4propertydescriptor.h | 14 ++++------ src/v4/qv4v8.cpp | 34 +++++++++--------------- 4 files changed, 76 insertions(+), 34 deletions(-) diff --git a/src/v4/qv4global.h b/src/v4/qv4global.h index 43409b2..11a74bb 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 0f4a945..b040aba 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 7bde67b..56f6301 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 56acd11..337a385 100644 --- a/src/v4/qv4v8.cpp +++ b/src/v4/qv4v8.cpp @@ -921,10 +921,8 @@ bool Object::SetAccessor(Handle 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 &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 result = that->m_template->m_fallbackPropertyQuery(String::New(name), that->fallbackAccessorInfo()); if (!result.IsEmpty()) return propertyAttributesToFlags(result); -- 2.7.4