aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFabian Kosmale <fabian.kosmale@qt.io>2024-11-01 09:04:02 +0100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2024-11-01 21:55:34 +0000
commita66d021748d093f698546d9b0082c643afa99ee9 (patch)
treebbbf74ab7b1200eabc9edf1b6dea470b39f3829d
parent629db8d98eeb546eb3a2fca13699fa2b94a73e70 (diff)
QQmlContextData: Don't expose PersistentValue in imported scripts API
This is in preparation of the next commit, which will change how we store the data internally. Change-Id: I5b35639c8757770c1efad98f85c70227344adeea Reviewed-by: Ulf Hermann <ulf.hermann@qt.io> (cherry picked from commit 85253dfa20babec2e56c07ab7e5ba68cc60c3176) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--src/qml/jsruntime/qv4qmlcontext.cpp4
-rw-r--r--src/qml/qml/qqmlcontext.cpp2
-rw-r--r--src/qml/qml/qqmlcontextdata_p.h4
-rw-r--r--src/qml/qml/qqmlengine.cpp2
-rw-r--r--src/qml/qml/qqmlobjectcreator.cpp2
-rw-r--r--src/qml/qml/qqmlscriptdata.cpp9
-rw-r--r--src/qml/qml/qqmltypewrapper.cpp2
-rw-r--r--tests/auto/qml/qqmlcontext/tst_qqmlcontext.cpp6
-rw-r--r--tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp2
9 files changed, 16 insertions, 17 deletions
diff --git a/src/qml/jsruntime/qv4qmlcontext.cpp b/src/qml/jsruntime/qv4qmlcontext.cpp
index 53444cddb7..013761302f 100644
--- a/src/qml/jsruntime/qv4qmlcontext.cpp
+++ b/src/qml/jsruntime/qv4qmlcontext.cpp
@@ -212,7 +212,7 @@ ReturnedValue QQmlContextWrapper::getPropertyAndBase(const QQmlContextWrapper *r
lookup->qmlContextPropertyGetter = QQmlContextWrapper::lookupScript;
return lookup->qmlContextPropertyGetter(lookup, v4, base);
}
- QV4::ScopedObject scripts(scope, context->importedScripts().valueRef());
+ QV4::ScopedObject scripts(scope, context->importedScripts());
if (scripts)
return scripts->get(r.scriptIndex);
return QV4::Encode::null();
@@ -568,7 +568,7 @@ ReturnedValue QQmlContextWrapper::lookupScript(Lookup *l, ExecutionEngine *engin
if (!context)
return QV4::Encode::null();
- QV4::ScopedObject scripts(scope, context->importedScripts().valueRef());
+ QV4::ScopedObject scripts(scope, context->importedScripts());
if (!scripts)
return QV4::Encode::null();
return scripts->get(l->qmlContextScriptLookup.scriptIndex);
diff --git a/src/qml/qml/qqmlcontext.cpp b/src/qml/qml/qqmlcontext.cpp
index cf6736deb9..39dacb80f4 100644
--- a/src/qml/qml/qqmlcontext.cpp
+++ b/src/qml/qml/qqmlcontext.cpp
@@ -455,7 +455,7 @@ QJSValue QQmlContext::importedScript(const QString &name) const
QQmlTypeNameCache::Result r = d->m_data->imports()->query(name, QQmlTypeLoader::get(engine()));
QV4::Scope scope(engine()->handle());
- QV4::ScopedObject scripts(scope, d->m_data->importedScripts().valueRef());
+ QV4::ScopedObject scripts(scope, d->m_data->importedScripts());
return scripts ? QJSValuePrivate::fromReturnedValue(scripts->get(r.scriptIndex))
: QJSValue(QJSValue::UndefinedValue);
}
diff --git a/src/qml/qml/qqmlcontextdata_p.h b/src/qml/qml/qqmlcontextdata_p.h
index 3aeabf72fa..c906a216a5 100644
--- a/src/qml/qml/qqmlcontextdata_p.h
+++ b/src/qml/qml/qqmlcontextdata_p.h
@@ -274,8 +274,8 @@ public:
bool isRootObjectInCreation() const { return m_isRootObjectInCreation; }
void setRootObjectInCreation(bool rootInCreation) { m_isRootObjectInCreation = rootInCreation; }
- QV4::PersistentValue importedScripts() const { return m_importedScripts; }
- void setImportedScripts(const QV4::PersistentValue &scripts) { m_importedScripts = scripts; }
+ QV4::Value importedScripts() const { return m_importedScripts.value(); }
+ void setImportedScripts(QV4::ExecutionEngine *engine, QV4::Value scripts) { m_importedScripts.set(engine, scripts); }
QQmlRefPointer<QQmlContextData> linkedContext() const { return m_linkedContext; }
void setLinkedContext(const QQmlRefPointer<QQmlContextData> &context) { m_linkedContext = context; }
diff --git a/src/qml/qml/qqmlengine.cpp b/src/qml/qml/qqmlengine.cpp
index 9098063fce..8e928303ce 100644
--- a/src/qml/qml/qqmlengine.cpp
+++ b/src/qml/qml/qqmlengine.cpp
@@ -2005,7 +2005,7 @@ QQmlEnginePrivate::createInternalContext(const QQmlRefPointer<QV4::ExecutableCom
QV4::Scope scope(v4);
QV4::ScopedObject scripts(scope, v4->newArrayObject(dependentScriptsSize));
- context->setImportedScripts(QV4::PersistentValue(v4, scripts.asReturnedValue()));
+ context->setImportedScripts(v4, scripts);
QV4::ScopedValue v(scope);
for (qsizetype i = 0; i < dependentScriptsSize; ++i)
scripts->put(i, (v = dependentScripts->at(i)->scriptValueForContext(context)));
diff --git a/src/qml/qml/qqmlobjectcreator.cpp b/src/qml/qml/qqmlobjectcreator.cpp
index a9b9140390..fab2790baa 100644
--- a/src/qml/qml/qqmlobjectcreator.cpp
+++ b/src/qml/qml/qqmlobjectcreator.cpp
@@ -195,7 +195,7 @@ QObject *QQmlObjectCreator::create(int subComponentIndex, QObject *parent, QQmlI
if (!isComponentRoot && sharedState->creationContext) {
// otherwise QQmlEnginePrivate::createInternalContext() handles it
- context->setImportedScripts(sharedState->creationContext->importedScripts());
+ context->setImportedScripts(v4, sharedState->creationContext->importedScripts());
}
QObject *instance = createInstance(objectToCreate, parent, /*isContextObject*/true);
diff --git a/src/qml/qml/qqmlscriptdata.cpp b/src/qml/qml/qqmlscriptdata.cpp
index f26b7610a6..202267473f 100644
--- a/src/qml/qml/qqmlscriptdata.cpp
+++ b/src/qml/qml/qqmlscriptdata.cpp
@@ -33,6 +33,7 @@ QQmlRefPointer<QQmlContextData> QQmlScriptData::qmlContextDataForContext(
qmlContextData->setPragmaLibraryContext(parentQmlContextData->isPragmaLibraryContext());
qmlContextData->setBaseUrl(url);
qmlContextData->setBaseUrlString(urlString);
+ QV4::ExecutionEngine *v4 = parentQmlContextData->engine()->handle();
// For backward compatibility, if there are no imports, we need to use the
// imports from the parent context. See QTBUG-17518.
@@ -40,21 +41,19 @@ QQmlRefPointer<QQmlContextData> QQmlScriptData::qmlContextDataForContext(
qmlContextData->setImports(typeNameCache);
} else if (!m_precompiledScript->isSharedLibrary()) {
qmlContextData->setImports(parentQmlContextData->imports());
- qmlContextData->setImportedScripts(parentQmlContextData->importedScripts());
+ qmlContextData->setImportedScripts(v4, parentQmlContextData->importedScripts());
}
if (m_precompiledScript->isSharedLibrary())
qmlContextData->setEngine(parentQmlContextData->engine()); // Fix for QTBUG-21620
- QV4::ExecutionEngine *v4 = parentQmlContextData->engine()->handle();
QV4::Scope scope(v4);
QV4::ScopedObject scriptsArray(scope);
if (qmlContextData->importedScripts().isNullOrUndefined()) {
scriptsArray = v4->newArrayObject(scripts.size());
- qmlContextData->setImportedScripts(
- QV4::PersistentValue(v4, scriptsArray.asReturnedValue()));
+ qmlContextData->setImportedScripts(v4, scriptsArray);
} else {
- scriptsArray = qmlContextData->importedScripts().valueRef();
+ scriptsArray = qmlContextData->importedScripts();
}
QV4::ScopedValue v(scope);
for (int ii = 0; ii < scripts.size(); ++ii) {
diff --git a/src/qml/qml/qqmltypewrapper.cpp b/src/qml/qml/qqmltypewrapper.cpp
index 12811ee195..2d489be73c 100644
--- a/src/qml/qml/qqmltypewrapper.cpp
+++ b/src/qml/qml/qqmltypewrapper.cpp
@@ -388,7 +388,7 @@ ReturnedValue QQmlTypeWrapper::virtualGet(const Managed *m, PropertyKey id, cons
if (r.type.isValid()) {
return create(scope.engine, object, r.type, w->d()->typeNameMode());
} else if (r.scriptIndex != -1) {
- QV4::ScopedObject scripts(scope, context->importedScripts().valueRef());
+ QV4::ScopedObject scripts(scope, context->importedScripts());
return scripts->get(r.scriptIndex);
} else if (r.importNamespace) {
return create(scope.engine, object, context->imports(), r.importNamespace);
diff --git a/tests/auto/qml/qqmlcontext/tst_qqmlcontext.cpp b/tests/auto/qml/qqmlcontext/tst_qqmlcontext.cpp
index 8e726857cc..257ee5417e 100644
--- a/tests/auto/qml/qqmlcontext/tst_qqmlcontext.cpp
+++ b/tests/auto/qml/qqmlcontext/tst_qqmlcontext.cpp
@@ -816,12 +816,12 @@ void tst_qqmlcontext::contextLeak()
QQmlRefPointer<QQmlContextData> context = ddata->context;
QVERIFY(context);
QVERIFY(!context->importedScripts().isNullOrUndefined());
- QCOMPARE(int(context->importedScripts().valueRef()->as<QV4::Object>()->getLength()), 1);
+ QCOMPARE(int(context->importedScripts().as<QV4::Object>()->getLength()), 1);
QV4::Scope scope(ddata->jsWrapper.engine());
QV4::ScopedValue scriptContextWrapper(scope);
- scriptContextWrapper = context->importedScripts().valueRef()
- ->as<QV4::Object>()->get(uint(0));
+ scriptContextWrapper = context->importedScripts()
+ .as<QV4::Object>()->get(uint(0));
scriptContext = scriptContextWrapper->as<QV4::QQmlContextWrapper>()->getContext();
}
diff --git a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
index 87d9f44bcc..14368b47ba 100644
--- a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
+++ b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
@@ -4755,7 +4755,7 @@ void tst_qqmlecmascript::verifyContextLifetime(const QQmlRefPointer<QQmlContextD
if (!ctxt->importedScripts().isNullOrUndefined()) {
QV4::ExecutionEngine *v4 = ctxt->engine()->handle();
QV4::Scope scope(v4);
- QV4::ScopedArrayObject scripts(scope, ctxt->importedScripts().value());
+ QV4::ScopedArrayObject scripts(scope, ctxt->importedScripts());
QV4::Scoped<QV4::QQmlContextWrapper> qml(scope);
for (quint32 i = 0; i < scripts->getLength(); ++i) {
QQmlRefPointer<QQmlContextData> scriptContext, newContext;