From d6c6ac356d2e5dc6af1b368c89124143b161fc4e Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Wed, 22 Jul 2009 16:42:35 +0200 Subject: More tests fixed (QScriptValue::toString) Handle Exception in a toString function Reviewed-by: Kent Hansen --- src/script/api/qscriptvalue.cpp | 8 ++++++++ tests/auto/qscriptvalue/tst_qscriptvalue.cpp | 4 ---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/script/api/qscriptvalue.cpp b/src/script/api/qscriptvalue.cpp index 79c769a..b23ac2c 100644 --- a/src/script/api/qscriptvalue.cpp +++ b/src/script/api/qscriptvalue.cpp @@ -1237,6 +1237,14 @@ QString QScriptValue::toString() const JSC::JSValue savedException; QScriptValuePrivate::saveException(exec, &savedException); JSC::UString str = d->jscValue.toString(exec); + if (exec && exec->hadException()) { + JSC::JSValue savedException2; + QScriptValuePrivate::saveException(exec, &savedException2); + if (!str.size()) + str = savedException2.toString(exec); + if (!eng_p->uncaughtException) + eng_p->uncaughtException = savedException2; + } QScriptValuePrivate::restoreException(exec, savedException); return QString(reinterpret_cast(str.data()), str.size()); } diff --git a/tests/auto/qscriptvalue/tst_qscriptvalue.cpp b/tests/auto/qscriptvalue/tst_qscriptvalue.cpp index ddd846a..2ed6d6f 100644 --- a/tests/auto/qscriptvalue/tst_qscriptvalue.cpp +++ b/tests/auto/qscriptvalue/tst_qscriptvalue.cpp @@ -392,11 +392,8 @@ void tst_QScriptValue::toString() " o.toString = function() { throw new Error('toString'); };" " return o;" "})()"); - QEXPECT_FAIL("", "Should produce an error message (or should it?)", Continue); QCOMPARE(objectObject.toString(), QLatin1String("Error: toString")); - QEXPECT_FAIL("", "hasUncaughtException() should return true", Continue); QVERIFY(eng.hasUncaughtException()); - QEXPECT_FAIL("", "Should produce an error message (or should it?)", Continue); QCOMPARE(eng.uncaughtException().toString(), QLatin1String("Error: toString")); } { @@ -411,7 +408,6 @@ void tst_QScriptValue::toString() QVERIFY(objectObject.isObject()); QEXPECT_FAIL("", "Should return an error string", Continue); QCOMPARE(objectObject.toString(), QString::fromLatin1("TypeError: Function.prototype.toString called on incompatible object")); - QEXPECT_FAIL("", "hasUncaughtException() should return true", Continue); QVERIFY(eng.hasUncaughtException()); eng.clearExceptions(); } -- cgit v0.12