aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/qml/qqmlcomponent.cpp
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@digia.com>2013-09-24 13:53:54 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-09-26 09:05:22 +0200
commit0f204625dc6720d40df22ca352af995af5448525 (patch)
treeedb78721935e2b0d34927b3dc358c3b171dc43b1 /src/qml/qml/qqmlcomponent.cpp
parenta57085f00b146798a0cca0d52dfa127232c3e659 (diff)
Fix QQmlV4Function API to be GC safe
Change-Id: Id4f79c22fc48ada1c8a9a858e1b7b3d1cf14d120 Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Diffstat (limited to 'src/qml/qml/qqmlcomponent.cpp')
-rw-r--r--src/qml/qml/qqmlcomponent.cpp47
1 files changed, 24 insertions, 23 deletions
diff --git a/src/qml/qml/qqmlcomponent.cpp b/src/qml/qml/qqmlcomponent.cpp
index cfda595438..f53df6386d 100644
--- a/src/qml/qml/qqmlcomponent.cpp
+++ b/src/qml/qml/qqmlcomponent.cpp
@@ -1206,49 +1206,48 @@ void QQmlComponent::createObject(QQmlV4Function *args)
Q_ASSERT(args);
QObject *parent = 0;
- QV4::Value valuemap = QV4::Value::undefinedValue();
+ QV4::ExecutionEngine *v4 = args->v4engine();
+ QV4::Scope scope(v4);
+ QV4::ScopedValue valuemap(scope, QV4::Value::undefinedValue());
if (args->length() >= 1) {
- if (QV4::QObjectWrapper *qobjectWrapper = (*args)[0].as<QV4::QObjectWrapper>())
+ QV4::Scoped<QV4::QObjectWrapper> qobjectWrapper(scope, (*args)[0]);
+ if (qobjectWrapper)
parent = qobjectWrapper->object();
}
if (args->length() >= 2) {
- QV4::Value v = (*args)[1];
- if (!v.asObject() || v.asArrayObject()) {
+ QV4::ScopedValue v(scope, (*args)[1]);
+ if (!v->asObject() || v->asArrayObject()) {
qmlInfo(this) << tr("createObject: value is not an object");
- args->setReturnValue(QV4::Value::nullValue());
+ args->setReturnValue(QV4::Encode::null());
return;
}
valuemap = v;
}
- QV8Engine *v8engine = args->engine();
- QV4::ExecutionEngine *v4engine = QV8Engine::getV4(v8engine);
- QV4::Scope scope(v4engine);
-
QQmlContext *ctxt = creationContext();
if (!ctxt) ctxt = d->engine->rootContext();
QObject *rv = beginCreate(ctxt);
if (!rv) {
- args->setReturnValue(QV4::Value::nullValue());
+ args->setReturnValue(QV4::Encode::null());
return;
}
QQmlComponent_setQmlParent(rv, parent);
- QV4::ScopedValue object(scope, QV4::QObjectWrapper::wrap(v4engine, rv));
+ QV4::ScopedValue object(scope, QV4::QObjectWrapper::wrap(v4, rv));
Q_ASSERT(object->isObject());
- if (!valuemap.isUndefined()) {
- QQmlComponentExtension *e = componentExtension(v8engine);
+ if (!valuemap->isUndefined()) {
+ QQmlComponentExtension *e = componentExtension(args->engine());
QV4::ScopedObject qmlglobal(scope, args->qmlGlobal());
- QV4::ScopedValue f(scope, QV4::Script::evaluate(v4engine, QString::fromLatin1(INITIALPROPERTIES_SOURCE), qmlglobal));
+ QV4::ScopedValue f(scope, QV4::Script::evaluate(v4, QString::fromLatin1(INITIALPROPERTIES_SOURCE), qmlglobal));
Q_ASSERT(f->asFunctionObject());
QV4::ScopedCallData callData(scope, 2);
- callData->thisObject = QV4::Value::fromObject(v4engine->globalObject);
+ callData->thisObject = QV4::Value::fromObject(v4->globalObject);
callData->args[0] = object;
callData->args[1] = valuemap;
f->asFunctionObject()->call(callData);
@@ -1261,9 +1260,9 @@ void QQmlComponent::createObject(QQmlV4Function *args)
QQmlData::get(rv)->indestructible = false;
if (!rv)
- args->setReturnValue(QV4::Value::nullValue());
+ args->setReturnValue(QV4::Encode::null());
else
- args->setReturnValue(object);
+ args->setReturnValue(object.asReturnedValue());
}
/*!
@@ -1330,7 +1329,7 @@ void QQmlComponent::incubateObject(QQmlV4Function *args)
Q_ASSERT(d->engine);
Q_UNUSED(d);
Q_ASSERT(args);
- QV4::ExecutionEngine *v4 = QV8Engine::getV4(args->engine());
+ QV4::ExecutionEngine *v4 = args->v4engine();
QV4::Scope scope(v4);
QObject *parent = 0;
@@ -1338,7 +1337,8 @@ void QQmlComponent::incubateObject(QQmlV4Function *args)
QQmlIncubator::IncubationMode mode = QQmlIncubator::Asynchronous;
if (args->length() >= 1) {
- if (QV4::QObjectWrapper *qobjectWrapper = (*args)[0].as<QV4::QObjectWrapper>())
+ QV4::Scoped<QV4::QObjectWrapper> qobjectWrapper(scope, (*args)[0]);
+ if (qobjectWrapper)
parent = qobjectWrapper->object();
}
@@ -1347,7 +1347,7 @@ void QQmlComponent::incubateObject(QQmlV4Function *args)
if (v->isNull()) {
} else if (!v->asObject() || v->asArrayObject()) {
qmlInfo(this) << tr("createObject: value is not an object");
- args->setReturnValue(QV4::Value::nullValue());
+ args->setReturnValue(QV4::Encode::null());
return;
} else {
valuemap = v;
@@ -1355,7 +1355,8 @@ void QQmlComponent::incubateObject(QQmlV4Function *args)
}
if (args->length() >= 3) {
- quint32 v = (*args)[2].toUInt32();
+ QV4::ScopedValue val(scope, (*args)[2]);
+ quint32 v = val->toUInt32();
if (v == 0)
mode = QQmlIncubator::Asynchronous;
else if (v == 1)
@@ -1377,9 +1378,9 @@ void QQmlComponent::incubateObject(QQmlV4Function *args)
create(*r.getPointer(), creationContext());
if (r->status() == QQmlIncubator::Null) {
- args->setReturnValue(QV4::Value::nullValue());
+ args->setReturnValue(QV4::Encode::null());
} else {
- args->setReturnValue(r.asValue());
+ args->setReturnValue(r.asReturnedValue());
}
}