diff options
author | Lars Knoll <lars.knoll@digia.com> | 2013-10-10 12:21:12 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-10-11 08:56:22 +0200 |
commit | b0e83cdc1a3a80ecc26cb31ac046b6c743238d41 (patch) | |
tree | 9170ffd694ca3e8447c36f42dc30c598b1d1da5e | |
parent | 979e625dc1ff257c1793bbd7ebd8001c25a11872 (diff) |
Remove usage of String pointers where not required
Change-Id: Ia533308a1641fab263d8faa8316455e8ade1c859
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
-rw-r--r-- | src/qml/jsruntime/qv4serialize.cpp | 2 | ||||
-rw-r--r-- | src/qml/qml/v8/qqmlbuiltinfunctions.cpp | 18 | ||||
-rw-r--r-- | src/qml/types/qqmllistmodel.cpp | 8 |
3 files changed, 18 insertions, 10 deletions
diff --git a/src/qml/jsruntime/qv4serialize.cpp b/src/qml/jsruntime/qv4serialize.cpp index d38897c37c..53d7e4701a 100644 --- a/src/qml/jsruntime/qv4serialize.cpp +++ b/src/qml/jsruntime/qv4serialize.cpp @@ -281,7 +281,7 @@ void Serialize::serialize(QByteArray &data, const QV4::ValueRef v, QV8Engine *en QV4::ExecutionContext *ctx = v4->current; try { - str = s->asString(); + str = s; val = o->get(str); } catch (...) { ctx->catchException(); diff --git a/src/qml/qml/v8/qqmlbuiltinfunctions.cpp b/src/qml/qml/v8/qqmlbuiltinfunctions.cpp index 92ab09e994..ba5f05b5ba 100644 --- a/src/qml/qml/v8/qqmlbuiltinfunctions.cpp +++ b/src/qml/qml/v8/qqmlbuiltinfunctions.cpp @@ -613,6 +613,7 @@ ReturnedValue QtObject::method_formatDate(QV4::SimpleCallContext *ctx) { if (ctx->callData->argc < 1 || ctx->callData->argc > 2) V4THROW_ERROR("Qt.formatDate(): Invalid arguments"); + QV4::Scope scope(ctx); QV8Engine *v8engine = ctx->engine->v8Engine; @@ -620,7 +621,8 @@ ReturnedValue QtObject::method_formatDate(QV4::SimpleCallContext *ctx) QDate date = v8engine->toVariant(ctx->callData->args[0], -1).toDateTime().date(); QString formattedDate; if (ctx->callData->argc == 2) { - if (String *s = ctx->callData->args[1].asString()) { + QV4::ScopedString s(scope, ctx->callData->args[1]); + if (s) { QString format = s->toQString(); formattedDate = date.toString(format); } else if (ctx->callData->args[1].isNumber()) { @@ -634,7 +636,7 @@ ReturnedValue QtObject::method_formatDate(QV4::SimpleCallContext *ctx) formattedDate = date.toString(enumFormat); } - return v8engine->fromVariant(QVariant::fromValue(formattedDate)); + return ctx->engine->newString(formattedDate)->asReturnedValue(); } /*! @@ -656,6 +658,7 @@ ReturnedValue QtObject::method_formatTime(QV4::SimpleCallContext *ctx) { if (ctx->callData->argc < 1 || ctx->callData->argc > 2) V4THROW_ERROR("Qt.formatTime(): Invalid arguments"); + QV4::Scope scope(ctx); QV8Engine *v8engine = ctx->engine->v8Engine; @@ -669,7 +672,8 @@ ReturnedValue QtObject::method_formatTime(QV4::SimpleCallContext *ctx) Qt::DateFormat enumFormat = Qt::DefaultLocaleShortDate; QString formattedTime; if (ctx->callData->argc == 2) { - if (String *s = ctx->callData->args[1].asString()) { + QV4::ScopedString s(scope, ctx->callData->args[1]); + if (s) { QString format = s->toQString(); formattedTime = time.toString(format); } else if (ctx->callData->args[1].isNumber()) { @@ -683,7 +687,7 @@ ReturnedValue QtObject::method_formatTime(QV4::SimpleCallContext *ctx) formattedTime = time.toString(enumFormat); } - return v8engine->fromVariant(QVariant::fromValue(formattedTime)); + return ctx->engine->newString(formattedTime)->asReturnedValue(); } /*! @@ -780,6 +784,7 @@ ReturnedValue QtObject::method_formatDateTime(QV4::SimpleCallContext *ctx) { if (ctx->callData->argc < 1 || ctx->callData->argc > 2) V4THROW_ERROR("Qt.formatDateTime(): Invalid arguments"); + QV4::Scope scope(ctx); QV8Engine *v8engine = ctx->engine->v8Engine; @@ -787,7 +792,8 @@ ReturnedValue QtObject::method_formatDateTime(QV4::SimpleCallContext *ctx) QDateTime dt = v8engine->toVariant(ctx->callData->args[0], -1).toDateTime(); QString formattedDt; if (ctx->callData->argc == 2) { - if (String *s = ctx->callData->args[1].asString()) { + QV4::ScopedString s(scope, ctx->callData->args[1]); + if (s) { QString format = s->toQString(); formattedDt = dt.toString(format); } else if (ctx->callData->args[1].isNumber()) { @@ -801,7 +807,7 @@ ReturnedValue QtObject::method_formatDateTime(QV4::SimpleCallContext *ctx) formattedDt = dt.toString(enumFormat); } - return v8engine->fromVariant(QVariant::fromValue(formattedDt)); + return ctx->engine->newString(formattedDt)->asReturnedValue(); } /*! diff --git a/src/qml/types/qqmllistmodel.cpp b/src/qml/types/qqmllistmodel.cpp index 4fee073180..d6d3de8af3 100644 --- a/src/qml/types/qqmllistmodel.cpp +++ b/src/qml/types/qqmllistmodel.cpp @@ -420,6 +420,8 @@ void ListModel::set(int elementIndex, QV4::ObjectRef object, QVector<int> *roles QV4::ObjectIterator it(scope, object, QV4::ObjectIterator::WithProtoChain|QV4::ObjectIterator::EnumerableOnly); QV4::Scoped<QV4::String> propertyName(scope); QV4::ScopedValue propertyValue(scope); + QV4::ScopedString s(scope); + QV4::ScopedArrayObject a(scope); while (1) { propertyName = it.nextPropertyNameAsString(propertyValue); if (!propertyName) @@ -429,13 +431,13 @@ void ListModel::set(int elementIndex, QV4::ObjectRef object, QVector<int> *roles int roleIndex = -1; // Add the value now - if (QV4::String *s = propertyValue->asString()) { + if ((s = propertyValue)) { const ListLayout::Role &r = m_layout->getRoleOrCreate(propertyName, ListLayout::Role::String); roleIndex = e->setStringProperty(r, s->toQString()); } else if (propertyValue->isNumber()) { const ListLayout::Role &r = m_layout->getRoleOrCreate(propertyName, ListLayout::Role::Number); roleIndex = e->setDoubleProperty(r, propertyValue->asDouble()); - } else if (QV4::ArrayObject *a = propertyValue->asArrayObject()) { + } else if ((a = propertyValue)) { const ListLayout::Role &r = m_layout->getRoleOrCreate(propertyName, ListLayout::Role::List); ListModel *subModel = new ListModel(r.subLayout, 0, -1); @@ -1174,7 +1176,7 @@ int ListElement::setJsProperty(const ListLayout::Role &role, const QV4::ValueRef QV4::Scope scope(QV8Engine::getV4(eng)); // Add the value now - if (d->asString()) { + if (d->isString()) { QString qstr = d->toQString(); roleIndex = setStringProperty(role, qstr); } else if (d->isNumber()) { |