From 3e3e9343737ec18ef0579c0bb70c5fecdd3169f0 Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Mon, 15 Jun 2015 15:52:51 +0200 Subject: Add some typesafety Even though the goal is to get rid of the contextwrapper, this helps in the meantime. Change-Id: I234ef39f74fb0eee78710884de6a1c90763bce74 Reviewed-by: Simon Hausmann --- src/qml/jsruntime/qv4context.cpp | 5 +++-- src/qml/jsruntime/qv4context_p.h | 5 +++-- src/qml/jsruntime/qv4script.cpp | 10 +++++----- src/qml/jsruntime/qv4script_p.h | 4 ++-- src/qml/qml/qqmlobjectcreator.cpp | 2 +- 5 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/qml/jsruntime/qv4context.cpp b/src/qml/jsruntime/qv4context.cpp index e223bc0da7..2ce4d85e8c 100644 --- a/src/qml/jsruntime/qv4context.cpp +++ b/src/qml/jsruntime/qv4context.cpp @@ -41,6 +41,7 @@ #include "qv4function_p.h" #include "qv4errorobject_p.h" #include "qv4string_p.h" +#include "private/qqmlcontextwrapper_p.h" using namespace QV4; @@ -92,7 +93,7 @@ Heap::CatchContext *ExecutionContext::newCatchContext(String *exceptionVarName, return d()->engine->memoryManager->alloc(d()->engine, exceptionVarName, exceptionValue); } -Heap::QmlContext *ExecutionContext::newQmlContext(Object *qml) +Heap::QmlContext *ExecutionContext::newQmlContext(QmlContextWrapper *qml) { return d()->engine->memoryManager->alloc(this, qml); } @@ -165,7 +166,7 @@ Heap::CatchContext::CatchContext(ExecutionEngine *engine, QV4::String *exception this->exceptionValue = exceptionValue; } -Heap::QmlContext::QmlContext(QV4::ExecutionContext *outer, QV4::Object *qml) +Heap::QmlContext::QmlContext(QV4::ExecutionContext *outer, QV4::QmlContextWrapper *qml) : Heap::ExecutionContext(outer->engine(), Heap::ExecutionContext::Type_QmlContext) { strictMode = false; diff --git a/src/qml/jsruntime/qv4context_p.h b/src/qml/jsruntime/qv4context_p.h index 1a84097e14..09a15369a4 100644 --- a/src/qml/jsruntime/qv4context_p.h +++ b/src/qml/jsruntime/qv4context_p.h @@ -45,6 +45,7 @@ struct CompilationUnit; struct Function; } +struct QmlContextWrapper; struct Identifier; struct CallContext; struct CatchContext; @@ -126,7 +127,7 @@ struct WithContext : ExecutionContext { }; struct QmlContext : ExecutionContext { - QmlContext(QV4::ExecutionContext *outer, QV4::Object *qml); + QmlContext(QV4::ExecutionContext *outer, QV4::QmlContextWrapper *qml); Pointer qml; }; @@ -146,7 +147,7 @@ struct Q_QML_EXPORT ExecutionContext : public Managed Heap::CallContext *newCallContext(FunctionObject *f, CallData *callData); Heap::WithContext *newWithContext(Object *with); Heap::CatchContext *newCatchContext(String *exceptionVarName, const Value &exceptionValue); - Heap::QmlContext *newQmlContext(Object *qml); + Heap::QmlContext *newQmlContext(QmlContextWrapper *qml); void createMutableBinding(String *name, bool deletable); diff --git a/src/qml/jsruntime/qv4script.cpp b/src/qml/jsruntime/qv4script.cpp index c7dd28e795..767614c137 100644 --- a/src/qml/jsruntime/qv4script.cpp +++ b/src/qml/jsruntime/qv4script.cpp @@ -87,7 +87,7 @@ using namespace QV4; DEFINE_OBJECT_VTABLE(QmlBindingWrapper); DEFINE_OBJECT_VTABLE(CompilationUnitHolder); -Heap::QmlBindingWrapper::QmlBindingWrapper(QV4::ExecutionContext *scope, Function *f, QV4::Object *qml) +Heap::QmlBindingWrapper::QmlBindingWrapper(QV4::ExecutionContext *scope, Function *f, QV4::QmlContextWrapper *qml) : Heap::FunctionObject(scope, scope->d()->engine->id_eval(), /*createProto = */ false) , qml(qml->d()) { @@ -106,7 +106,7 @@ Heap::QmlBindingWrapper::QmlBindingWrapper(QV4::ExecutionContext *scope, Functio s.engine->popContext(); } -Heap::QmlBindingWrapper::QmlBindingWrapper(QV4::ExecutionContext *scope, QV4::Object *qml) +Heap::QmlBindingWrapper::QmlBindingWrapper(QV4::ExecutionContext *scope, QV4::QmlContextWrapper *qml) : Heap::FunctionObject(scope, scope->d()->engine->id_eval(), /*createProto = */ false) , qml(qml->d()) { @@ -163,7 +163,7 @@ Heap::FunctionObject *QmlBindingWrapper::createQmlCallableForFunction(QQmlContex { ExecutionEngine *engine = QQmlEnginePrivate::getV4Engine(qmlContext->engine); QV4::Scope valueScope(engine); - QV4::ScopedObject qmlScopeObject(valueScope, QV4::QmlContextWrapper::qmlScope(engine, qmlContext, scopeObject)); + QV4::Scoped qmlScopeObject(valueScope, QV4::QmlContextWrapper::qmlScope(engine, qmlContext, scopeObject)); ScopedContext global(valueScope, valueScope.engine->rootContext()); QV4::Scoped wrapper(valueScope, engine->memoryManager->alloc(global, qmlScopeObject)); QV4::Scoped wrapperContext(valueScope, wrapper->context()); @@ -299,7 +299,7 @@ ReturnedValue Script::run() return vmFunction->code(engine, vmFunction->codeData); } else { - ScopedObject qmlObj(valueScope, qml.value()); + Scoped qmlObj(valueScope, qml.value()); ScopedFunctionObject f(valueScope, engine->memoryManager->alloc(scope, vmFunction, qmlObj)); ScopedCallData callData(valueScope); callData->thisObject = Primitive::undefinedValue(); @@ -377,7 +377,7 @@ ReturnedValue Script::qmlBinding() parse(); ExecutionEngine *v4 = scope->engine(); Scope valueScope(v4); - ScopedObject qmlObj(valueScope, qml.value()); + Scoped qmlObj(valueScope, qml.value()); ScopedObject v(valueScope, v4->memoryManager->alloc(scope, vmFunction, qmlObj)); return v.asReturnedValue(); } diff --git a/src/qml/jsruntime/qv4script_p.h b/src/qml/jsruntime/qv4script_p.h index 4c8644e8c2..7591df4769 100644 --- a/src/qml/jsruntime/qv4script_p.h +++ b/src/qml/jsruntime/qv4script_p.h @@ -87,9 +87,9 @@ struct ContextStateSaver { namespace Heap { struct QmlBindingWrapper : Heap::FunctionObject { - QmlBindingWrapper(QV4::ExecutionContext *scope, Function *f, QV4::Object *qml); + QmlBindingWrapper(QV4::ExecutionContext *scope, Function *f, QmlContextWrapper *qml); // Constructor for QML functions and signal handlers, resulting binding wrapper is not callable! - QmlBindingWrapper(QV4::ExecutionContext *scope, QV4::Object *qml); + QmlBindingWrapper(QV4::ExecutionContext *scope, QmlContextWrapper *qml); Pointer qml; }; diff --git a/src/qml/qml/qqmlobjectcreator.cpp b/src/qml/qml/qqmlobjectcreator.cpp index 2004f94093..0b977f2551 100644 --- a/src/qml/qml/qqmlobjectcreator.cpp +++ b/src/qml/qml/qqmlobjectcreator.cpp @@ -989,7 +989,7 @@ QV4::Heap::ExecutionContext *QQmlObjectCreator::currentQmlContext() { if (!_qmlBindingWrapper->objectValue()) { QV4::Scope valueScope(v4); - QV4::ScopedObject qmlScope(valueScope, QV4::QmlContextWrapper::qmlScope(v4, context, _scopeObject)); + QV4::Scoped qmlScope(valueScope, QV4::QmlContextWrapper::qmlScope(v4, context, _scopeObject)); QV4::ScopedContext global(valueScope, v4->rootContext()); *_qmlBindingWrapper = v4->memoryManager->alloc(global, qmlScope); } -- cgit v1.2.3