aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@digia.com>2014-05-08 21:29:56 +0200
committerSimon Hausmann <simon.hausmann@digia.com>2014-07-22 13:49:16 +0200
commit20224f2152aca440e91ef11644356c9db8d929de (patch)
tree6596748eda8f609f1a5f26085074db718f3693a3
parent6fa459deaf40f162b20b8f12c75ce80d4fa927b9 (diff)
New construction scheme for the binding wrapper
Change-Id: Ic248aef22e1222e84dfb9b8af0413cf750beb576 Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
-rw-r--r--src/qml/jsruntime/qv4script.cpp46
-rw-r--r--src/qml/jsruntime/qv4script_p.h7
-rw-r--r--src/qml/qml/qqmlobjectcreator.cpp4
3 files changed, 27 insertions, 30 deletions
diff --git a/src/qml/jsruntime/qv4script.cpp b/src/qml/jsruntime/qv4script.cpp
index af25f6aec2..635115ff0a 100644
--- a/src/qml/jsruntime/qv4script.cpp
+++ b/src/qml/jsruntime/qv4script.cpp
@@ -61,45 +61,43 @@
using namespace QV4;
-QmlBindingWrapper::QmlBindingWrapper(ExecutionContext *scope, Function *f, Object *qml)
- : FunctionObject(scope, scope->d()->engine->id_eval, /*createProto = */ false)
+QmlBindingWrapper::Data::Data(ExecutionContext *scope, Function *f, Object *qml)
+ : FunctionObject::Data(scope, scope->d()->engine->id_eval, /*createProto = */ false)
+ , qml(qml)
{
- d()->qml = qml;
-
Q_ASSERT(scope->inUse());
setVTable(staticVTable());
- d()->function = f;
- if (function())
- function()->compilationUnit->ref();
- d()->needsActivation = function() ? function()->needsActivation() : false;
+ function = f;
+ if (function)
+ function->compilationUnit->ref();
+ needsActivation = function ? function->needsActivation() : false;
Scope s(scope);
- ScopedValue protectThis(s, this);
+ Scoped<QmlBindingWrapper> o(s, this);
- defineReadonlyProperty(scope->d()->engine->id_length, Primitive::fromInt32(1));
+ o->defineReadonlyProperty(scope->d()->engine->id_length, Primitive::fromInt32(1));
- d()->qmlContext = scope->d()->engine->currentContext()->newQmlContext(this, qml);
- scope->d()->engine->popContext();
+ o->d()->qmlContext = s.engine->currentContext()->newQmlContext(o, qml);
+ s.engine->popContext();
}
-QmlBindingWrapper::QmlBindingWrapper(ExecutionContext *scope, Object *qml)
- : FunctionObject(scope, scope->d()->engine->id_eval, /*createProto = */ false)
+QmlBindingWrapper::Data::Data(ExecutionContext *scope, Object *qml)
+ : FunctionObject::Data(scope, scope->d()->engine->id_eval, /*createProto = */ false)
+ , qml(qml)
{
- d()->qml = qml;
-
Q_ASSERT(scope->inUse());
setVTable(staticVTable());
- d()->needsActivation = false;
+ needsActivation = false;
Scope s(scope);
- ScopedValue protectThis(s, this);
+ Scoped<QmlBindingWrapper> o(s, this);
- defineReadonlyProperty(scope->d()->engine->id_length, Primitive::fromInt32(1));
+ o->defineReadonlyProperty(scope->d()->engine->id_length, Primitive::fromInt32(1));
- d()->qmlContext = scope->d()->engine->currentContext()->newQmlContext(this, qml);
- scope->d()->engine->popContext();
+ o->d()->qmlContext = s.engine->currentContext()->newQmlContext(o, qml);
+ s.engine->popContext();
}
ReturnedValue QmlBindingWrapper::call(Managed *that, CallData *)
@@ -143,7 +141,7 @@ Returned<FunctionObject> *QmlBindingWrapper::createQmlCallableForFunction(QQmlCo
ExecutionEngine *engine = QQmlEnginePrivate::getV4Engine(qmlContext->engine);
QV4::Scope valueScope(engine);
QV4::ScopedObject qmlScopeObject(valueScope, QV4::QmlContextWrapper::qmlScope(engine->v8Engine, qmlContext, scopeObject));
- QV4::Scoped<QV4::QmlBindingWrapper> wrapper(valueScope, new (engine->memoryManager) QV4::QmlBindingWrapper(engine->rootContext, qmlScopeObject));
+ QV4::Scoped<QV4::QmlBindingWrapper> wrapper(valueScope, new (engine) QV4::QmlBindingWrapper::Data(engine->rootContext, qmlScopeObject));
if (!signalParameters.isEmpty()) {
if (error)
@@ -334,7 +332,7 @@ ReturnedValue Script::run()
return vmFunction->code(scope, vmFunction->codeData);
} else {
ScopedObject qmlObj(valueScope, qml.value());
- FunctionObject *f = new (engine->memoryManager) QmlBindingWrapper(scope, vmFunction, qmlObj);
+ ScopedFunctionObject f(valueScope, new (engine) QmlBindingWrapper::Data(scope, vmFunction, qmlObj));
ScopedCallData callData(valueScope, 0);
callData->thisObject = Primitive::undefinedValue();
return f->call(callData);
@@ -410,7 +408,7 @@ ReturnedValue Script::qmlBinding()
ExecutionEngine *v4 = scope->d()->engine;
Scope valueScope(v4);
ScopedObject qmlObj(valueScope, qml.value());
- ScopedObject v(valueScope, new (v4->memoryManager) QmlBindingWrapper(scope, vmFunction, qmlObj));
+ ScopedObject v(valueScope, new (v4) QmlBindingWrapper::Data(scope, vmFunction, qmlObj));
return v.asReturnedValue();
}
diff --git a/src/qml/jsruntime/qv4script_p.h b/src/qml/jsruntime/qv4script_p.h
index 02fa82e282..ac5df82ef2 100644
--- a/src/qml/jsruntime/qv4script_p.h
+++ b/src/qml/jsruntime/qv4script_p.h
@@ -57,6 +57,9 @@ struct ExecutionContext;
struct Q_QML_EXPORT QmlBindingWrapper : FunctionObject {
struct Data : FunctionObject::Data {
+ Data(ExecutionContext *scope, Function *f, Object *qml);
+ // Constructor for QML functions and signal handlers, resulting binding wrapper is not callable!
+ Data(ExecutionContext *scope, Object *qml);
Object *qml;
CallContext *qmlContext;
};
@@ -67,10 +70,6 @@ struct Q_QML_EXPORT QmlBindingWrapper : FunctionObject {
V4_OBJECT
- QmlBindingWrapper(ExecutionContext *scope, Function *f, Object *qml);
- // Constructor for QML functions and signal handlers, resulting binding wrapper is not callable!
- QmlBindingWrapper(ExecutionContext *scope, Object *qml);
-
static ReturnedValue call(Managed *that, CallData *);
static void markObjects(Managed *m, ExecutionEngine *e);
diff --git a/src/qml/qml/qqmlobjectcreator.cpp b/src/qml/qml/qqmlobjectcreator.cpp
index 8fae12326f..8162777172 100644
--- a/src/qml/qml/qqmlobjectcreator.cpp
+++ b/src/qml/qml/qqmlobjectcreator.cpp
@@ -261,7 +261,7 @@ bool QQmlObjectCreator::populateDeferredProperties(QObject *instance)
QV4::ScopedValue scopeObjectProtector(valueScope, declarativeData->jsWrapper.value());
Q_UNUSED(scopeObjectProtector);
QV4::ScopedObject qmlScope(valueScope, QV4::QmlContextWrapper::qmlScope(QV8Engine::get(engine), context, _scopeObject));
- QV4::Scoped<QV4::QmlBindingWrapper> qmlBindingWrapper(valueScope, new (v4->memoryManager) QV4::QmlBindingWrapper(v4->rootContext, qmlScope));
+ QV4::Scoped<QV4::QmlBindingWrapper> qmlBindingWrapper(valueScope, new (v4) QV4::QmlBindingWrapper::Data(v4->rootContext, qmlScope));
QV4::ExecutionContext *qmlContext = qmlBindingWrapper->context();
qSwap(_qmlContext, qmlContext);
@@ -1163,7 +1163,7 @@ QObject *QQmlObjectCreator::createInstance(int index, QObject *parent, bool isCo
QV4::ScopedValue scopeObjectProtector(valueScope, ddata ? ddata->jsWrapper.value() : 0);
Q_UNUSED(scopeObjectProtector);
QV4::ScopedObject qmlScope(valueScope, QV4::QmlContextWrapper::qmlScope(QV8Engine::get(engine), context, _scopeObject));
- QV4::Scoped<QV4::QmlBindingWrapper> qmlBindingWrapper(valueScope, new (v4->memoryManager) QV4::QmlBindingWrapper(v4->rootContext, qmlScope));
+ QV4::Scoped<QV4::QmlBindingWrapper> qmlBindingWrapper(valueScope, new (v4) QV4::QmlBindingWrapper::Data(v4->rootContext, qmlScope));
QV4::ExecutionContext *qmlContext = qmlBindingWrapper->context();
qSwap(_qmlContext, qmlContext);