diff options
author | Lars Knoll <lars.knoll@digia.com> | 2013-05-30 13:45:23 +0200 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@digia.com> | 2013-05-30 16:42:25 +0200 |
commit | ca7ddc345ec4df017b7db6aee5a823f817e6e708 (patch) | |
tree | 170cd6efba1028f867e15cb2dce160f3639d2395 /src/qml/qml | |
parent | 35ab04c907a1cefa23eff2d7c853350fb5d27178 (diff) |
Cleanup the context wrapper code
Remove the QV8ContextWrapper class and move the code out
of the v8 directory.
Change-Id: I00c02f7310a3e43bd105c5bc5af034ce652cfd49
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Diffstat (limited to 'src/qml/qml')
-rw-r--r-- | src/qml/qml/qml.pri | 2 | ||||
-rw-r--r-- | src/qml/qml/qqmlcontextwrapper.cpp (renamed from src/qml/qml/v8/qv8contextwrapper.cpp) | 154 | ||||
-rw-r--r-- | src/qml/qml/qqmlcontextwrapper_p.h (renamed from src/qml/qml/v8/qv8contextwrapper_p.h) | 49 | ||||
-rw-r--r-- | src/qml/qml/qqmljavascriptexpression.cpp | 5 | ||||
-rw-r--r-- | src/qml/qml/qqmltypewrapper.cpp | 2 | ||||
-rw-r--r-- | src/qml/qml/qqmlvme.cpp | 5 | ||||
-rw-r--r-- | src/qml/qml/qqmlxmlhttprequest.cpp | 5 | ||||
-rw-r--r-- | src/qml/qml/v8/qv8engine.cpp | 6 | ||||
-rw-r--r-- | src/qml/qml/v8/qv8engine_p.h | 11 | ||||
-rw-r--r-- | src/qml/qml/v8/qv8qobjectwrapper.cpp | 4 | ||||
-rw-r--r-- | src/qml/qml/v8/v8.pri | 2 |
11 files changed, 98 insertions, 147 deletions
diff --git a/src/qml/qml/qml.pri b/src/qml/qml/qml.pri index fbd738b22c..ae73265ad7 100644 --- a/src/qml/qml/qml.pri +++ b/src/qml/qml/qml.pri @@ -52,6 +52,7 @@ SOURCES += \ $$PWD/qqmlplatform.cpp \ $$PWD/qqmlbinding.cpp \ $$PWD/qqmlapplicationengine.cpp \ + $$PWD/qqmlcontextwrapper.cpp \ $$PWD/qqmltypewrapper.cpp HEADERS += \ @@ -126,6 +127,7 @@ HEADERS += \ $$PWD/qqmlextensionplugin_p.h \ $$PWD/qqmlapplicationengine_p.h \ $$PWD/qqmlapplicationengine.h \ + $$PWD/qqmlcontextwrapper_p.h \ $$PWD/qqmltypewrapper_p.h JS_CLASS_SOURCES += \ diff --git a/src/qml/qml/v8/qv8contextwrapper.cpp b/src/qml/qml/qqmlcontextwrapper.cpp index b5f75f79f8..493d55a30f 100644 --- a/src/qml/qml/v8/qv8contextwrapper.cpp +++ b/src/qml/qml/qqmlcontextwrapper.cpp @@ -39,8 +39,8 @@ ** ****************************************************************************/ -#include "qv8contextwrapper_p.h" -#include "qv8engine_p.h" +#include "qqmlcontextwrapper_p.h" +#include <private/qv8engine_p.h> #include <private/qqmlengine_p.h> #include <private/qqmlcontext_p.h> @@ -56,29 +56,6 @@ QT_BEGIN_NAMESPACE namespace QV4 { -struct Q_QML_EXPORT QmlContextWrapper : Object -{ - QmlContextWrapper(QV8Engine *engine, QQmlContextData *context, QObject *scopeObject, bool ownsContext = false); - ~QmlContextWrapper(); - - inline QObject *getScopeObject() const { return scopeObject; } - inline QQmlContextData *getContext() const { return context; } - - QV8Engine *v8; // ### temporary, remove - bool readOnly; - bool ownsContext; - - QQmlGuardedContextData context; - QQmlGuard<QObject> scopeObject; - - static Value get(Managed *m, ExecutionContext *ctx, String *name, bool *hasProperty); - static void put(Managed *m, ExecutionContext *ctx, String *name, const Value &value); - static void destroy(Managed *that); - -private: - const static ManagedVTable static_vtbl; -}; - struct QmlContextNullWrapper : QmlContextWrapper { QmlContextNullWrapper(QV8Engine *engine, QQmlContextData *context, QObject *scopeObject, bool ownsContext = false) @@ -116,6 +93,58 @@ QmlContextWrapper::~QmlContextWrapper() context->destroy(); } +QV4::Value QmlContextWrapper::qmlScope(QV8Engine *v8, QQmlContextData *ctxt, QObject *scope) +{ + ExecutionEngine *v4 = QV8Engine::getV4(v8); + + QmlContextWrapper *w = new (v4->memoryManager) QmlContextWrapper(v8, ctxt, scope); + w->prototype = v4->objectPrototype; + return Value::fromObject(w); +} + +QV4::Value QmlContextWrapper::urlScope(QV8Engine *v8, const QUrl &url) +{ + ExecutionEngine *v4 = QV8Engine::getV4(v8); + + QQmlContextData *context = new QQmlContextData; + context->url = url; + context->isInternal = true; + context->isJSContext = true; + + QmlContextWrapper *w = new (v4->memoryManager) QmlContextNullWrapper(v8, context, 0); + w->prototype = v4->objectPrototype; + return Value::fromObject(w); +} + +QQmlContextData *QmlContextWrapper::callingContext(ExecutionEngine *v4) +{ + QV4::Object *qmlglobal = v4->qmlContextObject(); + if (!qmlglobal) + return 0; + + QmlContextWrapper *c = qmlglobal->asQmlContext(); + return c ? c->getContext() : 0; +} + +QQmlContextData *QmlContextWrapper::getContext(const Value &value) +{ + Object *o = value.asObject(); + QmlContextWrapper *c = o ? o->asQmlContext() : 0; + if (!c) + return 0; + + return c ? c->getContext():0; +} + +void QmlContextWrapper::takeContextOwnership(const Value &qmlglobal) +{ + Object *o = qmlglobal.asObject(); + QmlContextWrapper *c = o ? o->asQmlContext() : 0; + assert(c); + c->ownsContext = true; +} + + Value QmlContextWrapper::get(Managed *m, ExecutionContext *ctx, String *name, bool *hasProperty) { QmlContextWrapper *resource = m->asQmlContext(); @@ -331,79 +360,4 @@ void QmlContextNullWrapper::put(Managed *m, ExecutionContext *ctx, String *name, } - -QV8ContextWrapper::QV8ContextWrapper() - : m_engine(0), v4(0) -{ -} - -QV8ContextWrapper::~QV8ContextWrapper() -{ -} - -void QV8ContextWrapper::destroy() -{ -} - -void QV8ContextWrapper::init(QV8Engine *engine) -{ - m_engine = engine; - v4 = QV8Engine::getV4(engine); -} - -QV4::Value QV8ContextWrapper::qmlScope(QQmlContextData *ctxt, QObject *scope) -{ - QmlContextWrapper *w = new (v4->memoryManager) QmlContextWrapper(m_engine, ctxt, scope); - w->prototype = v4->objectPrototype; - return Value::fromObject(w); -} - -QV4::Value QV8ContextWrapper::urlScope(const QUrl &url) -{ - QQmlContextData *context = new QQmlContextData; - context->url = url; - context->isInternal = true; - context->isJSContext = true; - - QmlContextWrapper *w = new (v4->memoryManager) QmlContextNullWrapper(m_engine, context, 0); - w->prototype = v4->objectPrototype; - return Value::fromObject(w); -} - -void QV8ContextWrapper::setReadOnly(const Value &qmlglobal, bool readOnly) -{ - Object *o = qmlglobal.asObject(); - QmlContextWrapper *c = o ? o->asQmlContext() : 0; - assert(c); - c->readOnly = readOnly; -} - -QQmlContextData *QV8ContextWrapper::callingContext() -{ - QV4::Object *qmlglobal = QV8Engine::getV4(m_engine)->qmlContextObject(); - if (!qmlglobal) - return 0; - - QmlContextWrapper *c = qmlglobal->asQmlContext(); - return c ? c->getContext() : 0; -} - -QQmlContextData *QV8ContextWrapper::context(const Value &value) -{ - Object *o = value.asObject(); - QmlContextWrapper *c = o ? o->asQmlContext() : 0; - if (!c) - return 0; - - return c ? c->getContext():0; -} - -void QV8ContextWrapper::takeContextOwnership(const Value &qmlglobal) -{ - Object *o = qmlglobal.asObject(); - QmlContextWrapper *c = o ? o->asQmlContext() : 0; - assert(c); - c->ownsContext = true; -} - QT_END_NAMESPACE diff --git a/src/qml/qml/v8/qv8contextwrapper_p.h b/src/qml/qml/qqmlcontextwrapper_p.h index 1ed77f9839..a8df7ba2b6 100644 --- a/src/qml/qml/v8/qv8contextwrapper_p.h +++ b/src/qml/qml/qqmlcontextwrapper_p.h @@ -39,8 +39,8 @@ ** ****************************************************************************/ -#ifndef QV8CONTEXTWRAPPER_P_H -#define QV8CONTEXTWRAPPER_P_H +#ifndef QQMLCONTEXTWRAPPER_P_H +#define QQMLCONTEXTWRAPPER_P_H // // W A R N I N G @@ -55,7 +55,6 @@ #include <QtCore/qglobal.h> #include <private/qtqmlglobal_p.h> -#include <private/qv8_p.h> #include <private/qv4value_p.h> #include <private/qv4object_p.h> @@ -63,34 +62,42 @@ QT_BEGIN_NAMESPACE -class QUrl; -class QObject; -class QV8Engine; -class QQmlContextData; -class Q_QML_PRIVATE_EXPORT QV8ContextWrapper +namespace QV4 { + +struct Q_QML_EXPORT QmlContextWrapper : Object { -public: - QV8ContextWrapper(); - ~QV8ContextWrapper(); + QmlContextWrapper(QV8Engine *engine, QQmlContextData *context, QObject *scopeObject, bool ownsContext = false); + ~QmlContextWrapper(); + + static QV4::Value qmlScope(QV8Engine *e, QQmlContextData *ctxt, QObject *scope); + static QV4::Value urlScope(QV8Engine *e, const QUrl &); + + static QQmlContextData *callingContext(ExecutionEngine *v4); + static void takeContextOwnership(const QV4::Value &qmlglobal); + + inline QObject *getScopeObject() const { return scopeObject; } + inline QQmlContextData *getContext() const { return context; } + static QQmlContextData *getContext(const Value &value); - void init(QV8Engine *); - void destroy(); + void setReadOnly(bool b) { readOnly = b; } - QV4::Value qmlScope(QQmlContextData *ctxt, QObject *scope); - QV4::Value urlScope(const QUrl &); + static Value get(Managed *m, ExecutionContext *ctx, String *name, bool *hasProperty); + static void put(Managed *m, ExecutionContext *ctx, String *name, const Value &value); + static void destroy(Managed *that); - void setReadOnly(const QV4::Value &, bool); - QQmlContextData *callingContext(); - QQmlContextData *context(const QV4::Value &); + QV8Engine *v8; // ### temporary, remove + bool readOnly; + bool ownsContext; - void takeContextOwnership(const QV4::Value &qmlglobal); + QQmlGuardedContextData context; + QQmlGuard<QObject> scopeObject; private: - QV8Engine *m_engine; - QV4::ExecutionEngine *v4; + const static ManagedVTable static_vtbl; }; +} QT_END_NAMESPACE diff --git a/src/qml/qml/qqmljavascriptexpression.cpp b/src/qml/qml/qqmljavascriptexpression.cpp index 81d5f237b5..1d4bba66d2 100644 --- a/src/qml/qml/qqmljavascriptexpression.cpp +++ b/src/qml/qml/qqmljavascriptexpression.cpp @@ -42,6 +42,7 @@ #include "qqmljavascriptexpression_p.h" #include <private/qqmlexpression_p.h> +#include <private/qqmlcontextwrapper_p.h> #include <private/qv4value_p.h> #include <private/qv4functionobject_p.h> #include <private/qv4script_p.h> @@ -311,7 +312,7 @@ QQmlJavaScriptExpression::evalFunction(QQmlContextData *ctxt, QObject *scope, QV4::ExecutionEngine *v4 = QV8Engine::getV4(ep->v8engine()); QV4::ExecutionContext *ctx = v4->current; - QV4::Value scopeObject = ep->v8engine()->qmlScope(ctxt, scope); + QV4::Value scopeObject = QV4::QmlContextWrapper::qmlScope(ep->v8engine(), ctxt, scope); QV4::Script script(v4, scopeObject.asObject(), code, filename, line); QV4::Value result; try { @@ -345,7 +346,7 @@ QV4::PersistentValue QQmlJavaScriptExpression::qmlBinding(QQmlContextData *ctxt, QV4::ExecutionEngine *v4 = QV8Engine::getV4(ep->v8engine()); QV4::ExecutionContext *ctx = v4->current; - QV4::Value scopeObject = ep->v8engine()->qmlScope(ctxt, scope); + QV4::Value scopeObject = QV4::QmlContextWrapper::qmlScope(ep->v8engine(), ctxt, scope); QV4::Script script(v4, scopeObject.asObject(), code, filename, line); QV4::Value result; try { diff --git a/src/qml/qml/qqmltypewrapper.cpp b/src/qml/qml/qqmltypewrapper.cpp index 322a7e31c4..6d464405f5 100644 --- a/src/qml/qml/qqmltypewrapper.cpp +++ b/src/qml/qml/qqmltypewrapper.cpp @@ -40,7 +40,7 @@ ****************************************************************************/ #include "qqmltypewrapper_p.h" -#include <private/qv8contextwrapper_p.h> +#include <private/qqmlcontextwrapper_p.h> #include <private/qv8engine_p.h> #include <private/qqmlengine_p.h> diff --git a/src/qml/qml/qqmlvme.cpp b/src/qml/qml/qqmlvme.cpp index 192fc6fd12..1fc9a7eee0 100644 --- a/src/qml/qml/qqmlvme.cpp +++ b/src/qml/qml/qqmlvme.cpp @@ -64,6 +64,7 @@ #include "qqmlpropertyvalueinterceptor_p.h" #include "qqmlvaluetypeproxybinding_p.h" #include "qqmlexpression_p.h" +#include "qqmlcontextwrapper_p.h" #include <QStack> #include <QPointF> @@ -1153,8 +1154,8 @@ QV4::PersistentValue QQmlVME::run(QQmlContextData *parentCtxt, QQmlScriptData *s if (!script->m_program) return QV4::PersistentValue(); - QV4::Value qmlglobal = v8engine->qmlScope(ctxt, 0); - v8engine->contextWrapper()->takeContextOwnership(qmlglobal); + QV4::Value qmlglobal = QV4::QmlContextWrapper::qmlScope(v8engine, ctxt, 0); + QV4::QmlContextWrapper::takeContextOwnership(qmlglobal); QV4::ExecutionContext *ctx = QV8Engine::getV4(v8engine)->current; try { diff --git a/src/qml/qml/qqmlxmlhttprequest.cpp b/src/qml/qml/qqmlxmlhttprequest.cpp index 8448e8dd16..60968f55d2 100644 --- a/src/qml/qml/qqmlxmlhttprequest.cpp +++ b/src/qml/qml/qqmlxmlhttprequest.cpp @@ -52,6 +52,7 @@ #include <private/qv4domerrors_p.h> #include <private/qv4engine_p.h> #include <private/qv4functionobject_p.h> +#include <private/qqmlcontextwrapper_p.h> #include <QtCore/qobject.h> #include <QtQml/qjsvalue.h> @@ -107,7 +108,7 @@ static v8::Handle<v8::Object> constructMeObject(v8::Handle<v8::Object> thisObj, { v8::Handle<v8::Object> meObj = v8::Object::New(); meObj->Set(v8::String::New("ThisObject"), thisObj); - meObj->Set(v8::String::New("ActivationObject"), e->qmlScope(e->callingContext(), 0)); + meObj->Set(v8::String::New("ActivationObject"), QV4::QmlContextWrapper::qmlScope(e, e->callingContext(), 0)); return meObj; } @@ -1464,7 +1465,7 @@ void QQmlXMLHttpRequest::dispatchCallback(const QV4::Value &me) return; } - QQmlContextData *callingContext = engine->contextWrapper()->context(activationObject); + QQmlContextData *callingContext = QV4::QmlContextWrapper::getContext(activationObject); if (callingContext) callback->call(v4->current, activationObject, 0, 0); diff --git a/src/qml/qml/v8/qv8engine.cpp b/src/qml/qml/v8/qv8engine.cpp index 272a7f0309..b359ff0d48 100644 --- a/src/qml/qml/v8/qv8engine.cpp +++ b/src/qml/qml/v8/qv8engine.cpp @@ -41,7 +41,6 @@ #include "qv8engine_p.h" -#include "qv8contextwrapper_p.h" #include "qv8valuetypewrapper_p.h" #include "qv4sequenceobject_p.h" #include "qjsengine_p.h" @@ -56,6 +55,7 @@ #include <private/qqmlplatform_p.h> #include <private/qjsvalue_p.h> #include <private/qqmltypewrapper_p.h> +#include <private/qqmlcontextwrapper_p.h> #include "qv4domerrors_p.h" #include "qv4sqlerrors_p.h" @@ -152,7 +152,6 @@ QV8Engine::QV8Engine(QJSEngine* qq) m_bindingFlagKey = QV4::Value::fromString(m_v4Engine->current, QStringLiteral("qml::binding")); - m_contextWrapper.init(this); m_qobjectWrapper.init(this); m_listWrapper.init(this); m_valueTypeWrapper.init(this); @@ -175,7 +174,6 @@ QV8Engine::~QV8Engine() m_valueTypeWrapper.destroy(); m_listWrapper.destroy(); m_qobjectWrapper.destroy(); - m_contextWrapper.destroy(); v8::Isolate::SetEngine(0); delete m_v4Engine; @@ -440,7 +438,7 @@ QV4::Value QV8Engine::getOwnPropertyNames(const QV4::Value &o) QQmlContextData *QV8Engine::callingContext() { - return m_contextWrapper.callingContext(); + return QV4::QmlContextWrapper::callingContext(m_v4Engine); } // Converts a JS value to a QVariant. diff --git a/src/qml/qml/v8/qv8engine_p.h b/src/qml/qml/v8/qv8engine_p.h index 5f5df4ffcd..2981e4ce57 100644 --- a/src/qml/qml/v8/qv8engine_p.h +++ b/src/qml/qml/v8/qv8engine_p.h @@ -71,7 +71,6 @@ #include <private/qqmlpropertycache_p.h> #include "qv8objectresource_p.h" -#include "qv8contextwrapper_p.h" #include "qv8qobjectwrapper_p.h" #include "qv8listwrapper_p.h" #include "qv8valuetypewrapper_p.h" @@ -273,7 +272,6 @@ public: QQmlEngine *engine() { return m_engine; } QV4::Value global(); - QV8ContextWrapper *contextWrapper() { return &m_contextWrapper; } QV8QObjectWrapper *qobjectWrapper() { return &m_qobjectWrapper; } QV8ListWrapper *listWrapper() { return &m_listWrapper; } QV8ValueTypeWrapper *valueTypeWrapper() { return &m_valueTypeWrapper; } @@ -291,9 +289,6 @@ public: QVariant toVariant(const QV4::Value &value, int typeHint); QV4::Value fromVariant(const QVariant &); - // Return the QML global "scope" object for the \a ctxt context and \a scope object. - inline QV4::Value qmlScope(QQmlContextData *ctxt, QObject *scope); - // Return a JS wrapper for the given QObject \a object inline QV4::Value newQObject(QObject *object); inline QV4::Value newQObject(QObject *object, const ObjectOwnership ownership); @@ -394,7 +389,6 @@ protected: QV4::PersistentValue m_bindingFlagKey; - QV8ContextWrapper m_contextWrapper; QV8QObjectWrapper m_qobjectWrapper; QV8ListWrapper m_listWrapper; QV8ValueTypeWrapper m_valueTypeWrapper; @@ -428,11 +422,6 @@ private: Q_DISABLE_COPY(QV8Engine) }; -QV4::Value QV8Engine::qmlScope(QQmlContextData *ctxt, QObject *scope) -{ - return m_contextWrapper.qmlScope(ctxt, scope); -} - bool QV8Engine::isQObject(const QV4::Value &value) { return value.isObject() ? m_qobjectWrapper.isQObject(value) : false; diff --git a/src/qml/qml/v8/qv8qobjectwrapper.cpp b/src/qml/qml/v8/qv8qobjectwrapper.cpp index fbe0461397..2329bcfc63 100644 --- a/src/qml/qml/v8/qv8qobjectwrapper.cpp +++ b/src/qml/qml/v8/qv8qobjectwrapper.cpp @@ -40,7 +40,6 @@ ****************************************************************************/ #include "qv8qobjectwrapper_p.h" -#include "qv8contextwrapper_p.h" #include "qv8engine_p.h" #include <private/qqmlguard_p.h> @@ -53,6 +52,7 @@ #include <private/qqmlexpression_p.h> #include <private/qqmlglobal_p.h> #include <private/qqmltypewrapper_p.h> +#include <private/qqmlcontextwrapper_p.h> #include <private/qv4functionobject_p.h> #include <private/qv4runtime_p.h> @@ -1957,7 +1957,7 @@ Value QObjectMethod::callInternal(ExecutionContext *context, const Value &thisOb QV4::Value rv = QV4::Value::undefinedValue(); QQmlV4Function func(argc, args, &rv, m_qmlGlobal.value(), - v8Engine->contextWrapper()->context(m_qmlGlobal.value()), + QmlContextWrapper::getContext(m_qmlGlobal.value()), v8Engine); QQmlV4Function *funcptr = &func; diff --git a/src/qml/qml/v8/v8.pri b/src/qml/qml/v8/v8.pri index 6b1c0e9e73..072db48ad0 100644 --- a/src/qml/qml/v8/v8.pri +++ b/src/qml/qml/v8/v8.pri @@ -5,7 +5,6 @@ HEADERS += \ $$PWD/qv8debug_p.h \ $$PWD/qv8profiler_p.h \ $$PWD/qv8engine_p.h \ - $$PWD/qv8contextwrapper_p.h \ $$PWD/qv8qobjectwrapper_p.h \ $$PWD/qv8listwrapper_p.h \ $$PWD/qv8valuetypewrapper_p.h \ @@ -17,7 +16,6 @@ HEADERS += \ SOURCES += \ $$PWD/qv8engine.cpp \ - $$PWD/qv8contextwrapper.cpp \ $$PWD/qv8qobjectwrapper.cpp \ $$PWD/qv8listwrapper.cpp \ $$PWD/qv8valuetypewrapper.cpp \ |