diff options
author | Lars Knoll <lars.knoll@qt.io> | 2018-05-14 10:22:02 +0200 |
---|---|---|
committer | Lars Knoll <lars.knoll@qt.io> | 2018-05-14 19:32:24 +0000 |
commit | b9311cc01da09f7f736850f500113f3e576c21a9 (patch) | |
tree | 55f203c12d4f928f6bf731a2c63a9e7d667083f9 /src | |
parent | 1b46ba1e35af5e5d71f71d671906cefcb3b48a19 (diff) |
Fix lookups of indexed properties
These can now happen through destructuring expressions, so add
proper support for those.
Change-Id: I3fdd4e9903ab851a5c4f5c1b64ab4e991ba7d8c1
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/qml/jsruntime/qv4lookup.cpp | 23 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4lookup_p.h | 6 |
2 files changed, 29 insertions, 0 deletions
diff --git a/src/qml/jsruntime/qv4lookup.cpp b/src/qml/jsruntime/qv4lookup.cpp index e4a7c703fc..67b4b9dc38 100644 --- a/src/qml/jsruntime/qv4lookup.cpp +++ b/src/qml/jsruntime/qv4lookup.cpp @@ -71,6 +71,11 @@ ReturnedValue Lookup::resolveGetter(ExecutionEngine *engine, const Object *objec { Heap::Object *obj = object->d(); Identifier name = engine->identifierTable->identifier(engine->currentStackFrame->v4Function->compilationUnit->runtimeStrings[nameIndex]); + if (name.isArrayIndex()) { + indexedLookup.index = name.asArrayIndex(); + getter = getterIndexed; + return getter(this, engine, *object); + } uint index = obj->internalClass->find(name); if (index != UINT_MAX) { @@ -373,6 +378,24 @@ ReturnedValue Lookup::getterProtoAccessorTwoClasses(Lookup *l, ExecutionEngine * return getterFallback(l, engine, object); } +ReturnedValue Lookup::getterIndexed(Lookup *l, ExecutionEngine *engine, const Value &object) +{ + Object *o = object.objectValue(); + if (o) { + Heap::Object *ho = o->d(); + if (ho->arrayData && ho->arrayData->type == Heap::ArrayData::Simple) { + Heap::SimpleArrayData *s = ho->arrayData.cast<Heap::SimpleArrayData>(); + if (l->indexedLookup.index < s->values.size) + if (!s->data(l->indexedLookup.index).isEmpty()) + return s->data(l->indexedLookup.index).asReturnedValue(); + } + return o->getIndexed(l->indexedLookup.index); + } + l->getter = getterFallback; + return getterFallback(l, engine, object); + +} + ReturnedValue Lookup::primitiveGetterProto(Lookup *l, ExecutionEngine *engine, const Value &object) { if (object.type() == l->primitiveLookup.type) { diff --git a/src/qml/jsruntime/qv4lookup_p.h b/src/qml/jsruntime/qv4lookup_p.h index eb6ad067d7..7fb9976135 100644 --- a/src/qml/jsruntime/qv4lookup_p.h +++ b/src/qml/jsruntime/qv4lookup_p.h @@ -111,6 +111,11 @@ struct Lookup { quintptr protoId; int offset; } insertionLookup; + struct { + quintptr _unused; + quintptr _unused2; + uint index; + } indexedLookup; }; uint nameIndex; @@ -133,6 +138,7 @@ struct Lookup { static ReturnedValue getterAccessor(Lookup *l, ExecutionEngine *engine, const Value &object); static ReturnedValue getterProtoAccessor(Lookup *l, ExecutionEngine *engine, const Value &object); static ReturnedValue getterProtoAccessorTwoClasses(Lookup *l, ExecutionEngine *engine, const Value &object); + static ReturnedValue getterIndexed(Lookup *l, ExecutionEngine *engine, const Value &object); static ReturnedValue primitiveGetterProto(Lookup *l, ExecutionEngine *engine, const Value &object); static ReturnedValue primitiveGetterAccessor(Lookup *l, ExecutionEngine *engine, const Value &object); |