From 18376523d495597bbe009cf20d783816c9f3a44a Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Fri, 3 Aug 2018 08:54:14 +0200 Subject: Implement support for Object.values Change-Id: I1f2507afb1c6f148d129325088a7db9d9b6fc98e Reviewed-by: Simon Hausmann --- src/qml/jsruntime/qv4objectproto.cpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'src/qml/jsruntime/qv4objectproto.cpp') 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(); -- cgit v1.2.3