diff options
author | Lars Knoll <lars.knoll@qt.io> | 2018-08-02 15:44:12 +0200 |
---|---|---|
committer | Lars Knoll <lars.knoll@qt.io> | 2018-08-02 20:25:41 +0000 |
commit | 0754f55287f4652382332bce42cd8c7d27846ef1 (patch) | |
tree | 490bbd3c5d66586a1427ba21dde76b2af65230dc /src/qml/jsruntime/qv4objectiterator_p.h | |
parent | 57640959320c87850315eae44c783803d113dc85 (diff) |
Introduce a new mechanism to iterate over object properties
The old advanceIterator schema was extremely ugly and in addition
not flexible enough to support the requirements for Proxy.ownKeys
and some of the methods in Object
Implemented a new scheme through a OwnPropertyKeys method in the
Object VTable that creates and returns an iterator object. Ported
QJSValueIterator and for-in to use the new mechanism.
There's still many places where we use the old ObjectIterator (that
relies on advanceIterator). Those will be ported in subsequent
commits.
Change-Id: I091a9bea9ff6b2b63630cc336814700757a718be
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src/qml/jsruntime/qv4objectiterator_p.h')
-rw-r--r-- | src/qml/jsruntime/qv4objectiterator_p.h | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/src/qml/jsruntime/qv4objectiterator_p.h b/src/qml/jsruntime/qv4objectiterator_p.h index 1e7000ad1f..20eb918e12 100644 --- a/src/qml/jsruntime/qv4objectiterator_p.h +++ b/src/qml/jsruntime/qv4objectiterator_p.h @@ -111,14 +111,18 @@ private: }; namespace Heap { -struct ForInIteratorObject : Object { + +#define ForInIteratorObjectMembers(class, Member) \ + Member(class, Pointer, Object *, object) \ + Member(class, Pointer, Object *, current) \ + Member(class, NoMark, OwnPropertyKeyIterator *, iterator) + +DECLARE_HEAP_OBJECT(ForInIteratorObject, Object) { void init(QV4::Object *o); - ObjectIterator &it() { return *reinterpret_cast<ObjectIterator*>(&itData); } Value workArea[2]; static void markObjects(Heap::Base *that, MarkStack *markStack); -private: - ObjectIteratorData itData; + void destroy(); }; } @@ -135,16 +139,20 @@ struct ForInIteratorObject: Object { V4_OBJECT2(ForInIteratorObject, Object) Q_MANAGED_TYPE(ForInIterator) V4_PROTOTYPE(forInIteratorPrototype) + V4_NEEDS_DESTROY - ReturnedValue nextPropertyName() const { return d()->it().nextPropertyNameAsString(); } + PropertyKey nextProperty() const; }; inline void Heap::ForInIteratorObject::init(QV4::Object *o) { Object::init(); - it() = ObjectIterator(internalClass->engine, workArea, workArea + 1, o, - ObjectIterator::EnumerableOnly | ObjectIterator::WithProtoChain); + if (!o) + return; + object.set(o->engine(), o->d()); + current.set(o->engine(), o->d()); + iterator = o->ownPropertyKeys(); } |