aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/qml/v8/qqmlbuiltinfunctions.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/qml/qml/v8/qqmlbuiltinfunctions.cpp')
-rw-r--r--src/qml/qml/v8/qqmlbuiltinfunctions.cpp129
1 files changed, 95 insertions, 34 deletions
diff --git a/src/qml/qml/v8/qqmlbuiltinfunctions.cpp b/src/qml/qml/v8/qqmlbuiltinfunctions.cpp
index b90fd7eb17..b9fb1f4ffe 100644
--- a/src/qml/qml/v8/qqmlbuiltinfunctions.cpp
+++ b/src/qml/qml/v8/qqmlbuiltinfunctions.cpp
@@ -1,31 +1,37 @@
/****************************************************************************
**
-** Copyright (C) 2015 The Qt Company Ltd.
-** Contact: http://www.qt.io/licensing/
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtQml module of the Qt Toolkit.
**
-** $QT_BEGIN_LICENSE:LGPL21$
+** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see http://www.qt.io/terms-conditions. For further
-** information use the contact form at http://www.qt.io/contact-us.
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 or version 3 as published by the Free
-** Software Foundation and appearing in the file LICENSE.LGPLv21 and
-** LICENSE.LGPLv3 included in the packaging of this file. Please review the
-** following information to ensure the GNU Lesser General Public License
-** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
-** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
**
-** As a special exception, The Qt Company gives you certain additional
-** rights. These rights are described in The Qt Company LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
@@ -56,6 +62,7 @@
#include <private/qv4mm_p.h>
#include <private/qv4jsonobject_p.h>
#include <private/qv4objectproto_p.h>
+#include <private/qv4qobjectwrapper_p.h>
#include <QtCore/qstring.h>
#include <QtCore/qdatetime.h>
@@ -81,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);
@@ -145,6 +148,70 @@ Heap::QtObject::QtObject(QQmlEngine *qmlEngine)
o->defineAccessorProperty(QStringLiteral("styleHints"), QV4::QtObject::method_get_styleHints, 0);
}
+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)
@@ -904,7 +971,7 @@ ReturnedValue QtObject::method_btoa(CallContext *ctx)
/*!
\qmlmethod string Qt::atob(data)
-ASCII to binary - this function returns a base64 decoding of \c data.
+ASCII to binary - this function decodes the base64 encoded \a data string and returns it.
*/
ReturnedValue QtObject::method_atob(CallContext *ctx)
{
@@ -1468,9 +1535,6 @@ QV4::ReturnedValue ConsoleObject::method_profile(CallContext *ctx)
{
QV4::ExecutionEngine *v4 = ctx->d()->engine;
- if (!v4->qmlEngine())
- return QV4::Encode::undefined(); // Not yet implemented for JavaScript.
-
QV4::StackFrame frame = v4->currentStackFrame();
const QByteArray baSource = frame.source.toUtf8();
const QByteArray baFunction = frame.function.toUtf8();
@@ -1479,7 +1543,7 @@ QV4::ReturnedValue ConsoleObject::method_profile(CallContext *ctx)
if (!service) {
logger.warning("Cannot start profiling because debug service is disabled. Start with -qmljsdebugger=port:XXXXX.");
} else {
- service->startProfiling(v4->qmlEngine());
+ service->startProfiling(v4->jsEngine());
logger.debug("Profiling started.");
}
@@ -1490,9 +1554,6 @@ QV4::ReturnedValue ConsoleObject::method_profileEnd(CallContext *ctx)
{
QV4::ExecutionEngine *v4 = ctx->d()->engine;
- if (!v4->qmlEngine())
- return QV4::Encode::undefined(); // Not yet implemented for JavaScript.
-
QV4::StackFrame frame = v4->currentStackFrame();
const QByteArray baSource = frame.source.toUtf8();
const QByteArray baFunction = frame.function.toUtf8();
@@ -1502,7 +1563,7 @@ QV4::ReturnedValue ConsoleObject::method_profileEnd(CallContext *ctx)
if (!service) {
logger.warning("Ignoring console.profileEnd(): the debug service is disabled.");
} else {
- service->stopProfiling(v4->qmlEngine());
+ service->stopProfiling(v4->jsEngine());
logger.debug("Profiling ended.");
}