diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/qml/jsruntime/qv4include.cpp | 17 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4include_p.h | 4 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4script.cpp | 23 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4script_p.h | 14 | ||||
-rw-r--r-- | src/qml/qml/qqmljavascriptexpression.cpp | 8 | ||||
-rw-r--r-- | src/qml/qml/qqmltypeloader.cpp | 9 | ||||
-rw-r--r-- | src/qml/types/qquickworkerscript.cpp | 7 |
7 files changed, 45 insertions, 37 deletions
diff --git a/src/qml/jsruntime/qv4include.cpp b/src/qml/jsruntime/qv4include.cpp index a95b1ce5ac..90c6738c46 100644 --- a/src/qml/jsruntime/qv4include.cpp +++ b/src/qml/jsruntime/qv4include.cpp @@ -50,10 +50,11 @@ QT_BEGIN_NAMESPACE QV4Include::QV4Include(const QUrl &url, QV4::ExecutionEngine *engine, - const QV4::Value &qmlglobal, const QV4::Value &callback) + QV4::QmlContext *qmlContext, const QV4::Value &callback) : v4(engine), m_network(0), m_reply(0), m_url(url), m_redirectCount(0) { - m_qmlglobal.set(engine, qmlglobal); + if (qmlContext) + m_qmlContext.set(engine, *qmlContext); if (callback.as<QV4::FunctionObject>()) m_callbackFunction.set(engine, callback); @@ -142,8 +143,8 @@ void QV4Include::finished() QString code = QString::fromUtf8(data); QmlIR::Document::removeScriptPragmas(code); - QV4::ScopedObject qmlglobal(scope, m_qmlglobal.value()); - QV4::Script script(v4, qmlglobal, code, m_url.toString()); + QV4::Scoped<QV4::QmlContext> qml(scope, m_qmlContext.value()); + QV4::Script script(v4, qml, code, m_url.toString()); script.parse(); if (!scope.engine->hasException) @@ -190,10 +191,10 @@ QV4::ReturnedValue QV4Include::method_include(QV4::CallContext *ctx) QString localFile = QQmlFile::urlToLocalFileOrQrc(url); QV4::ScopedValue result(scope); - QV4::ScopedObject qmlcontextobject(scope, scope.engine->qmlContextObject()); + QV4::Scoped<QV4::QmlContext> qmlcontext(scope, scope.engine->qmlContext()); if (localFile.isEmpty()) { - QV4Include *i = new QV4Include(url, scope.engine, qmlcontextobject, callbackFunction); + QV4Include *i = new QV4Include(url, scope.engine, qmlcontext, callbackFunction); result = i->result(); } else { @@ -201,7 +202,7 @@ QV4::ReturnedValue QV4Include::method_include(QV4::CallContext *ctx) if (const QQmlPrivate::CachedQmlUnit *cachedUnit = QQmlMetaType::findCachedCompilationUnit(url)) { QV4::CompiledData::CompilationUnit *jsUnit = cachedUnit->createCompilationUnit(); - script.reset(new QV4::Script(scope.engine, qmlcontextobject, jsUnit)); + script.reset(new QV4::Script(scope.engine, qmlcontext, jsUnit)); } else { QFile f(localFile); @@ -210,7 +211,7 @@ QV4::ReturnedValue QV4Include::method_include(QV4::CallContext *ctx) QString code = QString::fromUtf8(data); QmlIR::Document::removeScriptPragmas(code); - script.reset(new QV4::Script(scope.engine, qmlcontextobject, code, url.toString())); + script.reset(new QV4::Script(scope.engine, qmlcontext, code, url.toString())); } } diff --git a/src/qml/jsruntime/qv4include_p.h b/src/qml/jsruntime/qv4include_p.h index fc99ff7589..3e3cf5e770 100644 --- a/src/qml/jsruntime/qv4include_p.h +++ b/src/qml/jsruntime/qv4include_p.h @@ -76,7 +76,7 @@ private Q_SLOTS: void finished(); private: - QV4Include(const QUrl &url, QV4::ExecutionEngine *engine, const QV4::Value &qmlglobal, const QV4::Value &callback); + QV4Include(const QUrl &url, QV4::ExecutionEngine *engine, QV4::QmlContext *qmlContext, const QV4::Value &callback); ~QV4Include(); QV4::ReturnedValue result(); @@ -94,7 +94,7 @@ private: QV4::PersistentValue m_callbackFunction; QV4::PersistentValue m_resultObject; - QV4::PersistentValue m_qmlglobal; + QV4::PersistentValue m_qmlContext; }; QT_END_NAMESPACE diff --git a/src/qml/jsruntime/qv4script.cpp b/src/qml/jsruntime/qv4script.cpp index 41cb6309f8..32a15fdf5e 100644 --- a/src/qml/jsruntime/qv4script.cpp +++ b/src/qml/jsruntime/qv4script.cpp @@ -130,10 +130,13 @@ ReturnedValue QmlBindingWrapper::call(const Managed *that, CallData *callData) return result->asReturnedValue(); } -Script::Script(ExecutionEngine *v4, Object *qml, CompiledData::CompilationUnit *compilationUnit) +Script::Script(ExecutionEngine *v4, QmlContext *qml, CompiledData::CompilationUnit *compilationUnit) : line(0), column(0), scope(v4->rootContext()), strictMode(false), inheritContext(true), parsed(false) - , qml(v4, qml), vmFunction(0), parseAsBinding(true) + , vmFunction(0), parseAsBinding(true) { + if (qml) + qmlContext.set(v4, *qml); + parsed = true; vmFunction = compilationUnit ? compilationUnit->linkToEngine(v4) : 0; @@ -231,7 +234,7 @@ ReturnedValue Script::run() QV4::ExecutionEngine *engine = scope->engine(); QV4::Scope valueScope(engine); - if (qml.isUndefined()) { + if (qmlContext.isUndefined()) { TemporaryAssignment<Function*> savedGlobalCode(engine->globalCode, vmFunction); ExecutionContextSaver ctxSaver(valueScope, scope); @@ -242,9 +245,8 @@ ReturnedValue Script::run() return Q_V4_PROFILE(engine, vmFunction); } else { - Scoped<QmlContextWrapper> qmlObj(valueScope, qml.value()); - Scoped<QmlContext> qmlContext(valueScope, scope->newQmlContext(qmlObj)); - ScopedFunctionObject f(valueScope, engine->memoryManager->alloc<QmlBindingWrapper>(qmlContext, vmFunction)); + Scoped<QmlContext> qml(valueScope, qmlContext.value()); + ScopedFunctionObject f(valueScope, engine->memoryManager->alloc<QmlBindingWrapper>(qml, vmFunction)); ScopedCallData callData(valueScope); callData->thisObject = Primitive::undefinedValue(); return f->call(callData); @@ -321,16 +323,15 @@ ReturnedValue Script::qmlBinding() parse(); ExecutionEngine *v4 = scope->engine(); Scope valueScope(v4); - Scoped<QmlContextWrapper> qmlObj(valueScope, qml.value()); - Scoped<QmlContext> qmlContext(valueScope, scope->newQmlContext(qmlObj)); - ScopedObject v(valueScope, v4->memoryManager->alloc<QmlBindingWrapper>(qmlContext, vmFunction)); + Scoped<QmlContext> qml(valueScope, qmlContext.value()); + ScopedObject v(valueScope, v4->memoryManager->alloc<QmlBindingWrapper>(qml, vmFunction)); return v.asReturnedValue(); } -QV4::ReturnedValue Script::evaluate(ExecutionEngine *engine, const QString &script, Object *scopeObject) +QV4::ReturnedValue Script::evaluate(ExecutionEngine *engine, const QString &script, QmlContext *qmlContext) { QV4::Scope scope(engine); - QV4::Script qmlScript(engine, scopeObject, script, QString()); + QV4::Script qmlScript(engine, qmlContext, script, QString()); qmlScript.parse(); QV4::ScopedValue result(scope); diff --git a/src/qml/jsruntime/qv4script_p.h b/src/qml/jsruntime/qv4script_p.h index 5b92749b4c..63e8239342 100644 --- a/src/qml/jsruntime/qv4script_p.h +++ b/src/qml/jsruntime/qv4script_p.h @@ -36,6 +36,7 @@ #include "qv4global_p.h" #include "qv4engine_p.h" #include "qv4functionobject_p.h" +#include "qv4context_p.h" #include <QQmlError> @@ -90,11 +91,14 @@ struct Q_QML_EXPORT Script { : sourceFile(source), line(line), column(column), sourceCode(sourceCode) , scope(scope), strictMode(false), inheritContext(false), parsed(false) , vmFunction(0), parseAsBinding(false) {} - Script(ExecutionEngine *engine, Object *qml, const QString &sourceCode, const QString &source = QString(), int line = 1, int column = 0) + Script(ExecutionEngine *engine, QmlContext *qml, const QString &sourceCode, const QString &source = QString(), int line = 1, int column = 0) : sourceFile(source), line(line), column(column), sourceCode(sourceCode) , scope(engine->rootContext()), strictMode(false), inheritContext(true), parsed(false) - , qml(engine, qml), vmFunction(0), parseAsBinding(true) {} - Script(ExecutionEngine *engine, Object *qml, CompiledData::CompilationUnit *compilationUnit); + , vmFunction(0), parseAsBinding(true) { + if (qml) + qmlContext.set(engine, *qml); + } + Script(ExecutionEngine *engine, QmlContext *qml, CompiledData::CompilationUnit *compilationUnit); ~Script(); QString sourceFile; int line; @@ -104,7 +108,7 @@ struct Q_QML_EXPORT Script { bool strictMode; bool inheritContext; bool parsed; - QV4::PersistentValue qml; + QV4::PersistentValue qmlContext; QV4::PersistentValue compilationUnitHolder; Function *vmFunction; bool parseAsBinding; @@ -118,7 +122,7 @@ struct Q_QML_EXPORT Script { static QQmlRefPointer<CompiledData::CompilationUnit> precompile(IR::Module *module, Compiler::JSUnitGenerator *unitGenerator, ExecutionEngine *engine, const QUrl &url, const QString &source, QList<QQmlError> *reportedErrors = 0, QQmlJS::Directives *directivesCollector = 0); - static ReturnedValue evaluate(ExecutionEngine *engine, const QString &script, Object *scopeObject); + static ReturnedValue evaluate(ExecutionEngine *engine, const QString &script, QmlContext *qmlContext); }; } diff --git a/src/qml/qml/qqmljavascriptexpression.cpp b/src/qml/qml/qqmljavascriptexpression.cpp index 967a7e75d7..5938ebf5d7 100644 --- a/src/qml/qml/qqmljavascriptexpression.cpp +++ b/src/qml/qml/qqmljavascriptexpression.cpp @@ -365,8 +365,8 @@ QQmlJavaScriptExpression::evalFunction(QQmlContextData *ctxt, QObject *scopeObje QV4::ExecutionEngine *v4 = QV8Engine::getV4(ep->v8engine()); QV4::Scope scope(v4); - QV4::ScopedObject qmlScopeObject(scope, QV4::QmlContextWrapper::qmlScope(v4, ctxt, scopeObject)); - QV4::Script script(v4, qmlScopeObject, code, filename, line); + QV4::Scoped<QV4::QmlContext> qmlContext(scope, v4->rootContext()->newQmlContext(ctxt, scopeObject)); + QV4::Script script(v4, qmlContext, code, filename, line); QV4::ScopedValue result(scope); script.parse(); if (!v4->hasException) @@ -395,8 +395,8 @@ void QQmlJavaScriptExpression::createQmlBinding(QQmlContextData *ctxt, QObject * QV4::ExecutionEngine *v4 = QV8Engine::getV4(ep->v8engine()); QV4::Scope scope(v4); - QV4::ScopedObject qmlScopeObject(scope, QV4::QmlContextWrapper::qmlScope(v4, ctxt, qmlScope)); - QV4::Script script(v4, qmlScopeObject, code, filename, line); + QV4::Scoped<QV4::QmlContext> qmlContext(scope, v4->rootContext()->newQmlContext(ctxt, qmlScope)); + QV4::Script script(v4, qmlContext, code, filename, line); QV4::ScopedValue result(scope); script.parse(); if (!v4->hasException) diff --git a/src/qml/qml/qqmltypeloader.cpp b/src/qml/qml/qqmltypeloader.cpp index eb65f732dd..5f30b83bbd 100644 --- a/src/qml/qml/qqmltypeloader.cpp +++ b/src/qml/qml/qqmltypeloader.cpp @@ -2538,10 +2538,11 @@ QV4::PersistentValue QQmlScriptData::scriptValueForContext(QQmlContextData *pare return QV4::PersistentValue(); } - QV4::Scoped<QV4::QmlContextWrapper> qmlglobal(scope, QV4::QmlContextWrapper::qmlScope(v4, ctxt, 0)); - qmlglobal->takeContextOwnership(); + QV4::Scoped<QV4::QmlContext> qmlContext(scope, v4->rootContext()->newQmlContext(ctxt, 0)); + QV4::Scoped<QV4::QmlContextWrapper> w(scope, qmlContext->d()->qml); + w->takeContextOwnership(); - m_program->qml.set(scope.engine, qmlglobal); + m_program->qmlContext.set(scope.engine, qmlContext); m_program->run(); if (scope.engine->hasException) { QQmlError error = scope.engine->catchExceptionAsQmlError(); @@ -2549,7 +2550,7 @@ QV4::PersistentValue QQmlScriptData::scriptValueForContext(QQmlContextData *pare ep->warning(error); } - rv.set(scope.engine, qmlglobal); + rv.set(scope.engine, w); if (shared) { m_value = rv; m_loaded = true; diff --git a/src/qml/types/qquickworkerscript.cpp b/src/qml/types/qquickworkerscript.cpp index 0aa5dc4ef6..09e2709b2d 100644 --- a/src/qml/types/qquickworkerscript.cpp +++ b/src/qml/types/qquickworkerscript.cpp @@ -382,13 +382,14 @@ void QQuickWorkerScriptEnginePrivate::processLoad(int id, const QUrl &url) return; script->source = url; - QV4::ScopedObject activation(scope, getWorker(script)); + QV4::Scoped<QV4::QmlContextWrapper> activation(scope, getWorker(script)); if (!activation) return; + QV4::Scoped<QV4::QmlContext> qmlContext(scope, v4->rootContext()->newQmlContext(activation)); if (const QQmlPrivate::CachedQmlUnit *cachedUnit = QQmlMetaType::findCachedCompilationUnit(url)) { QV4::CompiledData::CompilationUnit *jsUnit = cachedUnit->createCompilationUnit(); - program.reset(new QV4::Script(v4, activation, jsUnit)); + program.reset(new QV4::Script(v4, qmlContext, jsUnit)); } else { QFile f(fileName); if (!f.open(QIODevice::ReadOnly)) { @@ -400,7 +401,7 @@ void QQuickWorkerScriptEnginePrivate::processLoad(int id, const QUrl &url) QString sourceCode = QString::fromUtf8(data); QmlIR::Document::removeScriptPragmas(sourceCode); - program.reset(new QV4::Script(v4, activation, sourceCode, url.toString())); + program.reset(new QV4::Script(v4, qmlContext, sourceCode, url.toString())); program->parse(); } |