aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/qml/v8
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@theqtcompany.com>2016-05-18 15:17:37 +0200
committerSimon Hausmann <simon.hausmann@theqtcompany.com>2016-05-18 15:17:37 +0200
commit5861dc4869e2bb313a0ea20d39b3c7a198664acf (patch)
tree24538a98ddd31e11dce2bc25b7744c59a8792fed /src/qml/qml/v8
parent709f6370884b110def2e4665df8fa7bbf5fae734 (diff)
parentb9e4a4df577959579b2322fb6077bde82d9ffce3 (diff)
Merge remote-tracking branch 'origin/5.7' into dev
Conflicts: src/qml/qml/v8/qqmlbuiltinfunctions_p.h tests/auto/qml/qqmlqt/tst_qqmlqt.cpp Change-Id: I9dd93732f4b19513576ca1dd89ae18c69de0203b
Diffstat (limited to 'src/qml/qml/v8')
-rw-r--r--src/qml/qml/v8/qqmlbuiltinfunctions.cpp82
-rw-r--r--src/qml/qml/v8/qqmlbuiltinfunctions_p.h14
2 files changed, 85 insertions, 11 deletions
diff --git a/src/qml/qml/v8/qqmlbuiltinfunctions.cpp b/src/qml/qml/v8/qqmlbuiltinfunctions.cpp
index d4ffd2747d..1f42cbf983 100644
--- a/src/qml/qml/v8/qqmlbuiltinfunctions.cpp
+++ b/src/qml/qml/v8/qqmlbuiltinfunctions.cpp
@@ -88,22 +88,18 @@ struct StaticQtMetaObject : public QObject
};
Heap::QtObject::QtObject(QQmlEngine *qmlEngine)
+ : enumeratorIterator(0)
+ , keyIterator(0)
{
Scope scope(internalClass->engine);
ScopedObject o(scope, this);
- // Set all the enums from the "Qt" namespace
- const QMetaObject *qtMetaObject = StaticQtMetaObject::get();
- ScopedString str(scope);
- ScopedValue v(scope);
- for (int ii = 0, eii = qtMetaObject->enumeratorCount(); ii < eii; ++ii) {
- QMetaEnum enumerator = qtMetaObject->enumerator(ii);
- for (int jj = 0, ejj = enumerator.keyCount(); jj < ejj; ++jj) {
- o->put((str = scope.engine->newString(QString::fromUtf8(enumerator.key(jj)))), (v = QV4::Primitive::fromInt32(enumerator.value(jj))));
- }
+ {
+ ScopedString str(scope);
+ ScopedValue v(scope);
+ o->put((str = scope.engine->newString(QStringLiteral("Asynchronous"))), (v = QV4::Primitive::fromInt32(0)));
+ o->put((str = scope.engine->newString(QStringLiteral("Synchronous"))), (v = QV4::Primitive::fromInt32(1)));
}
- o->put((str = scope.engine->newString(QStringLiteral("Asynchronous"))), (v = QV4::Primitive::fromInt32(0)));
- o->put((str = scope.engine->newString(QStringLiteral("Synchronous"))), (v = QV4::Primitive::fromInt32(1)));
o->defineDefaultProperty(QStringLiteral("include"), QV4Include::method_include);
o->defineDefaultProperty(QStringLiteral("isQtObject"), QV4::QtObject::method_isQtObject);
@@ -154,6 +150,70 @@ Heap::QtObject::QtObject(QQmlEngine *qmlEngine)
o->defineDefaultProperty(QStringLiteral("callLater"), QV4::QtObject::method_callLater);
}
+void QtObject::addAll()
+{
+ bool dummy = false;
+ findAndAdd(nullptr, dummy);
+}
+
+ReturnedValue QtObject::findAndAdd(const QString *name, bool &foundProperty) const
+{
+ Scope scope(engine());
+ ScopedObject o(scope, this);
+ ScopedString key(scope);
+ ScopedValue value(scope);
+
+ const QMetaObject *qtMetaObject = StaticQtMetaObject::get();
+ for (int enumCount = qtMetaObject->enumeratorCount(); d()->enumeratorIterator < enumCount;
+ ++d()->enumeratorIterator) {
+ QMetaEnum enumerator = qtMetaObject->enumerator(d()->enumeratorIterator);
+ for (int keyCount = enumerator.keyCount(); d()->keyIterator < keyCount; ++d()->keyIterator) {
+ key = scope.engine->newString(QString::fromUtf8(enumerator.key(d()->keyIterator)));
+ value = QV4::Primitive::fromInt32(enumerator.value(d()->keyIterator));
+ o->put(key, value);
+ if (name && key->toQString() == *name) {
+ ++d()->keyIterator;
+ foundProperty = true;
+ return value->asReturnedValue();
+ }
+ }
+ d()->keyIterator = 0;
+ }
+ d()->enumeratorIterator = Heap::QtObject::Finished;
+ foundProperty = false;
+ return Encode::undefined();
+}
+
+ReturnedValue QtObject::get(const Managed *m, String *name, bool *hasProperty)
+{
+ bool hasProp = false;
+ if (hasProperty == nullptr) {
+ hasProperty = &hasProp;
+ }
+
+ ReturnedValue ret = QV4::Object::get(m, name, hasProperty);
+ if (*hasProperty) {
+ return ret;
+ }
+
+ auto that = static_cast<const QtObject*>(m);
+ if (!that->d()->isComplete()) {
+ const QString key = name->toQString();
+ ret = that->findAndAdd(&key, *hasProperty);
+ }
+
+ return ret;
+}
+
+void QtObject::advanceIterator(Managed *m, ObjectIterator *it, Value *name, uint *index, Property *p, PropertyAttributes *attributes)
+{
+ auto that = static_cast<QtObject*>(m);
+ if (!that->d()->isComplete()) {
+ that->addAll();
+ }
+
+ QV4::Object::advanceIterator(m, it, name, index, p, attributes);
+}
/*!
\qmlmethod bool Qt::isQtObject(object)
diff --git a/src/qml/qml/v8/qqmlbuiltinfunctions_p.h b/src/qml/qml/v8/qqmlbuiltinfunctions_p.h
index 99c8b69724..5404ab3616 100644
--- a/src/qml/qml/v8/qqmlbuiltinfunctions_p.h
+++ b/src/qml/qml/v8/qqmlbuiltinfunctions_p.h
@@ -67,6 +67,13 @@ struct QtObject : Object {
QtObject(QQmlEngine *qmlEngine);
QObject *platform;
QObject *application;
+
+ enum { Finished = -1 };
+ int enumeratorIterator;
+ int keyIterator;
+
+ bool isComplete() const
+ { return enumeratorIterator == Finished; }
};
struct ConsoleObject : Object {
@@ -86,6 +93,9 @@ struct QtObject : Object
{
V4_OBJECT2(QtObject, Object)
+ static ReturnedValue get(const Managed *m, String *name, bool *hasProperty);
+ static void advanceIterator(Managed *m, ObjectIterator *it, Value *name, uint *index, Property *p, PropertyAttributes *attributes);
+
static ReturnedValue method_isQtObject(CallContext *ctx);
static ReturnedValue method_rgba(CallContext *ctx);
static ReturnedValue method_hsla(CallContext *ctx);
@@ -126,6 +136,10 @@ struct QtObject : Object
static ReturnedValue method_get_styleHints(CallContext *ctx);
static ReturnedValue method_callLater(CallContext *ctx);
+
+private:
+ void addAll();
+ ReturnedValue findAndAdd(const QString *name, bool &foundProperty) const;
};
struct ConsoleObject : Object