aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/jsapi/qjsmanagedvalue.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/qml/jsapi/qjsmanagedvalue.cpp')
-rw-r--r--src/qml/jsapi/qjsmanagedvalue.cpp101
1 files changed, 35 insertions, 66 deletions
diff --git a/src/qml/jsapi/qjsmanagedvalue.cpp b/src/qml/jsapi/qjsmanagedvalue.cpp
index 202c940785..452f991a26 100644
--- a/src/qml/jsapi/qjsmanagedvalue.cpp
+++ b/src/qml/jsapi/qjsmanagedvalue.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2020 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: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 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 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.
-**
-** 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$
-**
-****************************************************************************/
+// Copyright (C) 2020 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include <QtQml/qjsmanagedvalue.h>
#include <QtQml/qjsengine.h>
@@ -49,9 +13,11 @@
#include <QtQml/private/qv4urlobject_p.h>
#include <QtQml/private/qv4variantobject_p.h>
#include <QtQml/private/qv4qobjectwrapper_p.h>
+#include <QtQml/private/qv4qmetaobjectwrapper_p.h>
#include <QtQml/private/qv4regexpobject_p.h>
#include <QtQml/private/qv4dateobject_p.h>
#include <QtQml/private/qv4errorobject_p.h>
+#include <QtQml/private/qv4identifiertable_p.h>
#include <QtCore/qregularexpression.h>
#include <QtCore/qurl.h>
@@ -64,6 +30,8 @@ QT_BEGIN_NAMESPACE
* \inmodule QtQml
* \since 6.1
*
+ * \inmodule QtQml
+ *
* \brief QJSManagedValue represents a value on the JavaScript heap belonging to a QJSEngine.
*
* The QJSManagedValue class allows interaction with JavaScript values in most
@@ -664,11 +632,10 @@ QVariant QJSManagedValue::toVariant() const
return QVariant(d->doubleValue());
if (d->isString())
return QVariant(d->toQString());
- if (QV4::Managed *m = d->as<QV4::Managed>())
- return m->engine()->toVariant(*d, -1, true);
+ if (d->as<QV4::Managed>())
+ return QV4::ExecutionEngine::toVariant(*d, QMetaType{}, true);
- Q_UNREACHABLE();
- return QVariant();
+ Q_UNREACHABLE_RETURN(QVariant());
}
/*!
@@ -740,8 +707,8 @@ bool QJSManagedValue::hasProperty(const QString &name) const
if (QV4::Object *obj = d->as<QV4::Object>()) {
QV4::Scope scope(obj->engine());
- QV4::ScopedString str(scope, obj->engine()->newString(name));
- return obj->hasProperty(str->toPropertyKey());
+ QV4::ScopedPropertyKey key(scope, scope.engine->identifierTable->asPropertyKey(name));
+ return obj->hasProperty(key);
}
return prototype().hasProperty(name);
@@ -761,8 +728,8 @@ bool QJSManagedValue::hasOwnProperty(const QString &name) const
if (QV4::Object *obj = d->as<QV4::Object>()) {
QV4::Scope scope(obj->engine());
- QV4::ScopedString str(scope, obj->engine()->newString(name));
- return obj->getOwnProperty(str->toPropertyKey()) != QV4::Attr_Invalid;
+ QV4::ScopedPropertyKey key(scope, scope.engine->identifierTable->asPropertyKey(name));
+ return obj->getOwnProperty(key) != QV4::Attr_Invalid;
}
return false;
@@ -790,8 +757,8 @@ QJSValue QJSManagedValue::property(const QString &name) const
if (QV4::Object *obj = d->as<QV4::Object>()) {
QV4::Scope scope(obj->engine());
- QV4::ScopedString str(scope, obj->engine()->newString(name));
- return QJSValuePrivate::fromReturnedValue(obj->get(str->toPropertyKey()));
+ QV4::ScopedPropertyKey key(scope, scope.engine->identifierTable->asPropertyKey(name));
+ return QJSValuePrivate::fromReturnedValue(obj->get(key));
}
return prototype().property(name);
@@ -813,16 +780,15 @@ void QJSManagedValue::setProperty(const QString &name, const QJSValue &value)
}
if (QV4::Object *obj = d->as<QV4::Object>()) {
+ QV4::Scope scope(obj->engine());
QV4::ExecutionEngine *v4 = QJSValuePrivate::engine(&value);
- if (Q_UNLIKELY(v4 && v4 != obj->engine())) {
+ if (Q_UNLIKELY(v4 && v4 != scope.engine)) {
qWarning("QJSManagedValue::setProperty() failed: "
"Value was created in different engine.");
return;
}
- QV4::Scope scope(obj->engine());
- QV4::ScopedString str(scope, obj->engine()->newString(name));
- obj->put(str->toPropertyKey(),
- QJSValuePrivate::convertToReturnedValue(scope.engine, value));
+ QV4::ScopedPropertyKey key(scope, scope.engine->identifierTable->asPropertyKey(name));
+ obj->put(key, QJSValuePrivate::convertToReturnedValue(scope.engine, value));
}
}
@@ -837,8 +803,8 @@ bool QJSManagedValue::deleteProperty(const QString &name)
if (QV4::Object *obj = d->as<QV4::Object>()) {
QV4::Scope scope(obj->engine());
- QV4::ScopedString str(scope, obj->engine()->newString(name));
- return obj->deleteProperty(str->toPropertyKey());
+ QV4::ScopedPropertyKey key(scope, scope.engine->identifierTable->asPropertyKey(name));
+ return obj->deleteProperty(key);
}
return false;
@@ -907,7 +873,7 @@ QJSValue QJSManagedValue::property(quint32 arrayIndex) const
if (QV4::String *string = d->as<QV4::String>()) {
const QString qString = string->toQString();
- if (arrayIndex < qString.size())
+ if (arrayIndex < quint32(qString.size()))
return qString.sliced(arrayIndex, 1);
return QJSValue();
}
@@ -992,15 +958,15 @@ QJSValue QJSManagedValue::call(const QJSValueList &arguments) const
QV4::ExecutionEngine *engine = f->engine();
QV4::Scope scope(engine);
- QV4::JSCallData jsCallData(scope, arguments.length());
- *jsCallData->thisObject = engine->globalObject;
+ QV4::JSCallArguments jsCallData(scope, arguments.size());
+ *jsCallData.thisObject = engine->globalObject;
int i = 0;
for (const QJSValue &arg : arguments) {
if (Q_UNLIKELY(!QJSValuePrivate::checkEngine(engine, arg))) {
qWarning("QJSManagedValue::call() failed: Argument was created in different engine.");
return QJSValue();
}
- jsCallData->args[i++] = QJSValuePrivate::convertToReturnedValue(engine, arg);
+ jsCallData.args[i++] = QJSValuePrivate::convertToReturnedValue(engine, arg);
}
return QJSValuePrivate::fromReturnedValue(f->call(jsCallData));
@@ -1031,8 +997,8 @@ QJSValue QJSManagedValue::callWithInstance(const QJSValue &instance,
}
QV4::Scope scope(engine);
- QV4::JSCallData jsCallData(scope, arguments.length());
- *jsCallData->thisObject = QJSValuePrivate::convertToReturnedValue(engine, instance);
+ QV4::JSCallArguments jsCallData(scope, arguments.size());
+ *jsCallData.thisObject = QJSValuePrivate::convertToReturnedValue(engine, instance);
int i = 0;
for (const QJSValue &arg : arguments) {
if (Q_UNLIKELY(!QJSValuePrivate::checkEngine(engine, arg))) {
@@ -1040,7 +1006,7 @@ QJSValue QJSManagedValue::callWithInstance(const QJSValue &instance,
"Argument was created in different engine.");
return QJSValue();
}
- jsCallData->args[i++] = QJSValuePrivate::convertToReturnedValue(engine, arg);
+ jsCallData.args[i++] = QJSValuePrivate::convertToReturnedValue(engine, arg);
}
return QJSValuePrivate::fromReturnedValue(f->call(jsCallData));
@@ -1064,7 +1030,7 @@ QJSValue QJSManagedValue::callAsConstructor(const QJSValueList &arguments) const
QV4::ExecutionEngine *engine = f->engine();
QV4::Scope scope(engine);
- QV4::JSCallData jsCallData(scope, arguments.length());
+ QV4::JSCallArguments jsCallData(scope, arguments.size());
int i = 0;
for (const QJSValue &arg : arguments) {
if (Q_UNLIKELY(!QJSValuePrivate::checkEngine(engine, arg))) {
@@ -1072,7 +1038,7 @@ QJSValue QJSManagedValue::callAsConstructor(const QJSValueList &arguments) const
"Argument was created in different engine.");
return QJSValue();
}
- jsCallData->args[i++] = QJSValuePrivate::convertToReturnedValue(engine, arg);
+ jsCallData.args[i++] = QJSValuePrivate::convertToReturnedValue(engine, arg);
}
return QJSValuePrivate::fromReturnedValue(f->callAsConstructor(jsCallData));
@@ -1121,8 +1087,11 @@ QStringList QJSManagedValue::jsMetaMembers() const
const int size = heapClass->size;
QStringList result;
result.reserve(size);
- for (int i = 0; i < size; ++i)
- result.append(heapClass->keyAt(i));
+ QV4::Scope scope(c->engine());
+ for (int i = 0; i < size; ++i) {
+ QV4::ScopedValue key(scope, heapClass->keyAt(i));
+ result.append(key->toQString());
+ }
return result;
}