aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/jsruntime/qv4objectproto.cpp
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@qt.io>2018-08-03 08:54:14 +0200
committerSimon Hausmann <simon.hausmann@qt.io>2018-08-04 09:16:27 +0000
commit18376523d495597bbe009cf20d783816c9f3a44a (patch)
treea6369754a2eea309999e581a2d4217a6248207c6 /src/qml/jsruntime/qv4objectproto.cpp
parent78658b94121948c73c9eb81c8375e69aaeaae894 (diff)
Implement support for Object.values
Change-Id: I1f2507afb1c6f148d129325088a7db9d9b6fc98e Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src/qml/jsruntime/qv4objectproto.cpp')
-rw-r--r--src/qml/jsruntime/qv4objectproto.cpp29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/qml/jsruntime/qv4objectproto.cpp b/src/qml/jsruntime/qv4objectproto.cpp
index 8d5eaa74c0..ed810cb456 100644
--- a/src/qml/jsruntime/qv4objectproto.cpp
+++ b/src/qml/jsruntime/qv4objectproto.cpp
@@ -115,6 +115,7 @@ void ObjectPrototype::init(ExecutionEngine *v4, Object *ctor)
ctor->defineDefaultProperty(QStringLiteral("isExtensible"), method_isExtensible, 1);
ctor->defineDefaultProperty(QStringLiteral("keys"), method_keys, 1);
ctor->defineDefaultProperty(QStringLiteral("setPrototypeOf"), method_setPrototypeOf, 2);
+ ctor->defineDefaultProperty(QStringLiteral("values"), method_values, 1);
defineDefaultProperty(QStringLiteral("constructor"), (o = ctor));
defineDefaultProperty(v4->id_toString(), method_toString, 0);
@@ -589,6 +590,34 @@ ReturnedValue ObjectPrototype::method_setPrototypeOf(const FunctionObject *f, co
return o->asReturnedValue();
}
+ReturnedValue ObjectPrototype::method_values(const FunctionObject *f, const Value *, const Value *argv, int argc)
+{
+ Scope scope(f);
+ if (!argc)
+ return scope.engine->throwTypeError();
+
+ ScopedObject o(scope, argv[0].toObject(scope.engine));
+ if (scope.engine->hasException)
+ return QV4::Encode::undefined();
+
+ ScopedArrayObject a(scope, scope.engine->newArrayObject());
+
+ ObjectIterator it(scope, o, ObjectIterator::EnumerableOnly);
+ ScopedPropertyKey key(scope);
+ ScopedProperty pd(scope);
+ ScopedValue value(scope);
+ PropertyAttributes attrs;
+ while (1) {
+ key = it.next(pd, &attrs);
+ if (!key->isValid())
+ break;
+ value = o->getValue(pd->value, attrs);
+ a->push_back(value);
+ }
+
+ return a.asReturnedValue();
+}
+
ReturnedValue ObjectPrototype::method_toString(const FunctionObject *b, const Value *thisObject, const Value *, int)
{
ExecutionEngine *v4 = b->engine();