From de6b46d64a193278f6f4c0d8967783d47f605ca0 Mon Sep 17 00:00:00 2001 From: Kent Hansen Date: Thu, 18 Mar 2010 18:15:40 +0100 Subject: Don't assert in QScriptValue::call() Oops, the case of a non-array object argument wasn't implemented nor tested in the new back-end. This commit brings it in line with the behavior of the old back-end. Also test that QScriptValue::construct() doesn't have the same problem. Reviewed-by: TrustMe --- src/script/api/qscriptvalue.cpp | 5 ++--- tests/auto/qscriptvalue/tst_qscriptvalue.cpp | 8 ++++++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/script/api/qscriptvalue.cpp b/src/script/api/qscriptvalue.cpp index 5bfe46a..8cf01e7 100644 --- a/src/script/api/qscriptvalue.cpp +++ b/src/script/api/qscriptvalue.cpp @@ -1946,7 +1946,7 @@ QScriptValue QScriptValue::call(const QScriptValue &thisObject, JSC::MarkedArgumentBuffer applyArgs; if (!array.isUndefinedOrNull()) { if (!array.isObject()) { - return d->engine->scriptValueFromJSCValue(JSC::throwError(exec, JSC::TypeError)); + return d->engine->scriptValueFromJSCValue(JSC::throwError(exec, JSC::TypeError, "Arguments must be an array")); } if (JSC::asObject(array)->classInfo() == &JSC::Arguments::info) JSC::asArguments(array)->fillArgList(exec, applyArgs); @@ -1957,8 +1957,7 @@ QScriptValue QScriptValue::call(const QScriptValue &thisObject, for (unsigned i = 0; i < length; ++i) applyArgs.append(JSC::asArray(array)->get(exec, i)); } else { - Q_ASSERT_X(false, Q_FUNC_INFO, "implement me"); -// return JSC::throwError(exec, JSC::TypeError); + return d->engine->scriptValueFromJSCValue(JSC::throwError(exec, JSC::TypeError, "Arguments must be an array")); } } diff --git a/tests/auto/qscriptvalue/tst_qscriptvalue.cpp b/tests/auto/qscriptvalue/tst_qscriptvalue.cpp index f83cf58..b2f6caf 100644 --- a/tests/auto/qscriptvalue/tst_qscriptvalue.cpp +++ b/tests/auto/qscriptvalue/tst_qscriptvalue.cpp @@ -2571,6 +2571,10 @@ void tst_QScriptValue::call() // call with something else as arguments QScriptValue ret5 = fun.call(QScriptValue(), QScriptValue(&eng, 123.0)); QCOMPARE(ret5.isError(), true); + // call with a non-array object as arguments + QScriptValue ret6 = fun.call(QScriptValue(), eng.globalObject()); + QVERIFY(ret6.isError()); + QCOMPARE(ret6.toString(), QString::fromLatin1("TypeError: Arguments must be an array")); } // calling things that are not functions @@ -2703,6 +2707,10 @@ void tst_QScriptValue::construct() // construct with something else as arguments QScriptValue ret5 = fun.construct(QScriptValue(&eng, 123.0)); QCOMPARE(ret5.isError(), true); + // construct with a non-array object as arguments + QScriptValue ret6 = fun.construct(eng.globalObject()); + QVERIFY(ret6.isError()); + QCOMPARE(ret6.toString(), QString::fromLatin1("TypeError: Arguments must be an array")); } // construct on things that are not functions -- cgit v0.12