diff options
Diffstat (limited to 'src/qml/types/qquickworkerscript.cpp')
-rw-r--r-- | src/qml/types/qquickworkerscript.cpp | 64 |
1 files changed, 26 insertions, 38 deletions
diff --git a/src/qml/types/qquickworkerscript.cpp b/src/qml/types/qquickworkerscript.cpp index 346f2e6a61..80c2d3a4bc 100644 --- a/src/qml/types/qquickworkerscript.cpp +++ b/src/qml/types/qquickworkerscript.cpp @@ -186,7 +186,7 @@ public: int m_nextId; - static QV4::ReturnedValue method_sendMessage(const QV4::BuiltinFunction *, QV4::CallData *callData); + static QV4::ReturnedValue method_sendMessage(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc); signals: void stopThread(); @@ -201,9 +201,9 @@ private: }; QQuickWorkerScriptEnginePrivate::WorkerEngine::WorkerEngine(QQuickWorkerScriptEnginePrivate *parent) -: QV8Engine(0), p(parent) + : QV8Engine(nullptr, new QV4::ExecutionEngine), p(parent) #if QT_CONFIG(qml_network) -, accessManager(0) +, accessManager(nullptr) #endif { m_v4Engine->v8Engine = this; @@ -214,6 +214,7 @@ QQuickWorkerScriptEnginePrivate::WorkerEngine::~WorkerEngine() #if QT_CONFIG(qml_network) delete accessManager; #endif + delete m_v4Engine; } void QQuickWorkerScriptEnginePrivate::WorkerEngine::init() @@ -246,11 +247,11 @@ void QQuickWorkerScriptEnginePrivate::WorkerEngine::init() QV4::ScopedFunctionObject createsendconstructor(scope, createsendscript.run()); Q_ASSERT(!scope.engine->hasException); QV4::ScopedString name(scope, m_v4Engine->newString(QStringLiteral("sendMessage"))); - QV4::ScopedValue function(scope, QV4::BuiltinFunction::create(globalContext, name, - QQuickWorkerScriptEnginePrivate::method_sendMessage)); + QV4::ScopedValue function(scope, QV4::FunctionObject::createBuiltinFunction(globalContext, name, + QQuickWorkerScriptEnginePrivate::method_sendMessage)); QV4::JSCallData jsCallData(scope, 1); jsCallData->args[0] = function; - *jsCallData->thisObject = global(); + *jsCallData->thisObject = m_v4Engine->global(); createsend.set(scope.engine, createsendconstructor->call(jsCallData)); } @@ -267,7 +268,7 @@ QV4::ReturnedValue QQuickWorkerScriptEnginePrivate::WorkerEngine::sendFunction(i QV4::ScopedValue v(scope); QV4::JSCallData jsCallData(scope, 1); jsCallData->args[0] = QV4::Primitive::fromInt32(id); - *jsCallData->thisObject = global(); + *jsCallData->thisObject = m_v4Engine->global(); v = f->call(jsCallData); if (scope.hasException()) v = scope.engine->catchException(); @@ -289,19 +290,19 @@ QNetworkAccessManager *QQuickWorkerScriptEnginePrivate::WorkerEngine::networkAcc #endif QQuickWorkerScriptEnginePrivate::QQuickWorkerScriptEnginePrivate(QQmlEngine *engine) -: workerEngine(0), qmlengine(engine), m_nextId(0) +: workerEngine(nullptr), qmlengine(engine), m_nextId(0) { } -QV4::ReturnedValue QQuickWorkerScriptEnginePrivate::method_sendMessage(const QV4::BuiltinFunction *b, - QV4::CallData *callData) +QV4::ReturnedValue QQuickWorkerScriptEnginePrivate::method_sendMessage(const QV4::FunctionObject *b, + const QV4::Value *, const QV4::Value *argv, int argc) { QV4::Scope scope(b); - WorkerEngine *engine = (WorkerEngine*)scope.engine->v8Engine; + WorkerEngine *engine = static_cast<WorkerEngine *>(scope.engine->v8Engine); - int id = callData->argc() > 1 ? callData->args[1].toInt32() : 0; + int id = argc > 1 ? argv[1].toInt32() : 0; - QV4::ScopedValue v(scope, callData->argument(2)); + QV4::ScopedValue v(scope, argc > 2 ? argv[2] : QV4::Primitive::undefinedValue()); QByteArray data = QV4::Serialize::serialize(v, scope.engine); QMutexLocker locker(&engine->p->m_lock); @@ -367,7 +368,7 @@ void QQuickWorkerScriptEnginePrivate::processMessage(int id, const QByteArray &d Q_ASSERT(!!qmlContext); QV4::JSCallData jsCallData(scope, 2); - *jsCallData->thisObject = workerEngine->global(); + *jsCallData->thisObject = v4->global(); jsCallData->args[0] = qmlContext->d()->qml(); // ### jsCallData->args[1] = value; f->call(jsCallData); @@ -396,22 +397,10 @@ void QQuickWorkerScriptEnginePrivate::processLoad(int id, const QUrl &url) 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(); - program.reset(new QV4::Script(v4, qmlContext, jsUnit)); - } else { - QFile f(fileName); - if (!f.open(QIODevice::ReadOnly)) { - qWarning().nospace() << "WorkerScript: Cannot find source file " << url.toString(); - return; - } - - QByteArray data = f.readAll(); - QString sourceCode = QString::fromUtf8(data); - QmlIR::Document::removeScriptPragmas(sourceCode); - - program.reset(new QV4::Script(v4, qmlContext, sourceCode, url.toString())); - program->parse(); + program.reset(QV4::Script::createFromFileOrCache(v4, qmlContext, fileName, url)); + if (program.isNull()) { + qWarning().nospace() << "WorkerScript: Cannot find source file " << url.toString(); + return; } if (!v4->hasException) @@ -518,7 +507,7 @@ QQuickWorkerScriptEngine::~QQuickWorkerScriptEngine() } QQuickWorkerScriptEnginePrivate::WorkerScript::WorkerScript() -: id(-1), initialized(false), owner(0) +: id(-1), initialized(false), owner(nullptr) { } @@ -545,7 +534,7 @@ void QQuickWorkerScriptEngine::removeWorkerScript(int id) { QQuickWorkerScriptEnginePrivate::WorkerScript* script = d->workers.value(id); if (script) { - script->owner = 0; + script->owner = nullptr; QCoreApplication::postEvent(d, new WorkerRemoveEvent(id)); } } @@ -576,7 +565,7 @@ void QQuickWorkerScriptEngine::run() qDeleteAll(d->workers); d->workers.clear(); - delete d->workerEngine; d->workerEngine = 0; + delete d->workerEngine; d->workerEngine = nullptr; } @@ -627,7 +616,7 @@ void QQuickWorkerScriptEngine::run() {Threaded ListModel Example} */ QQuickWorkerScript::QQuickWorkerScript(QObject *parent) -: QObject(parent), m_engine(0), m_scriptId(-1), m_componentComplete(true) +: QObject(parent), m_engine(nullptr), m_scriptId(-1), m_componentComplete(true) { } @@ -707,7 +696,7 @@ QQuickWorkerScriptEngine *QQuickWorkerScript::engine() QQmlEngine *engine = qmlEngine(this); if (!engine) { qWarning("QQuickWorkerScript: engine() called without qmlEngine() set"); - return 0; + return nullptr; } m_engine = QQmlEnginePrivate::get(engine)->getWorkerScriptEngine(); @@ -718,7 +707,7 @@ QQuickWorkerScriptEngine *QQuickWorkerScript::engine() return m_engine; } - return 0; + return nullptr; } void QQuickWorkerScript::componentComplete() @@ -742,8 +731,7 @@ bool QQuickWorkerScript::event(QEvent *event) QQmlEngine *engine = qmlEngine(this); if (engine) { WorkerDataEvent *workerEvent = static_cast<WorkerDataEvent *>(event); - QV8Engine *v8engine = QQmlEnginePrivate::get(engine)->v8engine(); - QV4::Scope scope(QV8Engine::getV4(v8engine)); + QV4::Scope scope(engine->handle()); QV4::ScopedValue value(scope, QV4::Serialize::deserialize(workerEvent->data(), scope.engine)); emit message(QQmlV4Handle(value)); } |