From 1075939a2b040aec3f63a20f27e4f9e502eabc97 Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Tue, 18 Jun 2013 12:48:08 +0200 Subject: Fix parts of workerscript The worker script creates a special QmlContextWrapper that doesn't contain many things found in the main thread. However we still need to be able to cast to it, so it should be the same class as the regular context wrapper. Fixes parts of the worker script auto tests. Change-Id: I3697b2b0080dc4ac967eb447e2efd0f28fbab465 Reviewed-by: Simon Hausmann --- src/qml/qml/qqmlcontextwrapper.cpp | 33 +++++++++++++++++---------------- src/qml/qml/qqmlcontextwrapper_p.h | 14 +------------- src/qml/qml/v4/qv4include.cpp | 3 ++- src/qml/types/qquickworkerscript.cpp | 2 +- 4 files changed, 21 insertions(+), 31 deletions(-) (limited to 'src') diff --git a/src/qml/qml/qqmlcontextwrapper.cpp b/src/qml/qml/qqmlcontextwrapper.cpp index 5507c8b966..6bdcda9ca6 100644 --- a/src/qml/qml/qqmlcontextwrapper.cpp +++ b/src/qml/qml/qqmlcontextwrapper.cpp @@ -58,11 +58,10 @@ QT_BEGIN_NAMESPACE using namespace QV4; DEFINE_MANAGED_VTABLE(QmlContextWrapper); -DEFINE_MANAGED_VTABLE(QmlContextNullWrapper); QmlContextWrapper::QmlContextWrapper(QV8Engine *engine, QQmlContextData *context, QObject *scopeObject, bool ownsContext) : Object(QV8Engine::getV4(engine)), - v8(engine), readOnly(true), ownsContext(ownsContext), + v8(engine), readOnly(true), ownsContext(ownsContext), isNullWrapper(false), context(context), scopeObject(scopeObject) { vtbl = &static_vtbl; @@ -92,7 +91,8 @@ QV4::Value QmlContextWrapper::urlScope(QV8Engine *v8, const QUrl &url) context->isInternal = true; context->isJSContext = true; - QmlContextWrapper *w = new (v4->memoryManager) QmlContextNullWrapper(v8, context, 0); + QmlContextWrapper *w = new (v4->memoryManager) QmlContextWrapper(v8, context, 0); + w->isNullWrapper = true; w->prototype = v4->objectPrototype; return Value::fromObject(w); } @@ -132,6 +132,9 @@ Value QmlContextWrapper::get(Managed *m, ExecutionContext *ctx, String *name, bo if (!resource) ctx->throwTypeError(); + if (resource->isNullWrapper) + return Object::get(m, ctx, name, hasProperty); + bool hasProp; Value result = Object::get(m, ctx, name, &hasProp); if (hasProp) { @@ -264,6 +267,17 @@ void QmlContextWrapper::put(Managed *m, ExecutionContext *ctx, String *name, con if (!wrapper) ctx->throwTypeError(); + if (wrapper->isNullWrapper) { + if (wrapper && wrapper->readOnly) { + QString error = QLatin1String("Invalid write to global property \"") + name->toQString() + + QLatin1Char('"'); + ctx->throwError(Value::fromString(ctx->engine->newString(error))); + } + + Object::put(m, ctx, name, value); + return; + } + PropertyAttributes attrs; Property *pd = wrapper->__getOwnProperty__(name, &attrs); if (pd) { @@ -321,17 +335,4 @@ void QmlContextWrapper::destroy(Managed *that) static_cast(that)->~QmlContextWrapper(); } -void QmlContextNullWrapper::put(Managed *m, ExecutionContext *ctx, String *name, const Value &value) -{ - QmlContextWrapper *w = m->as(); - if (w && w->readOnly) { - QString error = QLatin1String("Invalid write to global property \"") + name->toQString() + - QLatin1Char('"'); - ctx->throwError(Value::fromString(ctx->engine->newString(error))); - } - - Object::put(m, ctx, name, value); -} - - QT_END_NAMESPACE diff --git a/src/qml/qml/qqmlcontextwrapper_p.h b/src/qml/qml/qqmlcontextwrapper_p.h index 41026eed32..1ef8f7476d 100644 --- a/src/qml/qml/qqmlcontextwrapper_p.h +++ b/src/qml/qml/qqmlcontextwrapper_p.h @@ -90,24 +90,12 @@ struct Q_QML_EXPORT QmlContextWrapper : Object QV8Engine *v8; // ### temporary, remove bool readOnly; bool ownsContext; + bool isNullWrapper; QQmlGuardedContextData context; QQmlGuard scopeObject; }; -struct QmlContextNullWrapper : QmlContextWrapper -{ - Q_MANAGED - QmlContextNullWrapper(QV8Engine *engine, QQmlContextData *context, QObject *scopeObject, bool ownsContext = false) - : QmlContextWrapper(engine, context, scopeObject, ownsContext) - { - vtbl = &static_vtbl; - } - - using Object::get; - static void put(Managed *m, ExecutionContext *ctx, String *name, const Value &value); -}; - } QT_END_NAMESPACE diff --git a/src/qml/qml/v4/qv4include.cpp b/src/qml/qml/v4/qv4include.cpp index 0718f9bc8b..35ccb14644 100644 --- a/src/qml/qml/v4/qv4include.cpp +++ b/src/qml/qml/v4/qv4include.cpp @@ -52,6 +52,7 @@ #include #include #include +#include QT_BEGIN_NAMESPACE @@ -173,7 +174,7 @@ QV4::Value QV4Include::include(QV4::SimpleCallContext *ctx) QV4::ExecutionEngine *v4 = ctx->engine; QV8Engine *engine = v4->v8Engine; - QQmlContextData *context = engine->callingContext(); + QQmlContextData *context = QV4::QmlContextWrapper::callingContext(v4); if (!context || !context->isJSContext) V4THROW_ERROR("Qt.include(): Can only be called from JavaScript files"); diff --git a/src/qml/types/qquickworkerscript.cpp b/src/qml/types/qquickworkerscript.cpp index f832cb8008..825ab6ba1f 100644 --- a/src/qml/types/qquickworkerscript.cpp +++ b/src/qml/types/qquickworkerscript.cpp @@ -300,7 +300,7 @@ QV4::Value QQuickWorkerScriptEnginePrivate::getWorker(WorkerScript *script) script->object = QV4::QmlContextWrapper::urlScope(workerEngine, script->source); - QV4::QmlContextWrapper *w = script->object.value().asObject()->as(); + QV4::QmlContextWrapper *w = script->object.value().asObject()->as(); w->setReadOnly(false); QV4::Object *api = v4->newObject(); -- cgit v1.2.3