aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@qt.io>2018-08-03 08:33:40 +0200
committerSimon Hausmann <simon.hausmann@qt.io>2018-08-04 09:16:19 +0000
commit78658b94121948c73c9eb81c8375e69aaeaae894 (patch)
tree111a293b7dac1848cc45f068dfe5a0ec1efd204c /src/qml
parentdb780b5e3277af1a9ce1a68bb7b47c6776309806 (diff)
Add support for Object.getOwnPropertyDescriptors
Change-Id: I9f80c583a5c238997b7141e11f4302a9e19c5499 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src/qml')
-rw-r--r--src/qml/jsruntime/qv4objectproto.cpp30
-rw-r--r--src/qml/jsruntime/qv4objectproto_p.h1
2 files changed, 31 insertions, 0 deletions
diff --git a/src/qml/jsruntime/qv4objectproto.cpp b/src/qml/jsruntime/qv4objectproto.cpp
index 53113debb2..8d5eaa74c0 100644
--- a/src/qml/jsruntime/qv4objectproto.cpp
+++ b/src/qml/jsruntime/qv4objectproto.cpp
@@ -98,6 +98,7 @@ void ObjectPrototype::init(ExecutionEngine *v4, Object *ctor)
ctor->defineReadonlyConfigurableProperty(v4->id_length(), Primitive::fromInt32(1));
ctor->defineDefaultProperty(QStringLiteral("getPrototypeOf"), method_getPrototypeOf, 1);
ctor->defineDefaultProperty(QStringLiteral("getOwnPropertyDescriptor"), method_getOwnPropertyDescriptor, 2);
+ ctor->defineDefaultProperty(QStringLiteral("getOwnPropertyDescriptors"), method_getOwnPropertyDescriptors, 1);
ctor->defineDefaultProperty(QStringLiteral("getOwnPropertyNames"), method_getOwnPropertyNames, 1);
ctor->defineDefaultProperty(QStringLiteral("getOwnPropertySymbols"), method_getOwnPropertySymbols, 1);
ctor->defineDefaultProperty(QStringLiteral("assign"), method_assign, 2);
@@ -174,6 +175,35 @@ ReturnedValue ObjectPrototype::method_getOwnPropertyDescriptor(const FunctionObj
return fromPropertyDescriptor(scope.engine, desc, attrs);
}
+ReturnedValue ObjectPrototype::method_getOwnPropertyDescriptors(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 Encode::undefined();
+
+ ScopedObject descriptors(scope, scope.engine->newObject());
+
+ ObjectIterator it(scope, o, ObjectIterator::NoFlags);
+ ScopedProperty pd(scope);
+ PropertyAttributes attrs;
+ ScopedPropertyKey key(scope);
+ ScopedObject entry(scope);
+ while (1) {
+ key = it.next(pd, &attrs);
+ if (!key->isValid())
+ break;
+ entry = fromPropertyDescriptor(scope.engine, pd, attrs);
+ descriptors->put(key, entry);
+ }
+
+ return descriptors.asReturnedValue();
+
+}
+
ReturnedValue ObjectPrototype::method_getOwnPropertyNames(const FunctionObject *b, const Value *, const Value *argv, int argc)
{
Scope scope(b);
diff --git a/src/qml/jsruntime/qv4objectproto_p.h b/src/qml/jsruntime/qv4objectproto_p.h
index 51f0e32a2c..5a225239ab 100644
--- a/src/qml/jsruntime/qv4objectproto_p.h
+++ b/src/qml/jsruntime/qv4objectproto_p.h
@@ -85,6 +85,7 @@ struct ObjectPrototype: Object
static ReturnedValue method_entries(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
static ReturnedValue method_freeze(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
static ReturnedValue method_getOwnPropertyDescriptor(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
+ static ReturnedValue method_getOwnPropertyDescriptors(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
static ReturnedValue method_getOwnPropertyNames(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
static ReturnedValue method_getOwnPropertySymbols(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
static ReturnedValue method_getPrototypeOf(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);