diff options
author | Lars Knoll <lars.knoll@qt.io> | 2018-09-09 21:57:43 +0200 |
---|---|---|
committer | Lars Knoll <lars.knoll@qt.io> | 2018-09-10 06:37:42 +0000 |
commit | 0b157e9ab3b2b6282e567e656b5f6b8c713a9ac3 (patch) | |
tree | 31f3972c7ee2cedd3fad7e71855023dea8c088b4 /src/qml | |
parent | ccd9bd94147dbacbaae3dba4c6fb9425877faaee (diff) |
Implement OwnPropertyKeys for TypedArray
Change-Id: I85d6cfa4b4652863cfafad4810176d99dccdabc9
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src/qml')
-rw-r--r-- | src/qml/jsruntime/qv4typedarray.cpp | 32 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4typedarray_p.h | 1 |
2 files changed, 33 insertions, 0 deletions
diff --git a/src/qml/jsruntime/qv4typedarray.cpp b/src/qml/jsruntime/qv4typedarray.cpp index a07443077e..a4d32ec06b 100644 --- a/src/qml/jsruntime/qv4typedarray.cpp +++ b/src/qml/jsruntime/qv4typedarray.cpp @@ -576,6 +576,38 @@ bool TypedArray::virtualDefineOwnProperty(Managed *m, PropertyKey id, const Prop return true; } +struct TypedArrayOwnPropertyKeyIterator : ObjectOwnPropertyKeyIterator +{ + ~TypedArrayOwnPropertyKeyIterator() override = default; + PropertyKey next(const Object *o, Property *pd = nullptr, PropertyAttributes *attrs = nullptr) override; + +}; + +PropertyKey TypedArrayOwnPropertyKeyIterator::next(const Object *o, Property *pd, PropertyAttributes *attrs) +{ + const TypedArray *a = static_cast<const TypedArray *>(o); + if (arrayIndex < a->length()) { + if (attrs) + *attrs = Attr_NotConfigurable; + PropertyKey id = PropertyKey::fromArrayIndex(arrayIndex); + if (pd) { + bool hasProperty = false; + pd->value = TypedArray::virtualGet(a, id, a, &hasProperty); + } + ++arrayIndex; + return id; + } + + arrayIndex = UINT_MAX; + return ObjectOwnPropertyKeyIterator::next(o, pd, attrs); +} + +OwnPropertyKeyIterator *TypedArray::virtualOwnPropertyKeys(const Object *m, Value *target) +{ + *target = *m; + return new TypedArrayOwnPropertyKeyIterator(); +} + void TypedArrayPrototype::init(ExecutionEngine *engine, TypedArrayCtor *ctor) { Scope scope(engine); diff --git a/src/qml/jsruntime/qv4typedarray_p.h b/src/qml/jsruntime/qv4typedarray_p.h index ad0953ed0c..dd89faa34d 100644 --- a/src/qml/jsruntime/qv4typedarray_p.h +++ b/src/qml/jsruntime/qv4typedarray_p.h @@ -170,6 +170,7 @@ struct Q_QML_PRIVATE_EXPORT TypedArray : Object static PropertyAttributes virtualGetOwnProperty(Managed *m, PropertyKey id, Property *p); static bool virtualPut(Managed *m, PropertyKey id, const Value &value, Value *receiver); static bool virtualDefineOwnProperty(Managed *m, PropertyKey id, const Property *p, PropertyAttributes attrs); + static OwnPropertyKeyIterator *virtualOwnPropertyKeys(const Object *m, Value *target); }; |