diff options
author | Kent Hansen <kent.hansen@nokia.com> | 2012-01-20 08:00:27 +0100 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-01-20 23:35:18 +0100 |
commit | 95cee5d6e514891aab160c8e1fc4814c147ab3a6 (patch) | |
tree | bac0e5c4bd8c23623e92f3f5de20d4acd47c7b3a /src/declarative/qml/v8 | |
parent | dfad4902b7227540baa2a15f894fe8937c3c6e15 (diff) |
Add QJSValue::call() overload
This overload takes only an argument list, not a this-object, since
that is a very common way of calling stand-alone ("non-member")
functions. Now there is no longer a need to pass a dummy value for
the this-object.
Task-number: QTBUG-23604
Change-Id: Iae952d91fce5bcaa62a05b9978c15f32802da90a
Reviewed-by: Simon Hausmann <simon.hausmann@nokia.com>
Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@nokia.com>
Diffstat (limited to 'src/declarative/qml/v8')
-rw-r--r-- | src/declarative/qml/v8/qjsvalue.cpp | 22 | ||||
-rw-r--r-- | src/declarative/qml/v8/qjsvalue.h | 1 |
2 files changed, 23 insertions, 0 deletions
diff --git a/src/declarative/qml/v8/qjsvalue.cpp b/src/declarative/qml/v8/qjsvalue.cpp index a43dd33f14..623e24b42c 100644 --- a/src/declarative/qml/v8/qjsvalue.cpp +++ b/src/declarative/qml/v8/qjsvalue.cpp @@ -696,6 +696,28 @@ QVariant QJSValue::toVariant() const return d->toVariant(); } +/*! + Calls this QJSValue as a function, passing \a args as arguments + to the function, and using the globalObject() as the "this"-object. + Returns the value returned from the function. + + If this QJSValue is not callable, call() does nothing and + returns an undefined QJSValue. + + Calling call() can cause an exception to occur in the script engine; + in that case, call() returns the value that was thrown (typically an + \c{Error} object). You can call + QJSEngine::hasUncaughtException() to determine if an exception + occurred. + + \sa isCallable() +*/ +QJSValue QJSValue::call(const QJSValueList &args) +{ + Q_D(QJSValue); + QScriptIsolate api(d->engine()); + return d->call(/*thisObject=*/0, args); +} /*! Calls this QJSValue as a function, using \a thisObject as diff --git a/src/declarative/qml/v8/qjsvalue.h b/src/declarative/qml/v8/qjsvalue.h index 8a15c4e0f2..b9278c5d04 100644 --- a/src/declarative/qml/v8/qjsvalue.h +++ b/src/declarative/qml/v8/qjsvalue.h @@ -141,6 +141,7 @@ public: QJSValue::PropertyFlags propertyFlags(const QString &name) const; bool isCallable() const; + QJSValue call(const QJSValueList &args); QJSValue call(const QJSValue &thisObject = QJSValue(), const QJSValueList &args = QJSValueList()); QJSValue construct(const QJSValueList &args = QJSValueList()); |