aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/jsapi
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@digia.com>2013-10-22 10:48:21 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-10-29 10:38:57 +0100
commit2b996ca17fbc36029af3900933b6fcc1418afb6a (patch)
tree1c3712947febfedc5bb5566053ab0e7093eeabc6 /src/qml/jsapi
parente0284ab41f7a1889f28e719212df66e942959f4c (diff)
Correctly catch exceptions in the API methods
Replace all C++ try/catch statements with engine->hasException checks. Change-Id: I7c04e02664ec6b4d256478c6e18f6b20ae4f7bc1 Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Diffstat (limited to 'src/qml/jsapi')
-rw-r--r--src/qml/jsapi/qjsvalue.cpp81
-rw-r--r--src/qml/jsapi/qjsvalueiterator.cpp23
2 files changed, 47 insertions, 57 deletions
diff --git a/src/qml/jsapi/qjsvalue.cpp b/src/qml/jsapi/qjsvalue.cpp
index 29734fda92..9031187d7e 100644
--- a/src/qml/jsapi/qjsvalue.cpp
+++ b/src/qml/jsapi/qjsvalue.cpp
@@ -377,12 +377,12 @@ QString QJSValue::toString() const
double QJSValue::toNumber() const
{
QV4::ExecutionContext *ctx = d->engine ? d->engine->current : 0;
- try {
- return d->value.toNumber();
- } catch (...) {
+ double dbl = d->value.toNumber();
+ if (ctx && ctx->engine->hasException) {
ctx->catchException();
return 0;
}
+ return dbl;
}
/*!
@@ -400,12 +400,12 @@ double QJSValue::toNumber() const
bool QJSValue::toBool() const
{
QV4::ExecutionContext *ctx = d->engine ? d->engine->current : 0;
- try {
- return d->value.toBoolean();
- } catch (...) {
+ bool b = d->value.toBoolean();
+ if (ctx && ctx->engine->hasException) {
ctx->catchException();
return false;
}
+ return b;
}
/*!
@@ -423,12 +423,12 @@ bool QJSValue::toBool() const
qint32 QJSValue::toInt() const
{
QV4::ExecutionContext *ctx = d->engine ? d->engine->current : 0;
- try {
- return d->value.toInt32();
- } catch (...) {
+ qint32 i = d->value.toInt32();
+ if (ctx && ctx->engine->hasException) {
ctx->catchException();
return 0;
}
+ return i;
}
/*!
@@ -446,12 +446,12 @@ qint32 QJSValue::toInt() const
quint32 QJSValue::toUInt() const
{
QV4::ExecutionContext *ctx = d->engine ? d->engine->current : 0;
- try {
- return d->value.toUInt32();
- } catch (...) {
+ quint32 u = d->value.toUInt32();
+ if (ctx && ctx->engine->hasException) {
ctx->catchException();
return 0;
}
+ return u;
}
/*!
@@ -518,11 +518,9 @@ QJSValue QJSValue::call(const QJSValueList &args)
ScopedValue result(scope);
QV4::ExecutionContext *ctx = engine->current;
- try {
- result = f->call(callData);
- } catch (...) {
+ result = f->call(callData);
+ if (scope.hasException())
result = ctx->catchException();
- }
return new QJSValuePrivate(engine, result);
}
@@ -574,11 +572,9 @@ QJSValue QJSValue::callWithInstance(const QJSValue &instance, const QJSValueList
ScopedValue result(scope);
QV4::ExecutionContext *ctx = engine->current;
- try {
- result = f->call(callData);
- } catch (...) {
+ result = f->call(callData);
+ if (scope.hasException())
result = ctx->catchException();
- }
return new QJSValuePrivate(engine, result);
}
@@ -622,11 +618,9 @@ QJSValue QJSValue::callAsConstructor(const QJSValueList &args)
ScopedValue result(scope);
QV4::ExecutionContext *ctx = engine->current;
- try {
- result = f->construct(callData);
- } catch (...) {
+ result = f->construct(callData);
+ if (scope.hasException())
result = ctx->catchException();
- }
return new QJSValuePrivate(engine, result);
}
@@ -813,11 +807,10 @@ QJSValue QJSValue::property(const QString& name) const
s->makeIdentifier();
QV4::ExecutionContext *ctx = engine->current;
QV4::ScopedValue result(scope);
- try {
- result = o->get(s);
- } catch (...) {
+ result = o->get(s);
+ if (scope.hasException())
result = ctx->catchException();
- }
+
return new QJSValuePrivate(engine, result);
}
@@ -846,11 +839,9 @@ QJSValue QJSValue::property(quint32 arrayIndex) const
QV4::ExecutionContext *ctx = engine->current;
QV4::ScopedValue result(scope);
- try {
- result = arrayIndex == UINT_MAX ? o->get(engine->id_uintMax) : o->getIndexed(arrayIndex);
- } catch (...) {
+ result = arrayIndex == UINT_MAX ? o->get(engine->id_uintMax) : o->getIndexed(arrayIndex);
+ if (scope.hasException())
result = ctx->catchException();
- }
return new QJSValuePrivate(engine, result);
}
@@ -890,12 +881,10 @@ void QJSValue::setProperty(const QString& name, const QJSValue& value)
QV4::ExecutionContext *ctx = engine->current;
s->makeIdentifier();
- try {
- QV4::ScopedValue v(scope, value.d->getValue(engine));
- o->put(s, v);
- } catch (...) {
+ QV4::ScopedValue v(scope, value.d->getValue(engine));
+ o->put(s, v);
+ if (scope.hasException())
ctx->catchException();
- }
}
/*!
@@ -923,14 +912,12 @@ void QJSValue::setProperty(quint32 arrayIndex, const QJSValue& value)
QV4::ExecutionContext *ctx = engine->current;
QV4::ScopedValue v(scope, value.d->getValue(engine));
- try {
- if (arrayIndex != UINT_MAX)
- o->putIndexed(arrayIndex, v);
- else
- o->put(engine->id_uintMax, v);
- } catch (...) {
+ if (arrayIndex != UINT_MAX)
+ o->putIndexed(arrayIndex, v);
+ else
+ o->put(engine->id_uintMax, v);
+ if (scope.hasException())
ctx->catchException();
- }
}
/*!
@@ -956,13 +943,17 @@ void QJSValue::setProperty(quint32 arrayIndex, const QJSValue& value)
bool QJSValue::deleteProperty(const QString &name)
{
ExecutionEngine *engine = d->engine;
+ ExecutionContext *ctx = engine->current;
Scope scope(engine);
ScopedObject o(scope, d->value.asObject());
if (!o)
return false;
ScopedString s(scope, engine->newString(name));
- return o->deleteProperty(s);
+ bool b = o->deleteProperty(s);
+ if (scope.hasException())
+ ctx->catchException();
+ return b;
}
/*!
diff --git a/src/qml/jsapi/qjsvalueiterator.cpp b/src/qml/jsapi/qjsvalueiterator.cpp
index dcf7c4755b..245b75b384 100644
--- a/src/qml/jsapi/qjsvalueiterator.cpp
+++ b/src/qml/jsapi/qjsvalueiterator.cpp
@@ -199,21 +199,20 @@ QJSValue QJSValueIterator::value() const
QV4::ScopedObject o(scope, it->it.object);
QV4::ExecutionContext *ctx = engine->current;
- try {
- QV4::ScopedValue v(scope);
- if (!!d_ptr->currentName) {
- QV4::ScopedString n(scope, d_ptr->currentName);
- v = o->get(n);
- } else if (d_ptr->currentIndex != UINT_MAX) {
- v = o->getIndexed(d_ptr->currentIndex);
- } else {
- return QJSValue();
- }
- return new QJSValuePrivate(engine, v);
- } catch (...) {
+ QV4::ScopedValue v(scope);
+ if (!!d_ptr->currentName) {
+ QV4::ScopedString n(scope, d_ptr->currentName);
+ v = o->get(n);
+ } else if (d_ptr->currentIndex != UINT_MAX) {
+ v = o->getIndexed(d_ptr->currentIndex);
+ } else {
+ return QJSValue();
+ }
+ if (scope.hasException()) {
ctx->catchException();
return QJSValue();
}
+ return new QJSValuePrivate(engine, v);
}