Use the QmlContext as the scope for QQmlV4Function calls

This further reduces our dependency on the QQmlContextWrapper
and reduces storage requirements in the QObjectMethod.

Change-Id: I2c12d0a8818d81d45139f482caac8510ad8dfddc
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
This commit is contained in:
Lars Knoll 2015-08-12 12:15:47 +02:00
parent 6dda1b4258
commit cc98678f40
4 changed files with 14 additions and 24 deletions

View File

@ -333,9 +333,8 @@ ReturnedValue QObjectWrapper::getProperty(ExecutionEngine *engine, QObject *obje
Q_ASSERT(vmemo);
return vmemo->vmeMethod(property->coreIndex);
} else if (property->isV4Function()) {
QV4::ScopedObject qmlcontextobject(scope, engine->qmlContextObject());
ScopedContext global(scope, scope.engine->rootContext());
return QV4::QObjectMethod::create(global, object, property->coreIndex, qmlcontextobject);
ScopedContext global(scope, scope.engine->qmlContext());
return QV4::QObjectMethod::create(global, object, property->coreIndex);
} else if (property->isSignalHandler()) {
QV4::Scoped<QV4::QmlSignalHandler> handler(scope, scope.engine->memoryManager->alloc<QV4::QmlSignalHandler>(engine, object, property->coreIndex));
@ -1726,7 +1725,7 @@ QV4::ReturnedValue CallArgument::toValue(QV4::ExecutionEngine *engine)
}
}
ReturnedValue QObjectMethod::create(ExecutionContext *scope, QObject *object, int index, const Value &qmlGlobal)
ReturnedValue QObjectMethod::create(ExecutionContext *scope, QObject *object, int index)
{
Scope valueScope(scope);
Scoped<QObjectMethod> method(valueScope, scope->d()->engine->memoryManager->alloc<QObjectMethod>(scope));
@ -1736,18 +1735,16 @@ ReturnedValue QObjectMethod::create(ExecutionContext *scope, QObject *object, in
method->d()->propertyCache = ddata->propertyCache;
method->d()->index = index;
method->d()->qmlGlobal = qmlGlobal;
method->d()->valueTypeWrapper = Primitive::undefinedValue();
return method.asReturnedValue();
}
ReturnedValue QObjectMethod::create(ExecutionContext *scope, const QQmlValueTypeWrapper *valueType, int index, const Value &qmlGlobal)
ReturnedValue QObjectMethod::create(ExecutionContext *scope, const QQmlValueTypeWrapper *valueType, int index)
{
Scope valueScope(scope);
Scoped<QObjectMethod> method(valueScope, scope->d()->engine->memoryManager->alloc<QObjectMethod>(scope));
method->d()->propertyCache = valueType->d()->propertyCache;
method->d()->index = index;
method->d()->qmlGlobal = qmlGlobal;
method->d()->valueTypeWrapper = *valueType;
return method.asReturnedValue();
}
@ -1863,11 +1860,7 @@ ReturnedValue QObjectMethod::callInternal(CallData *callData) const
if (method.isV4Function()) {
QV4::ScopedValue rv(scope, QV4::Primitive::undefinedValue());
QV4::ScopedValue qmlGlobal(scope, d()->qmlGlobal);
QQmlV4Function func(callData, rv, qmlGlobal,
QmlContextWrapper::getContext(qmlGlobal),
scope.engine);
QQmlV4Function func(callData, rv, scope.engine);
QQmlV4Function *funcptr = &func;
void *args[] = { 0, &funcptr };
@ -1886,7 +1879,6 @@ ReturnedValue QObjectMethod::callInternal(CallData *callData) const
void QObjectMethod::markObjects(Heap::Base *that, ExecutionEngine *e)
{
QObjectMethod::Data *This = static_cast<QObjectMethod::Data*>(that);
This->qmlGlobal.mark(e);
This->valueTypeWrapper.mark(e);
FunctionObject::markObjects(that, e);

View File

@ -79,7 +79,6 @@ struct QObjectMethod : FunctionObject {
QPointer<QObject> object;
QQmlRefPointer<QQmlPropertyCache> propertyCache;
int index;
Value qmlGlobal;
Value valueTypeWrapper;
@ -149,8 +148,8 @@ struct Q_QML_EXPORT QObjectMethod : public QV4::FunctionObject
enum { DestroyMethod = -1, ToStringMethod = -2 };
static ReturnedValue create(QV4::ExecutionContext *scope, QObject *object, int index, const Value &qmlGlobal = Primitive::undefinedValue());
static ReturnedValue create(QV4::ExecutionContext *scope, const QQmlValueTypeWrapper *valueType, int index, const Value &qmlGlobal = Primitive::undefinedValue());
static ReturnedValue create(QV4::ExecutionContext *scope, QObject *object, int index);
static ReturnedValue create(QV4::ExecutionContext *scope, const QQmlValueTypeWrapper *valueType, int index);
int methodIndex() const { return d()->index; }
QObject *object() const { return d()->object.data(); }

View File

@ -379,7 +379,7 @@ ReturnedValue Script::qmlBinding()
return v.asReturnedValue();
}
QV4::ReturnedValue Script::evaluate(ExecutionEngine *engine, const QString &script, Object *scopeObject)
QV4::ReturnedValue Script::evaluate(ExecutionEngine *engine, const QString &script, Object *scopeObject)
{
QV4::Scope scope(engine);
QV4::Script qmlScript(engine, scopeObject, script, QString());

View File

@ -63,6 +63,7 @@
#include <private/qv4value_p.h>
#include <private/qv4object_p.h>
#include <private/qv4identifier_p.h>
#include <private/qqmlcontextwrapper_p.h>
QT_BEGIN_NAMESPACE
@ -119,8 +120,8 @@ class QQmlV4Function
public:
int length() const { return callData->argc; }
QV4::ReturnedValue operator[](int idx) { return (idx < callData->argc ? callData->args[idx].asReturnedValue() : QV4::Encode::undefined()); }
QQmlContextData *context() { return ctx; }
QV4::ReturnedValue qmlGlobal() { return callData->thisObject.asReturnedValue(); }
QQmlContextData *context() { return e->qmlContextObject()->context.contextData(); }
QV4::ReturnedValue qmlGlobal() { return e->qmlContextObject()->asReturnedValue(); }
void setReturnValue(QV4::ReturnedValue rv) { *retVal = rv; }
QV4::ExecutionEngine *v4engine() const { return e; }
private:
@ -129,16 +130,14 @@ private:
QQmlV4Function(const QQmlV4Function &);
QQmlV4Function &operator=(const QQmlV4Function &);
QQmlV4Function(QV4::CallData *callData, QV4::Value *retVal,
const QV4::Value &global, QQmlContextData *c, QV4::ExecutionEngine *e)
: callData(callData), retVal(retVal), ctx(c), e(e)
QQmlV4Function(QV4::CallData *callData, QV4::Value *retVal, QV4::ExecutionEngine *e)
: callData(callData), retVal(retVal), e(e)
{
callData->thisObject = QV4::Value::fromReturnedValue(global.asReturnedValue());
callData->thisObject = QV4::Encode::undefined();
}
QV4::CallData *callData;
QV4::Value *retVal;
QQmlContextData *ctx;
QV4::ExecutionEngine *e;
};