diff options
author | Simon Hausmann <simon.hausmann@qt.io> | 2018-08-20 11:23:01 +0200 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@qt.io> | 2018-08-21 06:33:11 +0000 |
commit | 26e9c07650474a23817487e768bbebbb87bd78e4 (patch) | |
tree | a287f36b018be08ad1c75d0d41cfef0a305c0d52 /src/qml/jsruntime/qv4qmlcontext.cpp | |
parent | 3a7bd721edad972dd0691ff814b3417b4b5228a0 (diff) |
Clean up QML worker scripts part 2
Now that we have one JS engine per worker script, we can get rid of the
per-script QML context and let the script simply run in the global
object, which is now also mutable.
Change-Id: I36d8616b85b2c0ff3a356ee7be9d242c3da624cf
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src/qml/jsruntime/qv4qmlcontext.cpp')
-rw-r--r-- | src/qml/jsruntime/qv4qmlcontext.cpp | 53 |
1 files changed, 4 insertions, 49 deletions
diff --git a/src/qml/jsruntime/qv4qmlcontext.cpp b/src/qml/jsruntime/qv4qmlcontext.cpp index c8ef87b979..b69081d378 100644 --- a/src/qml/jsruntime/qv4qmlcontext.cpp +++ b/src/qml/jsruntime/qv4qmlcontext.cpp @@ -65,8 +65,6 @@ DEFINE_MANAGED_VTABLE(QmlContext); void Heap::QQmlContextWrapper::init(QQmlContextData *context, QObject *scopeObject) { Object::init(); - readOnly = true; - isNullWrapper = false; this->context = new QQmlContextDataRef(context); this->scopeObject.init(scopeObject); } @@ -89,9 +87,6 @@ ReturnedValue QQmlContextWrapper::virtualGet(const Managed *m, PropertyKey id, c QV4::ExecutionEngine *v4 = resource->engine(); QV4::Scope scope(v4); - if (resource->d()->isNullWrapper) - return Object::virtualGet(m, id, receiver, hasProperty); - if (v4->callingQmlContext() != *resource->d()->context) return Object::virtualGet(m, id, receiver, hasProperty); @@ -274,18 +269,6 @@ bool QQmlContextWrapper::virtualPut(Managed *m, PropertyKey id, const Value &val if (member < UINT_MAX) return wrapper->putValue(member, value); - if (wrapper->d()->isNullWrapper) { - if (wrapper && wrapper->d()->readOnly) { - QString error = QLatin1String("Invalid write to global property \"") + id.toQString() + - QLatin1Char('"'); - ScopedString e(scope, v4->newString(error)); - v4->throwError(e); - return false; - } - - return Object::virtualPut(m, id, value, receiver); - } - // It's possible we could delay the calculation of the "actual" context (in the case // of sub contexts) until it is definitely needed. QQmlContextData *context = wrapper->getContext(); @@ -321,14 +304,10 @@ bool QQmlContextWrapper::virtualPut(Managed *m, PropertyKey id, const Value &val expressionContext->unresolvedNames = true; - if (wrapper->d()->readOnly) { - QString error = QLatin1String("Invalid write to global property \"") + name->toQString() + - QLatin1Char('"'); - v4->throwError(error); - return false; - } - - return Object::virtualPut(m, id, value, receiver); + QString error = QLatin1String("Invalid write to global property \"") + name->toQString() + + QLatin1Char('"'); + v4->throwError(error); + return false; } void Heap::QmlContext::init(QV4::ExecutionContext *outerContext, QV4::QQmlContextWrapper *qml) @@ -339,30 +318,6 @@ void Heap::QmlContext::init(QV4::ExecutionContext *outerContext, QV4::QQmlContex this->activation.set(internalClass->engine, qml->d()); } -Heap::QmlContext *QmlContext::createWorkerContext(ExecutionContext *parent, const QUrl &source, Value *sendFunction) -{ - Scope scope(parent); - - QQmlContextData *context = new QQmlContextData; - context->baseUrl = source; - context->baseUrlString = source.toString(); - context->isInternal = true; - context->isJSContext = true; - - Scoped<QQmlContextWrapper> qml(scope, scope.engine->memoryManager->allocate<QQmlContextWrapper>(context, (QObject*)nullptr)); - qml->d()->isNullWrapper = true; - - qml->setReadOnly(false); - QV4::ScopedObject api(scope, scope.engine->newObject()); - api->put(QV4::ScopedString(scope, scope.engine->newString(QStringLiteral("sendMessage"))), *sendFunction); - qml->QV4::Object::put(QV4::ScopedString(scope, scope.engine->newString(QStringLiteral("WorkerScript"))), api); - qml->setReadOnly(true); - - Heap::QmlContext *c = scope.engine->memoryManager->alloc<QmlContext>(parent, qml); - Q_ASSERT(c->vtable() == staticVTable()); - return c; -} - Heap::QmlContext *QmlContext::create(ExecutionContext *parent, QQmlContextData *context, QObject *scopeObject) { Scope scope(parent); |