summaryrefslogtreecommitdiffstats
path: root/tests/auto/qscriptvalue/tst_qscriptvalue.cpp
diff options
context:
space:
mode:
authorKent Hansen <kent.hansen@nokia.com>2010-10-28 10:27:49 (GMT)
committerKent Hansen <kent.hansen@nokia.com>2010-10-28 11:27:52 (GMT)
commit746f4b50e9c13c720162f3bcc8795b7ef772fbba (patch)
treee2f1bf826d24d97f5879e9c29d66c3ceafe07b8b /tests/auto/qscriptvalue/tst_qscriptvalue.cpp
parent7537554040827dbaae327d27c77319e6b7e7c618 (diff)
downloadQt-746f4b50e9c13c720162f3bcc8795b7ef772fbba.zip
Qt-746f4b50e9c13c720162f3bcc8795b7ef772fbba.tar.gz
Qt-746f4b50e9c13c720162f3bcc8795b7ef772fbba.tar.bz2
QScriptValue::construct(): Don't crash if function throws non-Object
If an exception occurs, we should ignore the result of JSC::construct() and return the exception value, even if the exception is not an object. This makes the behavior match the documentation: "Calling construct() can cause an exception to occur in the script engine; in that case, construct() returns the value that was thrown". Task-number: QTBUG-14801 Reviewed-by: Jedrzej Nowacki
Diffstat (limited to 'tests/auto/qscriptvalue/tst_qscriptvalue.cpp')
-rw-r--r--tests/auto/qscriptvalue/tst_qscriptvalue.cpp25
1 files changed, 25 insertions, 0 deletions
diff --git a/tests/auto/qscriptvalue/tst_qscriptvalue.cpp b/tests/auto/qscriptvalue/tst_qscriptvalue.cpp
index 83a3388..639df36 100644
--- a/tests/auto/qscriptvalue/tst_qscriptvalue.cpp
+++ b/tests/auto/qscriptvalue/tst_qscriptvalue.cpp
@@ -2739,6 +2739,31 @@ void tst_QScriptValue::construct()
QVERIFY(!QScriptValue(QScriptValue::NullValue).construct().isValid());
}
+void tst_QScriptValue::construct_constructorThrowsPrimitive()
+{
+ QScriptEngine eng;
+ QScriptValue fun = eng.evaluate("(function() { throw 123; })");
+ QVERIFY(fun.isFunction());
+ // construct(QScriptValueList)
+ {
+ QScriptValue ret = fun.construct();
+ QVERIFY(ret.isNumber());
+ QCOMPARE(ret.toNumber(), 123.0);
+ QVERIFY(eng.hasUncaughtException());
+ QVERIFY(ret.strictlyEquals(eng.uncaughtException()));
+ eng.clearExceptions();
+ }
+ // construct(QScriptValue)
+ {
+ QScriptValue ret = fun.construct(eng.newArray());
+ QVERIFY(ret.isNumber());
+ QCOMPARE(ret.toNumber(), 123.0);
+ QVERIFY(eng.hasUncaughtException());
+ QVERIFY(ret.strictlyEquals(eng.uncaughtException()));
+ eng.clearExceptions();
+ }
+}
+
void tst_QScriptValue::lessThan_old()
{
QScriptEngine eng;