aboutsummaryrefslogtreecommitdiffstats
path: root/src/quick/items
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/quick/items
parenta57085f00b146798a0cca0d52dfa127232c3e659 (diff)
Fix QQmlV4Function API to be GC safe
Change-Id: Id4f79c22fc48ada1c8a9a858e1b7b3d1cf14d120 Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Diffstat (limited to 'src/quick/items')
-rw-r--r--src/quick/items/context2d/qquickcanvasitem.cpp38
-rw-r--r--src/quick/items/qquickdrag.cpp16
-rw-r--r--src/quick/items/qquickdroparea.cpp16
-rw-r--r--src/quick/items/qquickitem.cpp53
-rw-r--r--src/quick/items/qquickloader.cpp15
-rw-r--r--src/quick/items/qquicktextinput.cpp11
6 files changed, 82 insertions, 67 deletions
diff --git a/src/quick/items/context2d/qquickcanvasitem.cpp b/src/quick/items/context2d/qquickcanvasitem.cpp
index 50a5431740..94fe95da4e 100644
--- a/src/quick/items/context2d/qquickcanvasitem.cpp
+++ b/src/quick/items/context2d/qquickcanvasitem.cpp
@@ -739,35 +739,37 @@ void QQuickCanvasItem::getContext(QQmlV4Function *args)
{
Q_D(QQuickCanvasItem);
- if (args->length() < 1 || !(*args)[0].isString()) {
+ QV4::Scope scope(args->v4engine());
+ QV4::ScopedString str(scope, (*args)[0]);
+ if (!str) {
qmlInfo(this) << "getContext should be called with a string naming the required context type";
- args->setReturnValue(QV4::Value::nullValue());
+ args->setReturnValue(QV4::Encode::null());
return;
}
if (!d->available) {
qmlInfo(this) << "Unable to use getContext() at this time, please wait for available: true";
- args->setReturnValue(QV4::Value::nullValue());
+ args->setReturnValue(QV4::Encode::null());
return;
}
- QString contextId = (*args)[0].toQStringNoThrow();
+ QString contextId = str->toQString();
if (d->context != 0) {
if (d->context->contextNames().contains(contextId, Qt::CaseInsensitive)) {
- args->setReturnValue(QV4::Value::fromReturnedValue(d->context->v4value()));
+ args->setReturnValue(d->context->v4value());
return;
}
qmlInfo(this) << "Canvas already initialized with a different context type";
- args->setReturnValue(QV4::Value::nullValue());
+ args->setReturnValue(QV4::Encode::null());
return;
}
if (createContext(contextId))
- args->setReturnValue(QV4::Value::fromReturnedValue(d->context->v4value()));
+ args->setReturnValue(d->context->v4value());
else
- args->setReturnValue(QV4::Value::nullValue());
+ args->setReturnValue(QV4::Encode::null());
}
/*!
@@ -779,9 +781,11 @@ void QQuickCanvasItem::getContext(QQmlV4Function *args)
void QQuickCanvasItem::requestAnimationFrame(QQmlV4Function *args)
{
- if (args->length() < 1 || !(*args)[0].asFunctionObject()) {
+ QV4::Scope scope(args->v4engine());
+ QV4::ScopedFunctionObject f(scope, (*args)[0]);
+ if (!f) {
qmlInfo(this) << "requestAnimationFrame should be called with an animation callback function";
- args->setReturnValue(QV4::Value::nullValue());
+ args->setReturnValue(QV4::Encode::null());
return;
}
@@ -789,14 +793,12 @@ void QQuickCanvasItem::requestAnimationFrame(QQmlV4Function *args)
static int id = 0;
- QV4::Scope scope(QV8Engine::getV4(args->engine()));
- QV4::ScopedValue v(scope, (*args)[0]);
- d->animationCallbacks.insert(++id, QV4::PersistentValue(v));
+ d->animationCallbacks.insert(++id, QV4::PersistentValue(f));
if (isVisible())
polish();
- args->setReturnValue(QV4::Value::fromInt32(id));
+ args->setReturnValue(QV4::Encode(id));
}
/*!
@@ -807,13 +809,15 @@ void QQuickCanvasItem::requestAnimationFrame(QQmlV4Function *args)
void QQuickCanvasItem::cancelRequestAnimationFrame(QQmlV4Function *args)
{
- if (args->length() < 1 || !(*args)[0].isInteger()) {
+ QV4::Scope scope(args->v4engine());
+ QV4::ScopedValue v(scope, (*args)[0]);
+ if (!v->isInteger()) {
qmlInfo(this) << "cancelRequestAnimationFrame should be called with an animation callback id";
- args->setReturnValue(QV4::Value::nullValue());
+ args->setReturnValue(QV4::Encode::null());
return;
}
- d_func()->animationCallbacks.remove((*args)[0].integerValue());
+ d_func()->animationCallbacks.remove(v->integerValue());
}
diff --git a/src/quick/items/qquickdrag.cpp b/src/quick/items/qquickdrag.cpp
index d66c57c667..fa8b52dfd9 100644
--- a/src/quick/items/qquickdrag.cpp
+++ b/src/quick/items/qquickdrag.cpp
@@ -595,9 +595,10 @@ void QQuickDragAttached::start(QQmlV4Function *args)
Qt::DropActions supportedActions = d->supportedActions;
// check arguments for supportedActions, maybe data?
if (args->length() >= 1) {
- QV4::Value v = (*args)[0];
- if (v.isInt32()) {
- supportedActions = Qt::DropActions(v.integerValue());
+ QV4::Scope scope(args->v4engine());
+ QV4::ScopedValue v(scope, (*args)[0]);
+ if (v->isInt32()) {
+ supportedActions = Qt::DropActions(v->integerValue());
d->overrideActions = true;
}
}
@@ -773,15 +774,16 @@ void QQuickDragAttached::startDrag(QQmlV4Function *args)
// check arguments for supportedActions
if (args->length() >= 1) {
- QV4::Value v = (*args)[0];
- if (v.isInt32()) {
- supportedActions = Qt::DropActions(v.integerValue());
+ QV4::Scope scope(args->v4engine());
+ QV4::ScopedValue v(scope, (*args)[0]);
+ if (v->isInt32()) {
+ supportedActions = Qt::DropActions(v->integerValue());
}
}
Qt::DropAction dropAction = d->startDrag(supportedActions);
- args->setReturnValue(QV4::Value::fromInt32(dropAction));
+ args->setReturnValue(QV4::Encode((int)dropAction));
}
QQuickDrag::QQuickDrag(QObject *parent)
diff --git a/src/quick/items/qquickdroparea.cpp b/src/quick/items/qquickdroparea.cpp
index 51037508e0..92275b1655 100644
--- a/src/quick/items/qquickdroparea.cpp
+++ b/src/quick/items/qquickdroparea.cpp
@@ -559,11 +559,12 @@ QStringList QQuickDropEvent::formats() const
void QQuickDropEvent::getDataAsString(QQmlV4Function *args)
{
if (args->length() != 0) {
- QV4::Value v = (*args)[0];
- QString format = v.toQString();
+ QV4::ExecutionEngine *v4 = args->v4engine();
+ QV4::Scope scope(v4);
+ QV4::ScopedValue v(scope, (*args)[0]);
+ QString format = v->toQString();
QString rv = QString::fromUtf8(event->mimeData()->data(format));
- QV4::ExecutionEngine *v4 = QV8Engine::getV4(args->engine());
- args->setReturnValue(QV4::Value::fromString(v4, rv));
+ args->setReturnValue(QV4::Value::fromString(v4, rv).asReturnedValue());
}
}
@@ -577,9 +578,10 @@ void QQuickDropEvent::accept(QQmlV4Function *args)
Qt::DropAction action = event->dropAction();
if (args->length() >= 1) {
- QV4::Value v = (*args)[0];
- if (v.isInt32())
- action = Qt::DropAction(v.integerValue());
+ QV4::Scope scope(args->v4engine());
+ QV4::ScopedValue v(scope, (*args)[0]);
+ if (v->isInt32())
+ action = Qt::DropAction(v->integerValue());
}
// get action from arguments.
diff --git a/src/quick/items/qquickitem.cpp b/src/quick/items/qquickitem.cpp
index 3ecd5f558d..cd9e88e452 100644
--- a/src/quick/items/qquickitem.cpp
+++ b/src/quick/items/qquickitem.cpp
@@ -3868,34 +3868,35 @@ void QQuickItem::polish()
void QQuickItem::mapFromItem(QQmlV4Function *args) const
{
if (args->length() != 0) {
- QV4::Value item = (*args)[0];
+ QV4::ExecutionEngine *v4 = args->v4engine();
+ QV4::Scope scope(v4);
+ QV4::ScopedValue item(scope, (*args)[0]);
QQuickItem *itemObj = 0;
- if (!item.isNull()) {
- if (QV4::QObjectWrapper *qobjectWrapper = item.as<QV4::QObjectWrapper>())
+ if (!item->isNull()) {
+ QV4::Scoped<QV4::QObjectWrapper> qobjectWrapper(scope, item->as<QV4::QObjectWrapper>());
+ if (qobjectWrapper)
itemObj = qobject_cast<QQuickItem*>(qobjectWrapper->object());
}
- if (!itemObj && !item.isNull()) {
- qmlInfo(this) << "mapFromItem() given argument \"" << item.toQStringNoThrow()
+ if (!itemObj && !item->isNull()) {
+ qmlInfo(this) << "mapFromItem() given argument \"" << item->toQStringNoThrow()
<< "\" which is neither null nor an Item";
return;
}
- QV4::ExecutionEngine *v4 = QV8Engine::getV4(args->engine());
- QV4::Scope scope(v4);
QV4::Scoped<QV4::Object> rv(scope, v4->newObject());
- args->setReturnValue(rv.asValue());
+ args->setReturnValue(rv.asReturnedValue());
QV4::ScopedString s(scope);
QV4::ScopedValue v(scope);
- qreal x = (args->length() > 1) ? (*args)[1].asDouble() : 0;
- qreal y = (args->length() > 2) ? (*args)[2].asDouble() : 0;
+ qreal x = (args->length() > 1) ? (v = (*args)[1])->asDouble() : 0;
+ qreal y = (args->length() > 2) ? (v = (*args)[2])->asDouble() : 0;
if (args->length() > 3) {
- qreal w = (*args)[3].asDouble();
- qreal h = (args->length() > 4) ? (*args)[4].asDouble() : 0;
+ qreal w = (v = (*args)[3])->asDouble();
+ qreal h = (args->length() > 4) ? (v = (*args)[4])->asDouble() : 0;
QRectF r = mapRectFromItem(itemObj, QRectF(x, y, w, h));
@@ -3946,34 +3947,36 @@ QTransform QQuickItem::itemTransform(QQuickItem *other, bool *ok) const
void QQuickItem::mapToItem(QQmlV4Function *args) const
{
if (args->length() != 0) {
- QV4::Value item = (*args)[0];
+ QV4::ExecutionEngine *v4 = args->v4engine();
+ QV4::Scope scope(v4);
+ QV4::ScopedValue item(scope, (*args)[0]);
QQuickItem *itemObj = 0;
- if (!item.isNull()) {
- if (QV4::QObjectWrapper *qobjectWrapper = item.as<QV4::QObjectWrapper>())
+ if (!item->isNull()) {
+ QV4::Scoped<QV4::QObjectWrapper> qobjectWrapper(scope, item->as<QV4::QObjectWrapper>());
+ if (qobjectWrapper)
itemObj = qobject_cast<QQuickItem*>(qobjectWrapper->object());
}
- if (!itemObj && !item.isNull()) {
- qmlInfo(this) << "mapToItem() given argument \"" << item.toQStringNoThrow()
+ if (!itemObj && !item->isNull()) {
+ qmlInfo(this) << "mapToItem() given argument \"" << item->toQStringNoThrow()
<< "\" which is neither null nor an Item";
return;
}
- QV4::ExecutionEngine *v4 = QV8Engine::getV4(args->engine());
- QV4::Scope scope(v4);
QV4::Scoped<QV4::Object> rv(scope, v4->newObject());
- args->setReturnValue(rv.asValue());
+ args->setReturnValue(rv.asReturnedValue());
- qreal x = (args->length() > 1) ? (*args)[1].asDouble() : 0;
- qreal y = (args->length() > 2) ? (*args)[2].asDouble() : 0;
+ QV4::ScopedValue v(scope);
+
+ qreal x = (args->length() > 1) ? (v = (*args)[1])->asDouble() : 0;
+ qreal y = (args->length() > 2) ? (v = (*args)[2])->asDouble() : 0;
QV4::ScopedString s(scope);
- QV4::ScopedValue v(scope);
if (args->length() > 3) {
- qreal w = (*args)[3].asDouble();
- qreal h = (args->length() > 4) ? (*args)[4].asDouble() : 0;
+ qreal w = (v = (*args)[3])->asDouble();
+ qreal h = (args->length() > 4) ? (v = (*args)[4])->asDouble() : 0;
QRectF r = mapRectToItem(itemObj, QRectF(x, y, w, h));
diff --git a/src/quick/items/qquickloader.cpp b/src/quick/items/qquickloader.cpp
index 63490ef2cc..1301225feb 100644
--- a/src/quick/items/qquickloader.cpp
+++ b/src/quick/items/qquickloader.cpp
@@ -568,7 +568,7 @@ void QQuickLoader::setSource(QQmlV4Function *args)
Q_D(QQuickLoader);
bool ipvError = false;
- args->setReturnValue(QV4::Value::undefinedValue());
+ args->setReturnValue(QV4::Encode::undefined());
QV4::Value ipv = d->extractInitialPropertyValues(args, this, &ipvError);
if (ipvError)
return;
@@ -578,7 +578,7 @@ void QQuickLoader::setSource(QQmlV4Function *args)
if (!ipv.isUndefined()) {
d->disposeInitialPropertyValues();
d->initialPropertyValues = ipv.asReturnedValue();
- d->qmlGlobalForIpv = args->qmlGlobal().asReturnedValue();
+ d->qmlGlobalForIpv = args->qmlGlobal();
}
setSource(sourceUrl, false); // already cleared and set ipv above.
@@ -926,7 +926,9 @@ void QQuickLoader::geometryChanged(const QRectF &newGeometry, const QRectF &oldG
QUrl QQuickLoaderPrivate::resolveSourceUrl(QQmlV4Function *args)
{
- QString arg = (*args)[0].toQStringNoThrow();
+ QV4::Scope scope(args->v4engine());
+ QV4::ScopedValue v(scope, (*args)[0]);
+ QString arg = v->toQString();
if (arg.isEmpty())
return QUrl();
@@ -937,10 +939,11 @@ QUrl QQuickLoaderPrivate::resolveSourceUrl(QQmlV4Function *args)
QV4::Value QQuickLoaderPrivate::extractInitialPropertyValues(QQmlV4Function *args, QObject *loader, bool *error)
{
- QV4::Value valuemap = QV4::Value::undefinedValue();
+ QV4::Scope scope(args->v4engine());
+ QV4::ScopedValue valuemap(scope, QV4::Value::undefinedValue());
if (args->length() >= 2) {
- QV4::Value v = (*args)[1];
- if (!v.isObject() || v.asArrayObject()) {
+ QV4::ScopedValue v(scope, (*args)[1]);
+ if (!v->isObject() || v->asArrayObject()) {
*error = true;
qmlInfo(loader) << QQuickLoader::tr("setSource: value is not an object");
} else {
diff --git a/src/quick/items/qquicktextinput.cpp b/src/quick/items/qquicktextinput.cpp
index b5b86993f4..a5db64c983 100644
--- a/src/quick/items/qquicktextinput.cpp
+++ b/src/quick/items/qquicktextinput.cpp
@@ -1420,17 +1420,18 @@ void QQuickTextInput::positionAt(QQmlV4Function *args) const
return;
int i = 0;
- QV4::Value arg = (*args)[i];
- x = arg.toNumber();
+ QV4::Scope scope(args->v4engine());
+ QV4::ScopedValue arg(scope, (*args)[0]);
+ x = arg->toNumber();
if (++i < args->length()) {
arg = (*args)[i];
- y = arg.toNumber();
+ y = arg->toNumber();
}
if (++i < args->length()) {
arg = (*args)[i];
- position = QTextLine::CursorPosition(arg.toInt32());
+ position = QTextLine::CursorPosition(arg->toInt32());
}
int pos = d->positionAt(x, y, position);
@@ -1445,7 +1446,7 @@ void QQuickTextInput::positionAt(QQmlV4Function *args) const
pos = cursor;
#endif
}
- args->setReturnValue(QV4::Value::fromInt32(pos));
+ args->setReturnValue(QV4::Encode(pos));
}
int QQuickTextInputPrivate::positionAt(qreal x, qreal y, QTextLine::CursorPosition position) const