diff options
author | Kent Hansen <kent.hansen@nokia.com> | 2012-01-18 14:15:59 +0100 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-01-20 23:35:18 +0100 |
commit | 1d577f68883bdc41be18d2a09a5bdf0a0611c380 (patch) | |
tree | 5830fc2a3ef9e9375ed3899a7574b02e4db293e5 /src/declarative/qml/v8/qjsvalue.cpp | |
parent | 174ee897edbea436046cfe0ea02f4185e1e0de34 (diff) |
Add QJSValue::callAsConstructor() function
The old name, construct(), was bad. This name is more descriptive
and consistent with the other callXXX() functions.
Task-number: QTBUG-23604
Change-Id: Ie205b0c52721782101e665f7dfedcac9051a00d0
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 | 50 |
1 files changed, 30 insertions, 20 deletions
diff --git a/src/declarative/qml/v8/qjsvalue.cpp b/src/declarative/qml/v8/qjsvalue.cpp index cee5dfaa02..cd0bed3472 100644 --- a/src/declarative/qml/v8/qjsvalue.cpp +++ b/src/declarative/qml/v8/qjsvalue.cpp @@ -73,7 +73,7 @@ Function objects (objects for which isCallable()) returns true) can be invoked by calling call(). Constructor functions can be used to - construct new objects by calling construct(). + construct new objects by calling callAsConstructor(). Use equals() or strictlyEquals() to compare a QJSValue to another. @@ -710,7 +710,7 @@ QVariant QJSValue::toVariant() const QJSEngine::hasUncaughtException() to determine if an exception occurred. - \sa isCallable(), callWithInstance() + \sa isCallable(), callWithInstance(), callAsConstructor() */ QJSValue QJSValue::call(const QJSValueList &args) { @@ -738,8 +738,6 @@ QJSValue QJSValue::call(const QJSValueList &args) QJSEngine::hasUncaughtException() to determine if an exception occurred. - \snippet doc/src/snippets/code/src_script_qjsvalue.cpp 1 - \sa call() */ QJSValue QJSValue::callWithInstance(const QJSValue &instance, const QJSValueList &args) @@ -750,6 +748,31 @@ QJSValue QJSValue::callWithInstance(const QJSValue &instance, const QJSValueList } /*! + Creates a new \c{Object} and calls this QJSValue as a + constructor, using the created object as the `this' object and + passing \a args as arguments. If the return value from the + constructor call is an object, then that object is returned; + otherwise the default constructed object is returned. + + If this QJSValue is not a function, callAsConstructor() does + nothing and returns an undefined QJSValue. + + Calling this function can cause an exception to occur in the + script engine; in that case, the value that was thrown + (typically an \c{Error} object) is returned. You can call + QJSEngine::hasUncaughtException() to determine if an exception + occurred. + + \sa call(), QJSEngine::newObject() +*/ +QJSValue QJSValue::callAsConstructor(const QJSValueList &args) +{ + Q_D(QJSValue); + QScriptIsolate api(d->engine()); + return QJSValuePrivate::get(d->callAsConstructor(args)); +} + +/*! \obsolete Use callWithInstance() instead. @@ -762,28 +785,15 @@ QJSValue QJSValue::call(const QJSValue& thisObject, const QJSValueList& args) } /*! - Creates a new \c{Object} and calls this QJSValue as a - constructor, using the created object as the `this' object and - passing \a args as arguments. If the return value from the - constructor call is an object, then that object is returned; - otherwise the default constructed object is returned. - - If this QJSValue is not a function, construct() does nothing - and returns an invalid QJSValue. - - Calling construct() can cause an exception to occur in the script - engine; in that case, construct() returns the value that was thrown - (typically an \c{Error} object). You can call - QJSEngine::hasUncaughtException() to determine if an exception - occurred. + \obsolete - \sa call(), QJSEngine::newObject() + Use callAsConstructor() instead. */ QJSValue QJSValue::construct(const QJSValueList &args) { Q_D(QJSValue); QScriptIsolate api(d->engine()); - return QJSValuePrivate::get(d->construct(args)); + return QJSValuePrivate::get(d->callAsConstructor(args)); } /*! |