From 95cee5d6e514891aab160c8e1fc4814c147ab3a6 Mon Sep 17 00:00:00 2001 From: Kent Hansen Date: Fri, 20 Jan 2012 08:00:27 +0100 Subject: Add QJSValue::call() overload MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-by: Jędrzej Nowacki --- src/declarative/qml/v8/qjsvalue.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'src/declarative/qml/v8/qjsvalue.cpp') 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 -- cgit v1.2.3