diff options
author | Lars Knoll <lars.knoll@theqtcompany.com> | 2015-08-20 22:17:56 +0200 |
---|---|---|
committer | Lars Knoll <lars.knoll@theqtcompany.com> | 2015-09-09 14:28:34 +0000 |
commit | 6f9a090aa5c21916d19e20ebea16ff46690b7346 (patch) | |
tree | aefe250878a6a96e6848e8a6903d2bb911a713b7 /src/qml | |
parent | 1079dbbdd96c517eed3269e4a5e18f18a6808be0 (diff) |
Centralize access to qml context
Change-Id: If601262c7fd2d304491d60f63a7b9bcd4118cee8
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
Diffstat (limited to 'src/qml')
-rw-r--r-- | src/qml/types/qquickworkerscript.cpp | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/src/qml/types/qquickworkerscript.cpp b/src/qml/types/qquickworkerscript.cpp index 09e2709b2d..ab69ed410f 100644 --- a/src/qml/types/qquickworkerscript.cpp +++ b/src/qml/types/qquickworkerscript.cpp @@ -165,7 +165,7 @@ public: QUrl source; bool initialized; QQuickWorkerScript *owner; - QV4::PersistentValue object; + QV4::PersistentValue qmlContext; }; QHash<int, WorkerScript *> workers; @@ -291,7 +291,6 @@ QV4::ReturnedValue QQuickWorkerScriptEnginePrivate::method_sendMessage(QV4::Call return QV4::Encode::undefined(); } -// Requires handle scope and context scope QV4::ReturnedValue QQuickWorkerScriptEnginePrivate::getWorker(WorkerScript *script) { if (!script->initialized) { @@ -300,9 +299,7 @@ QV4::ReturnedValue QQuickWorkerScriptEnginePrivate::getWorker(WorkerScript *scri QV4::ExecutionEngine *v4 = QV8Engine::getV4(workerEngine); QV4::Scope scope(v4); - script->object.set(v4, QV4::QmlContextWrapper::urlScope(v4, script->source)); - - QV4::Scoped<QV4::QmlContextWrapper> w(scope, script->object.value()); + QV4::Scoped<QV4::QmlContextWrapper> w(scope, QV4::QmlContextWrapper::urlScope(v4, script->source)); Q_ASSERT(!!w); w->setReadOnly(false); @@ -312,9 +309,11 @@ QV4::ReturnedValue QQuickWorkerScriptEnginePrivate::getWorker(WorkerScript *scri w->QV4::Object::put(QV4::ScopedString(scope, v4->newString(QStringLiteral("WorkerScript"))), api); w->setReadOnly(true); + + script->qmlContext.set(v4, v4->rootContext()->newQmlContext(w)); } - return script->object.value(); + return script->qmlContext.value(); } bool QQuickWorkerScriptEnginePrivate::event(QEvent *event) @@ -354,10 +353,12 @@ void QQuickWorkerScriptEnginePrivate::processMessage(int id, const QByteArray &d QV4::ScopedFunctionObject f(scope, workerEngine->onmessage.value()); QV4::ScopedValue value(scope, QV4::Serialize::deserialize(data, v4)); + QV4::Scoped<QV4::QmlContext> qmlContext(scope, script->qmlContext.value()); + Q_ASSERT(!!qmlContext); QV4::ScopedCallData callData(scope, 2); callData->thisObject = workerEngine->global(); - callData->args[0] = script->object.value(); + callData->args[0] = qmlContext->d()->qml; // ### callData->args[1] = value; f->call(callData); if (scope.hasException()) { @@ -382,10 +383,8 @@ void QQuickWorkerScriptEnginePrivate::processLoad(int id, const QUrl &url) return; script->source = url; - QV4::Scoped<QV4::QmlContextWrapper> activation(scope, getWorker(script)); - if (!activation) - return; - QV4::Scoped<QV4::QmlContext> qmlContext(scope, v4->rootContext()->newQmlContext(activation)); + QV4::Scoped<QV4::QmlContext> qmlContext(scope, getWorker(script)); + Q_ASSERT(!!qmlContext); if (const QQmlPrivate::CachedQmlUnit *cachedUnit = QQmlMetaType::findCachedCompilationUnit(url)) { QV4::CompiledData::CompilationUnit *jsUnit = cachedUnit->createCompilationUnit(); |