diff options
author | Lars Knoll <lars.knoll@qt.io> | 2018-09-08 11:40:44 +0200 |
---|---|---|
committer | Lars Knoll <lars.knoll@qt.io> | 2018-09-08 16:51:08 +0000 |
commit | f726c56ce8ca5cfae510d8b81b44ad816f6ad245 (patch) | |
tree | 199fe17be19bbbee1762512525db1da9e8e83cec /src/qml/jsruntime/qv4object.cpp | |
parent | 6e36fdb2f65ede9c84d2e822f1a69d31a756bc49 (diff) |
Fix spec compliance of Object::virtualGet()
Change-Id: I9c07a6b08e9029b893c28e7a945f839c0f0dda8d
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src/qml/jsruntime/qv4object.cpp')
-rw-r--r-- | src/qml/jsruntime/qv4object.cpp | 67 |
1 files changed, 25 insertions, 42 deletions
diff --git a/src/qml/jsruntime/qv4object.cpp b/src/qml/jsruntime/qv4object.cpp index 17cc058c39..3c98e6eb35 100644 --- a/src/qml/jsruntime/qv4object.cpp +++ b/src/qml/jsruntime/qv4object.cpp @@ -310,11 +310,7 @@ PropertyIndex Object::getValueOrSetter(PropertyKey id, PropertyAttributes *attrs ReturnedValue Object::virtualGet(const Managed *m, PropertyKey id, const Value *receiver, bool *hasProperty) { - if (id.isArrayIndex()) - return static_cast<const Object *>(m)->internalGetIndexed(id.asArrayIndex(), receiver, hasProperty); - Scope scope(m); - Scoped<StringOrSymbol> name(scope, id.asStringOrSymbol()); - return static_cast<const Object *>(m)->internalGet(name, receiver, hasProperty); + return static_cast<const Object *>(m)->internalGet(id, receiver, hasProperty); } bool Object::virtualPut(Managed *m, PropertyKey id, const Value &value, Value *receiver) @@ -400,40 +396,18 @@ OwnPropertyKeyIterator *Object::virtualOwnPropertyKeys(const Object *) } // Section 8.12.3 -ReturnedValue Object::internalGet(StringOrSymbol *name, const Value *receiver, bool *hasProperty) const +ReturnedValue Object::internalGet(PropertyKey id, const Value *receiver, bool *hasProperty) const { - PropertyKey id = name->toPropertyKey(); - - Q_ASSERT(!id.isArrayIndex()); - - Heap::Object *o = d(); - while (o) { - uint idx = o->internalClass->find(id); - if (idx < UINT_MAX) { + uint index = id.asArrayIndex(); + if (index != UINT_MAX) { + Scope scope(this); + PropertyAttributes attrs; + ScopedObject o(scope, this); + ScopedProperty pd(scope); + if (o->arrayData() && o->arrayData()->getProperty(index, pd, &attrs)) { if (hasProperty) *hasProperty = true; - return Object::getValue(*receiver, *o->propertyData(idx), o->internalClass->propertyData.at(idx)); - } - - o = o->prototype(); - } - - if (hasProperty) - *hasProperty = false; - return Encode::undefined(); -} - -ReturnedValue Object::internalGetIndexed(uint index, const Value *receiver, bool *hasProperty) const -{ - PropertyAttributes attrs; - Scope scope(engine()); - ScopedObject o(scope, this); - ScopedProperty pd(scope); - bool exists = false; - while (o) { - if (o->arrayData() && o->arrayData()->getProperty(index, pd, &attrs)) { - exists = true; - break; + return Object::getValue(*receiver, pd->value, attrs); } if (o->isStringObject()) { ScopedString str(scope, static_cast<StringObject *>(o.getPointer())->getIndex(index)); @@ -444,13 +418,23 @@ ReturnedValue Object::internalGetIndexed(uint index, const Value *receiver, bool return str.asReturnedValue(); } } - o = o->getPrototypeOf(); + } else { + Heap::Object *o = d(); + Q_ASSERT(!id.isArrayIndex()); + + uint idx = o->internalClass->find(id); + if (idx < UINT_MAX) { + if (hasProperty) + *hasProperty = true; + return Object::getValue(*receiver, *o->propertyData(idx), o->internalClass->propertyData.at(idx)); + } } - if (exists) { - if (hasProperty) - *hasProperty = true; - return Object::getValue(*receiver, pd->value, attrs); + Heap::Object *p = d()->prototype(); + if (p) { + const Value v = Primitive::fromHeapObject(p); + const Object &obj = static_cast<const Object &>(v); + return obj.get(id, receiver, hasProperty); } if (hasProperty) @@ -458,7 +442,6 @@ ReturnedValue Object::internalGetIndexed(uint index, const Value *receiver, bool return Encode::undefined(); } - // Section 8.12.5 bool Object::internalPut(PropertyKey id, const Value &value, Value *receiver) { |