From 174ee897edbea436046cfe0ea02f4185e1e0de34 Mon Sep 17 00:00:00 2001 From: Kent Hansen Date: Wed, 18 Jan 2012 14:01:39 +0100 Subject: Add QJSValue::callWithInstance() function MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit With the deprecated call() overload, it was confusing what the first argument was (the this-object or an actual argument passed to the function). Introduce a dedicated function for the "explicit this-object" case. This makes code more readable, and eliminates the need to pass a "dummy" this-object to call() in the quite common case where you don't care about the this-object. Task-number: QTBUG-23604 Change-Id: I18f8be6592a848436351516bea266fc7e9195777 Reviewed-by: Simon Hausmann Reviewed-by: Jędrzej Nowacki --- src/declarative/qml/v8/qjsvalue.cpp | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (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 623e24b42c..cee5dfaa02 100644 --- a/src/declarative/qml/v8/qjsvalue.cpp +++ b/src/declarative/qml/v8/qjsvalue.cpp @@ -710,7 +710,7 @@ QVariant QJSValue::toVariant() const QJSEngine::hasUncaughtException() to determine if an exception occurred. - \sa isCallable() + \sa isCallable(), callWithInstance() */ QJSValue QJSValue::call(const QJSValueList &args) { @@ -720,7 +720,7 @@ QJSValue QJSValue::call(const QJSValueList &args) } /*! - Calls this QJSValue as a function, using \a thisObject as + Calls this QJSValue as a function, using \a instance as the `this' object in the function call, and passing \a args as arguments to the function. Returns the value returned from the function. @@ -728,7 +728,7 @@ QJSValue QJSValue::call(const QJSValueList &args) If this QJSValue is not a function, call() does nothing and returns an invalid QJSValue. - Note that if \a thisObject is not an object, the global object + Note that if \a instance is not an object, the global object (see \l{QJSEngine::globalObject()}) will be used as the `this' object. @@ -740,7 +740,19 @@ QJSValue QJSValue::call(const QJSValueList &args) \snippet doc/src/snippets/code/src_script_qjsvalue.cpp 1 - \sa construct() + \sa call() +*/ +QJSValue QJSValue::callWithInstance(const QJSValue &instance, const QJSValueList &args) +{ + Q_D(QJSValue); + QScriptIsolate api(d->engine()); + return d->call(QJSValuePrivate::get(instance), args); +} + +/*! + \obsolete + + Use callWithInstance() instead. */ QJSValue QJSValue::call(const QJSValue& thisObject, const QJSValueList& args) { -- cgit v1.2.3