aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/qml/jsapi/qjsengine.cpp14
-rw-r--r--src/qml/jsapi/qjsengine.h1
-rw-r--r--tests/auto/qml/qjsengine/tst_qjsengine.cpp6
3 files changed, 19 insertions, 2 deletions
diff --git a/src/qml/jsapi/qjsengine.cpp b/src/qml/jsapi/qjsengine.cpp
index f0e3e69fbb..37b5306897 100644
--- a/src/qml/jsapi/qjsengine.cpp
+++ b/src/qml/jsapi/qjsengine.cpp
@@ -939,6 +939,20 @@ void QJSEngine::throwError(QJSValue::ErrorType errorType, const QString &message
}
/*!
+ \overload throwError()
+
+ Throws a pre-constructed run-time \a error (exception). This way you can
+ use \l newErrorObject() to create the error and customize it as necessary.
+
+ \since 6.1
+ \sa {Script Exceptions}, newErrorObject()
+*/
+void QJSEngine::throwError(const QJSValue &error)
+{
+ m_v4Engine->throwError(QJSValuePrivate::asReturnedValue(&error));
+}
+
+/*!
* Returns \c true if the last JavaScript execution resulted in an exception or
* if throwError() was called. Otherwise returns \c false. Mind that evaluate()
* catches any exceptions thrown in the evaluated code.
diff --git a/src/qml/jsapi/qjsengine.h b/src/qml/jsapi/qjsengine.h
index 9b02469b23..783f602c12 100644
--- a/src/qml/jsapi/qjsengine.h
+++ b/src/qml/jsapi/qjsengine.h
@@ -134,6 +134,7 @@ public:
void throwError(const QString &message);
void throwError(QJSValue::ErrorType errorType, const QString &message = QString());
+ void throwError(const QJSValue &error);
bool hasError() const;
QJSValue catchError();
diff --git a/tests/auto/qml/qjsengine/tst_qjsengine.cpp b/tests/auto/qml/qjsengine/tst_qjsengine.cpp
index a5316dce21..85d61a3537 100644
--- a/tests/auto/qml/qjsengine/tst_qjsengine.cpp
+++ b/tests/auto/qml/qjsengine/tst_qjsengine.cpp
@@ -4826,7 +4826,7 @@ void tst_QJSEngine::catchError()
QJSValue tst_QJSEngine::throwingCppMethod1()
{
- qjsEngine(this)->throwError("blub");
+ qjsEngine(this)->throwError(QStringLiteral("blub"));
return QJSValue(47);
}
@@ -4837,7 +4837,9 @@ void tst_QJSEngine::throwingCppMethod2()
QJSValue tst_QJSEngine::throwingCppMethod3()
{
- return qjsEngine(this)->newErrorObject(QJSValue::EvalError, "Something is wrong");
+ QJSEngine *engine = qjsEngine(this);
+ engine->throwError(engine->newErrorObject(QJSValue::EvalError, "Something is wrong"));
+ return QJSValue(31);
}
void tst_QJSEngine::mathMinMax()