aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@digia.com>2013-06-03 16:41:14 +0200
committerLars Knoll <lars.knoll@digia.com>2013-06-03 20:41:04 +0200
commit5458d5103d6ebdffc31aed0f4c829f04320ecd9e (patch)
tree953935c6d2c398919f250bd28166faed749e5d88 /src/qml
parent94946e6fb412a34f1d0bd3bb550a8ff195976ee6 (diff)
Get rid of inner MethodClosure object in QV8QObjectWrapper
Instead let's have a convenient create function in QV4::QObjectMethod Change-Id: I7369e614993eebcf9cbb5bc186979dcaa2b2593c Reviewed-by: Lars Knoll <lars.knoll@digia.com>
Diffstat (limited to 'src/qml')
-rw-r--r--src/qml/qml/v8/qv8qobjectwrapper.cpp29
-rw-r--r--src/qml/qml/v8/qv8qobjectwrapper_p.h4
2 files changed, 13 insertions, 20 deletions
diff --git a/src/qml/qml/v8/qv8qobjectwrapper.cpp b/src/qml/qml/v8/qv8qobjectwrapper.cpp
index ed64b34ec1..c2987282c7 100644
--- a/src/qml/qml/v8/qv8qobjectwrapper.cpp
+++ b/src/qml/qml/v8/qv8qobjectwrapper.cpp
@@ -133,7 +133,7 @@ Value QObjectWrapper::getProperty(ExecutionContext *ctx, String *name, QObjectWr
if (!hasProp) {
int index = name->isEqualTo(m_destroy) ? QV4::QObjectMethod::DestroyMethod : QV4::QObjectMethod::ToStringMethod;
- method = QV4::Value::fromObject(new (ctx->engine->memoryManager) QV4::QObjectMethod(ctx->engine->rootContext, m_object, index, QV4::Value::undefinedValue()));
+ method = QV4::QObjectMethod::create(ctx->engine->rootContext, m_object, index);
QV4::Object::put(this, ctx, name, method);
}
@@ -512,21 +512,6 @@ QV4::Value QV8QObjectWrapper::GetProperty(QV8Engine *engine, QObject *object,
QQmlContextData *context,
QV4::QObjectWrapper::RevisionMode revisionMode)
{
- // XXX More recent versions of V8 introduced "Callable" objects. It is possible that these
- // will be a faster way of creating QObject method objects.
- struct MethodClosure {
- static QV4::Value create(QV8Engine *engine, QObject *object,
- int index) {
- QV4::ExecutionEngine *v4 = QV8Engine::getV4(engine);
- return QV4::Value::fromObject(new (v4->memoryManager) QV4::QObjectMethod(v4->rootContext, object, index, QV4::Value::undefinedValue()));
- }
- static QV4::Value createWithGlobal(QV8Engine *engine, QObject *object,
- int index) {
- QV4::ExecutionEngine *v4 = QV8Engine::getV4(engine);
- return QV4::Value::fromObject(new (v4->memoryManager) QV4::QObjectMethod(v4->rootContext, object, index, QV4::Value::fromObject(QV8Engine::getV4(engine)->qmlContextObject())));
- }
- };
-
if (QQmlData::wasDeleted(object))
return QV4::Value::emptyValue();
@@ -551,15 +536,16 @@ QV4::Value QV8QObjectWrapper::GetProperty(QV8Engine *engine, QObject *object,
return QV4::Value::emptyValue();
}
+ QV4::ExecutionEngine *v4 = QV8Engine::getV4(engine);
+
if (result->isFunction() && !result->isVarProperty()) {
if (result->isVMEFunction()) {
QQmlVMEMetaObject *vmemo = QQmlVMEMetaObject::get(object);
Q_ASSERT(vmemo);
return vmemo->vmeMethod(result->coreIndex);
} else if (result->isV4Function()) {
- return MethodClosure::createWithGlobal(engine, object, result->coreIndex);
+ return QV4::QObjectMethod::create(v4->rootContext, object, result->coreIndex, QV4::Value::fromObject(v4->qmlContextObject()));
} else if (result->isSignalHandler()) {
- QV4::ExecutionEngine *v4 = QV8Engine::getV4(engine);
QV4::QmlSignalHandler *handler = new (v4->memoryManager) QV4::QmlSignalHandler(v4, object, result->coreIndex);
QV4::String *connect = v4->newIdentifier(QStringLiteral("connect"));
@@ -569,7 +555,7 @@ QV4::Value QV8QObjectWrapper::GetProperty(QV8Engine *engine, QObject *object,
return QV4::Value::fromObject(handler);
} else {
- return MethodClosure::create(engine, object, result->coreIndex);
+ return QV4::QObjectMethod::create(v4->rootContext, object, result->coreIndex);
}
}
@@ -1838,6 +1824,11 @@ QV4::Value CallArgument::toValue(QV8Engine *engine)
}
}
+Value QObjectMethod::create(ExecutionContext *scope, QObject *object, int index, const Value &qmlGlobal)
+{
+ return Value::fromObject(new (scope->engine->memoryManager) QObjectMethod(scope, object, index, qmlGlobal));
+}
+
QObjectMethod::QObjectMethod(ExecutionContext *scope, QObject *object, int index, const Value &qmlGlobal)
: FunctionObject(scope)
, m_object(object)
diff --git a/src/qml/qml/v8/qv8qobjectwrapper_p.h b/src/qml/qml/v8/qv8qobjectwrapper_p.h
index f8d128fc57..c50fd461a6 100644
--- a/src/qml/qml/v8/qv8qobjectwrapper_p.h
+++ b/src/qml/qml/v8/qv8qobjectwrapper_p.h
@@ -119,12 +119,14 @@ struct QObjectMethod : public QV4::FunctionObject
enum { DestroyMethod = -1, ToStringMethod = -2 };
- QObjectMethod(QV4::ExecutionContext *scope, QObject *object, int index, const QV4::Value &qmlGlobal);
+ static Value create(QV4::ExecutionContext *scope, QObject *object, int index, const Value &qmlGlobal = Value::undefinedValue());
int methodIndex() const { return m_index; }
QObject *object() const { return m_object.data(); }
private:
+ QObjectMethod(QV4::ExecutionContext *scope, QObject *object, int index, const QV4::Value &qmlGlobal);
+
QV4::Value method_toString(QV4::ExecutionContext *ctx);
QV4::Value method_destroy(QV4::ExecutionContext *ctx, Value *args, int argc);