diff options
author | Lars Knoll <lars.knoll@digia.com> | 2013-09-24 13:53:54 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-09-26 09:05:22 +0200 |
commit | 0f204625dc6720d40df22ca352af995af5448525 (patch) | |
tree | edb78721935e2b0d34927b3dc358c3b171dc43b1 /src/quick/items/context2d/qquickcanvasitem.cpp | |
parent | a57085f00b146798a0cca0d52dfa127232c3e659 (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/context2d/qquickcanvasitem.cpp')
-rw-r--r-- | src/quick/items/context2d/qquickcanvasitem.cpp | 38 |
1 files changed, 21 insertions, 17 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()); } |