aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/qml/qml/qqmlcontextwrapper.cpp33
-rw-r--r--src/qml/qml/qqmlcontextwrapper_p.h14
-rw-r--r--src/qml/qml/v4/qv4include.cpp3
-rw-r--r--src/qml/types/qquickworkerscript.cpp2
4 files changed, 21 insertions, 31 deletions
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<QmlContextWrapper *>(that)->~QmlContextWrapper();
}
-void QmlContextNullWrapper::put(Managed *m, ExecutionContext *ctx, String *name, const Value &value)
-{
- QmlContextWrapper *w = m->as<QmlContextWrapper>();
- 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<QObject> 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 <private/qv4functionobject_p.h>
#include <private/qv4script_p.h>
#include <private/qv4context_p.h>
+#include <private/qqmlcontextwrapper_p.h>
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::QmlContextNullWrapper>();
+ QV4::QmlContextWrapper *w = script->object.value().asObject()->as<QV4::QmlContextWrapper>();
w->setReadOnly(false);
QV4::Object *api = v4->newObject();