From e14b9dbee1260f799d1d2e175d106dbed79b6c49 Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Fri, 31 May 2013 13:05:37 +0200 Subject: Start converting casting of Managed to subtypes to a better scheme There is now a template based as() method available in Managed, that'll allow casting to the proper subclass. It uses the pointer to the vtable and compares it to the classes static vtable for type checking. Like this we can avoid that Managed has to know about all subclasses. Change-Id: Ic966bbe00d85224b8d96cc0ff00f69a6ac67129e Reviewed-by: Simon Hausmann --- src/qml/qml/qqmlcontextwrapper_p.h | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'src/qml/qml/qqmlcontextwrapper_p.h') diff --git a/src/qml/qml/qqmlcontextwrapper_p.h b/src/qml/qml/qqmlcontextwrapper_p.h index a8df7ba2b6..41026eed32 100644 --- a/src/qml/qml/qqmlcontextwrapper_p.h +++ b/src/qml/qml/qqmlcontextwrapper_p.h @@ -66,6 +66,7 @@ namespace QV4 { struct Q_QML_EXPORT QmlContextWrapper : Object { + Q_MANAGED QmlContextWrapper(QV8Engine *engine, QQmlContextData *context, QObject *scopeObject, bool ownsContext = false); ~QmlContextWrapper(); @@ -92,9 +93,19 @@ struct Q_QML_EXPORT QmlContextWrapper : Object QQmlGuardedContextData context; QQmlGuard scopeObject; +}; -private: - const static ManagedVTable static_vtbl; +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); }; } -- cgit v1.2.3