diff options
author | Lars Knoll <lars.knoll@theqtcompany.com> | 2015-08-26 09:49:27 +0200 |
---|---|---|
committer | Lars Knoll <lars.knoll@theqtcompany.com> | 2015-09-15 19:13:20 +0000 |
commit | b58c33da59bbcf3782ca3d21b68bf2593c7f8d7a (patch) | |
tree | 1a270c10897777de29f305bdd421bb728492b3d1 /src/qml/jsruntime | |
parent | 15cd948bdaed4f2e64fa879106e7237d958695b0 (diff) |
Get rid of propertyAt in Object
Change-Id: I3022b3c5c1ae90530ef5ca88e0b88a2fd1102e73
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
Diffstat (limited to 'src/qml/jsruntime')
-rw-r--r-- | src/qml/jsruntime/qv4arraydata_p.h | 21 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4object.cpp | 43 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4object_p.h | 6 |
3 files changed, 53 insertions, 17 deletions
diff --git a/src/qml/jsruntime/qv4arraydata_p.h b/src/qml/jsruntime/qv4arraydata_p.h index 1de69a90e4..cca5bf7f20 100644 --- a/src/qml/jsruntime/qv4arraydata_p.h +++ b/src/qml/jsruntime/qv4arraydata_p.h @@ -101,6 +101,8 @@ struct ArrayData : public Base { inline ReturnedValue get(uint i) const { return vtable()->get(this, i); } + inline void getProperty(uint index, Property *p, PropertyAttributes *attrs); + inline void setProperty(uint index, const Property *p); inline Property *getProperty(uint index); inline Value *getValueOrSetter(uint index, PropertyAttributes *attrs); inline PropertyAttributes attributes(uint i) const; @@ -271,6 +273,25 @@ inline SparseArrayData::~SparseArrayData() delete sparse; } +void ArrayData::getProperty(uint index, Property *p, PropertyAttributes *attrs) +{ + Property *pd = getProperty(index); + Q_ASSERT(pd); + *attrs = attributes(index); + p->value = pd->value; + if (attrs->isAccessor()) + p->set = pd->set; +} + +void ArrayData::setProperty(uint index, const Property *p) +{ + Property *pd = getProperty(index); + Q_ASSERT(pd); + pd->value = p->value; + if (attributes(index).isAccessor()) + pd->set = p->set; +} + inline Property *ArrayData::getProperty(uint index) { if (isSparse()) diff --git a/src/qml/jsruntime/qv4object.cpp b/src/qml/jsruntime/qv4object.cpp index 754dc597a6..5f96e0d758 100644 --- a/src/qml/jsruntime/qv4object.cpp +++ b/src/qml/jsruntime/qv4object.cpp @@ -67,6 +67,21 @@ void Object::setInternalClass(InternalClass *ic) ensureMemberData(); } +void Object::getProperty(uint index, Property *p, PropertyAttributes *attrs) const +{ + p->value = *propertyData(index); + *attrs = internalClass()->propertyData.at(index); + if (attrs->isAccessor()) + p->set = *propertyData(index + SetterOffset); +} + +void Object::setProperty(uint index, const Property *p) +{ + *propertyData(index) = p->value; + if (internalClass()->propertyData.at(index).isAccessor()) + *propertyData(index + SetterOffset) = p->set; +} + bool Object::setPrototype(Object *proto) { Heap::Object *pp = proto ? proto->d() : 0; @@ -859,16 +874,16 @@ bool Object::__defineOwnProperty__(ExecutionEngine *engine, String *name, const Scope scope(engine); name->makeIdentifier(scope.engine); - PropertyAttributes *cattrs; uint memberIndex; if (isArrayObject() && name->equals(engine->id_length())) { Q_ASSERT(Heap::ArrayObject::LengthPropertyIndex == internalClass()->find(engine->id_length())); - Property *lp = propertyAt(Heap::ArrayObject::LengthPropertyIndex); - cattrs = internalClass()->propertyData.constData() + Heap::ArrayObject::LengthPropertyIndex; - if (attrs.isEmpty() || p->isSubset(attrs, lp, *cattrs)) + ScopedProperty lp(scope); + PropertyAttributes cattrs; + getProperty(Heap::ArrayObject::LengthPropertyIndex, lp, &cattrs); + if (attrs.isEmpty() || p->isSubset(attrs, lp, cattrs)) return true; - if (!cattrs->isWritable() || attrs.type() == PropertyAttributes::Accessor || attrs.isConfigurable() || attrs.isEnumerable()) + if (!cattrs.isWritable() || attrs.type() == PropertyAttributes::Accessor || attrs.isConfigurable() || attrs.isEnumerable()) goto reject; bool succeeded = true; if (attrs.type() == PropertyAttributes::Data) { @@ -881,8 +896,10 @@ bool Object::__defineOwnProperty__(ExecutionEngine *engine, String *name, const } succeeded = setArrayLength(l); } - if (attrs.hasWritable() && !attrs.isWritable()) - cattrs->setWritable(false); + if (attrs.hasWritable() && !attrs.isWritable()) { + cattrs.setWritable(false); + InternalClass::changeMember(this, engine->id_length(), cattrs); + } if (!succeeded) goto reject; return true; @@ -890,7 +907,6 @@ bool Object::__defineOwnProperty__(ExecutionEngine *engine, String *name, const // Clause 1 memberIndex = internalClass()->find(name); - cattrs = internalClass()->propertyData.constData() + memberIndex; if (memberIndex == UINT_MAX) { // clause 3 @@ -969,13 +985,14 @@ bool Object::__defineOwnProperty__(ExecutionEngine *engine, uint index, String * if (attrs.isEmpty()) return true; - Property *current = 0; + Scope scope(engine); + ScopedProperty current(scope); PropertyAttributes cattrs; if (member) { - current = propertyAt(index); + getProperty(index, current, &cattrs); cattrs = internalClass()->propertyData[index]; } else if (arrayData()) { - current = arrayData()->getProperty(index); + arrayData()->getProperty(index, current, &cattrs); cattrs = arrayData()->attributes(index); } @@ -1009,7 +1026,6 @@ bool Object::__defineOwnProperty__(ExecutionEngine *engine, uint index, String * initSparseArray(); Q_ASSERT(arrayData()); setArrayAttributes(index, cattrs); - current = arrayData()->getProperty(index); } current->setGetter(0); current->setSetter(0); @@ -1020,7 +1036,6 @@ bool Object::__defineOwnProperty__(ExecutionEngine *engine, uint index, String * if (!member) { // need to convert the array and the slot setArrayAttributes(index, cattrs); - current = arrayData()->getProperty(index); } current->value = Primitive::undefinedValue(); } @@ -1044,8 +1059,10 @@ bool Object::__defineOwnProperty__(ExecutionEngine *engine, uint index, String * current->merge(cattrs, p, attrs); if (member) { InternalClass::changeMember(this, member, cattrs); + setProperty(index, current); } else { setArrayAttributes(index, cattrs); + arrayData()->setProperty(index, current); } return true; reject: diff --git a/src/qml/jsruntime/qv4object_p.h b/src/qml/jsruntime/qv4object_p.h index 6d8f6234fc..943325ef03 100644 --- a/src/qml/jsruntime/qv4object_p.h +++ b/src/qml/jsruntime/qv4object_p.h @@ -52,8 +52,6 @@ struct Object : Base { const Value *propertyData(uint index) const { return memberData->data + index; } Value *propertyData(uint index) { return memberData->data + index; } - const Property *propertyAt(uint index) const { return reinterpret_cast<const Property *>(propertyData(index)); } - Property *propertyAt(uint index) { return reinterpret_cast<Property *>(propertyData(index)); } InternalClass *internalClass; Pointer<Object> prototype; @@ -142,8 +140,8 @@ struct Q_QML_EXPORT Object: Managed { Heap::ArrayData *arrayData() const { return d()->arrayData; } void setArrayData(ArrayData *a) { d()->arrayData = a->d(); } - const Property *propertyAt(uint index) const { return d()->propertyAt(index); } - Property *propertyAt(uint index) { return d()->propertyAt(index); } + void getProperty(uint index, Property *p, PropertyAttributes *attrs) const; + void setProperty(uint index, const Property *p); const ObjectVTable *vtable() const { return reinterpret_cast<const ObjectVTable *>(d()->vtable()); } Heap::Object *prototype() const { return d()->prototype; } |