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;
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);
}
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) {
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) {
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
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
#include <private/qv4functionobject_p.h>
#include <private/qv4script_p.h>
#include <private/qv4context_p.h>
+#include <private/qqmlcontextwrapper_p.h>
QT_BEGIN_NAMESPACE
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");