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 | |
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')
-rw-r--r-- | src/qml/jsruntime/qv4include.cpp | 2 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4qmlcontext.cpp | 53 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4qmlcontext_p.h | 5 |
3 files changed, 5 insertions, 55 deletions
diff --git a/src/qml/jsruntime/qv4include.cpp b/src/qml/jsruntime/qv4include.cpp index d0d66c9b9a..e3e16fa070 100644 --- a/src/qml/jsruntime/qv4include.cpp +++ b/src/qml/jsruntime/qv4include.cpp @@ -207,7 +207,7 @@ QV4::ReturnedValue QV4Include::method_include(const QV4::FunctionObject *b, cons QQmlContextData *context = scope.engine->callingQmlContext(); - if (!context || !context->isJSContext) + if ((!context || !context->isJSContext) && scope.engine->qmlEngine()) RETURN_RESULT(scope.engine->throwError(QString::fromUtf8("Qt.include(): Can only be called from JavaScript files"))); QV4::ScopedValue callbackFunction(scope, QV4::Primitive::undefinedValue()); 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); diff --git a/src/qml/jsruntime/qv4qmlcontext_p.h b/src/qml/jsruntime/qv4qmlcontext_p.h index b9061a3f58..4fe34a0a06 100644 --- a/src/qml/jsruntime/qv4qmlcontext_p.h +++ b/src/qml/jsruntime/qv4qmlcontext_p.h @@ -69,8 +69,6 @@ namespace Heap { struct QQmlContextWrapper : Object { void init(QQmlContextData *context, QObject *scopeObject); void destroy(); - bool readOnly; - bool isNullWrapper; QQmlContextDataRef *context; QQmlQPointer<QObject> scopeObject; @@ -96,8 +94,6 @@ struct Q_QML_EXPORT QQmlContextWrapper : Object inline QObject *getScopeObject() const { return d()->scopeObject; } inline QQmlContextData *getContext() const { return *d()->context; } - void setReadOnly(bool b) { d()->readOnly = b; } - static ReturnedValue virtualGet(const Managed *m, PropertyKey id, const Value *receiver, bool *hasProperty); static bool virtualPut(Managed *m, PropertyKey id, const Value &value, Value *receiver); }; @@ -107,7 +103,6 @@ struct Q_QML_EXPORT QmlContext : public ExecutionContext V4_MANAGED(QmlContext, ExecutionContext) V4_INTERNALCLASS(QmlContext) - static Heap::QmlContext *createWorkerContext(QV4::ExecutionContext *parent, const QUrl &source, Value *sendFunction); static Heap::QmlContext *create(QV4::ExecutionContext *parent, QQmlContextData *context, QObject *scopeObject); QObject *qmlScope() const { |