aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@qt.io>2018-09-08 23:07:31 +0200
committerLars Knoll <lars.knoll@qt.io>2018-09-09 15:52:10 +0000
commitbcc9aa7daf197e8f2befe215902443d608e07b6a (patch)
tree89d077b637c683e5b8add795e0b8ba2089dc4a3d
parent166fc4d84729fee683a9ea6b2c27cf51dc5f1c9d (diff)
Include symbols in getOwnPropertyKeys
And fix getOwnPropertySymbols and getOwnPropertyDescriptors. Change-Id: Ie0e4c3d308ffe8a904e9a6ab9242b2cda59d779f Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
-rw-r--r--src/qml/jsruntime/qv4object.cpp48
-rw-r--r--src/qml/jsruntime/qv4object_p.h1
-rw-r--r--src/qml/jsruntime/qv4objectiterator.cpp3
-rw-r--r--src/qml/jsruntime/qv4objectiterator_p.h3
-rw-r--r--src/qml/jsruntime/qv4objectproto.cpp24
-rw-r--r--tests/auto/qml/ecmascripttests/TestExpectations2
6 files changed, 51 insertions, 30 deletions
diff --git a/src/qml/jsruntime/qv4object.cpp b/src/qml/jsruntime/qv4object.cpp
index 267726d22f..cd9ea66297 100644
--- a/src/qml/jsruntime/qv4object.cpp
+++ b/src/qml/jsruntime/qv4object.cpp
@@ -366,25 +366,39 @@ PropertyKey ObjectOwnPropertyKeyIterator::next(const Object *o, Property *pd, Pr
arrayIndex = UINT_MAX;
}
- while (memberIndex < o->internalClass()->size) {
- PropertyKey n = o->internalClass()->nameMap.at(memberIndex);
- if (!n.isStringOrSymbol()) {
- // accessor properties have a dummy entry with n == 0
- ++memberIndex;
- continue;
- }
+ while (true) {
+ while (memberIndex < o->internalClass()->size) {
+ PropertyKey n = o->internalClass()->nameMap.at(memberIndex);
+ if (!n.isStringOrSymbol()) {
+ // accessor properties have a dummy entry with n == 0
+ ++memberIndex;
+ continue;
+ }
+ if (!iterateOverSymbols && n.isSymbol()) {
+ ++memberIndex;
+ continue;
+ }
+ if (iterateOverSymbols && !n.isSymbol()) {
+ ++memberIndex;
+ continue;
+ }
- uint index = memberIndex;
- PropertyAttributes a = o->internalClass()->propertyData[memberIndex];
- ++memberIndex;
- if (pd) {
- pd->value = *o->propertyData(index);
- if (a.isAccessor())
- pd->set = *o->propertyData(index + Object::SetterOffset);
+ uint index = memberIndex;
+ PropertyAttributes a = o->internalClass()->propertyData[memberIndex];
+ ++memberIndex;
+ if (pd) {
+ pd->value = *o->propertyData(index);
+ if (a.isAccessor())
+ pd->set = *o->propertyData(index + Object::SetterOffset);
+ }
+ if (attrs)
+ *attrs = a;
+ return n;
}
- if (attrs)
- *attrs = a;
- return n;
+ if (iterateOverSymbols)
+ break;
+ iterateOverSymbols = true;
+ memberIndex = 0;
}
return PropertyKey::invalid();
diff --git a/src/qml/jsruntime/qv4object_p.h b/src/qml/jsruntime/qv4object_p.h
index 0a27993004..41484660ab 100644
--- a/src/qml/jsruntime/qv4object_p.h
+++ b/src/qml/jsruntime/qv4object_p.h
@@ -392,6 +392,7 @@ struct ObjectOwnPropertyKeyIterator : OwnPropertyKeyIterator
{
uint arrayIndex = 0;
uint memberIndex = 0;
+ bool iterateOverSymbols = false;
SparseArrayNode *arrayNode = nullptr;
~ObjectOwnPropertyKeyIterator() override = default;
PropertyKey next(const Object *o, Property *pd = nullptr, PropertyAttributes *attrs = nullptr) override;
diff --git a/src/qml/jsruntime/qv4objectiterator.cpp b/src/qml/jsruntime/qv4objectiterator.cpp
index 906f6b38a6..e529b8e86b 100644
--- a/src/qml/jsruntime/qv4objectiterator.cpp
+++ b/src/qml/jsruntime/qv4objectiterator.cpp
@@ -66,7 +66,8 @@ PropertyKey ObjectIterator::next(Property *pd, PropertyAttributes *attrs)
object = nullptr;
return key;
}
- if (key->isSymbol() || ((flags & EnumerableOnly) && !attrs->isEnumerable()))
+ if ((!(flags & WithSymbols) && key->isSymbol()) ||
+ ((flags & EnumerableOnly) && !attrs->isEnumerable()))
continue;
return key;
}
diff --git a/src/qml/jsruntime/qv4objectiterator_p.h b/src/qml/jsruntime/qv4objectiterator_p.h
index 0a5bcfc7ed..a20ce9cb88 100644
--- a/src/qml/jsruntime/qv4objectiterator_p.h
+++ b/src/qml/jsruntime/qv4objectiterator_p.h
@@ -61,7 +61,8 @@ struct Q_QML_EXPORT ObjectIterator
{
enum Flags {
NoFlags = 0,
- EnumerableOnly = 0x1
+ EnumerableOnly = 0x1,
+ WithSymbols = 0x2
};
ExecutionEngine *engine;
diff --git a/src/qml/jsruntime/qv4objectproto.cpp b/src/qml/jsruntime/qv4objectproto.cpp
index 926d246373..a4f960a3b6 100644
--- a/src/qml/jsruntime/qv4objectproto.cpp
+++ b/src/qml/jsruntime/qv4objectproto.cpp
@@ -188,7 +188,7 @@ ReturnedValue ObjectPrototype::method_getOwnPropertyDescriptors(const FunctionOb
ScopedObject descriptors(scope, scope.engine->newObject());
- ObjectIterator it(scope, o, ObjectIterator::NoFlags);
+ ObjectIterator it(scope, o, ObjectIterator::WithSymbols);
ScopedProperty pd(scope);
PropertyAttributes attrs;
ScopedPropertyKey key(scope);
@@ -227,15 +227,19 @@ ReturnedValue ObjectPrototype::method_getOwnPropertySymbols(const FunctionObject
ScopedObject O(scope, argv[0].toObject(scope.engine));
if (!O)
return Encode::undefined();
- Heap::InternalClass *ic = O->d()->internalClass;
- ScopedValue n(scope);
+
ScopedArrayObject array(scope, scope.engine->newArrayObject());
- for (uint i = 0; i < ic->size; ++i) {
- PropertyKey id = ic->nameMap.at(i);
- n = id.asStringOrSymbol();
- if (!n || !n->isSymbol())
- continue;
- array->push_back(n);
+ if (O) {
+ ObjectIterator it(scope, O, ObjectIterator::WithSymbols);
+ ScopedValue name(scope);
+ while (1) {
+ name = it.nextPropertyNameAsString();
+ if (name->isNull())
+ break;
+ if (!name->isSymbol())
+ continue;
+ array->push_back(name);
+ }
}
return array->asReturnedValue();
}
@@ -916,6 +920,8 @@ Heap::ArrayObject *ObjectPrototype::getOwnPropertyNames(ExecutionEngine *v4, con
name = it.nextPropertyNameAsString();
if (name->isNull())
break;
+ if (name->isSymbol())
+ continue;
array->push_back(name);
}
}
diff --git a/tests/auto/qml/ecmascripttests/TestExpectations b/tests/auto/qml/ecmascripttests/TestExpectations
index 2be466fdf4..c164691d2b 100644
--- a/tests/auto/qml/ecmascripttests/TestExpectations
+++ b/tests/auto/qml/ecmascripttests/TestExpectations
@@ -170,7 +170,6 @@ built-ins/Object/entries/getter-making-future-key-nonenumerable.js fails
built-ins/Object/entries/getter-removing-future-key.js fails
built-ins/Object/entries/observable-operations.js fails
built-ins/Object/getOwnPropertyDescriptors/proxy-undefined-descriptor.js fails
-built-ins/Object/getOwnPropertyDescriptors/symbols-included.js fails
built-ins/Object/keys/proxy-keys.js fails
built-ins/Object/proto-from-ctor.js fails
built-ins/Object/prototype/toLocaleString/primitive_this_value_getter.js strictFails
@@ -330,7 +329,6 @@ built-ins/Promise/resolve/prop-desc.js fails
built-ins/Promise/resolve/resolve-from-promise-capability.js fails
built-ins/Promise/resolve/resolve-prms-cstm-then.js fails
built-ins/Proxy/has/call-object-create.js fails
-built-ins/Proxy/ownKeys/call-parameters-object-getownpropertysymbols.js fails
built-ins/Proxy/ownKeys/return-duplicate-entries-throws.js fails
built-ins/Proxy/ownKeys/return-duplicate-symbol-entries-throws.js fails
built-ins/RegExp/S15.10.2.12_A2_T1.js fails