diff options
author | Kent Hansen <kent.hansen@nokia.com> | 2012-01-18 14:01:39 +0100 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-01-20 23:35:18 +0100 |
commit | 174ee897edbea436046cfe0ea02f4185e1e0de34 (patch) | |
tree | 5ec724de6413a6ff4aaf196489cec39f8739956c /src/declarative/qml/v8/qjsvalue.cpp | |
parent | 95cee5d6e514891aab160c8e1fc4814c147ab3a6 (diff) |
Add QJSValue::callWithInstance() function
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 <simon.hausmann@nokia.com>
Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@nokia.com>
Diffstat (limited to 'src/declarative/qml/v8/qjsvalue.cpp')
-rw-r--r-- | src/declarative/qml/v8/qjsvalue.cpp | 20 |
1 files changed, 16 insertions, 4 deletions
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) { |