From b9311cc01da09f7f736850f500113f3e576c21a9 Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Mon, 14 May 2018 10:22:02 +0200 Subject: 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 --- src/qml/jsruntime/qv4lookup.cpp | 23 +++++++++++++++++++++++ src/qml/jsruntime/qv4lookup_p.h | 6 ++++++ 2 files changed, 29 insertions(+) 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(); + 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); -- cgit v1.2.3