aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorKent Hansen <kent.hansen@nokia.com>2012-01-18 14:15:59 +0100
committerQt by Nokia <qt-info@nokia.com>2012-01-20 23:35:18 +0100
commit1d577f68883bdc41be18d2a09a5bdf0a0611c380 (patch)
tree5830fc2a3ef9e9375ed3899a7574b02e4db293e5 /src
parent174ee897edbea436046cfe0ea02f4185e1e0de34 (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')
-rw-r--r--src/declarative/qml/v8/qjsvalue.cpp50
-rw-r--r--src/declarative/qml/v8/qjsvalue.h1
-rw-r--r--src/declarative/qml/v8/qjsvalue_impl_p.h8
-rw-r--r--src/declarative/qml/v8/qjsvalue_p.h6
4 files changed, 38 insertions, 27 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));
}
/*!
diff --git a/src/declarative/qml/v8/qjsvalue.h b/src/declarative/qml/v8/qjsvalue.h
index f3988d1819..b6e8e6a416 100644
--- a/src/declarative/qml/v8/qjsvalue.h
+++ b/src/declarative/qml/v8/qjsvalue.h
@@ -143,6 +143,7 @@ public:
bool isCallable() const;
QJSValue call(const QJSValueList &args);
QJSValue callWithInstance(const QJSValue &instance, const QJSValueList &args = QJSValueList());
+ QJSValue callAsConstructor(const QJSValueList &args = QJSValueList());
QJSValue call(const QJSValue &thisObject = QJSValue(),
const QJSValueList &args = QJSValueList());
QJSValue construct(const QJSValueList &args = QJSValueList());
diff --git a/src/declarative/qml/v8/qjsvalue_impl_p.h b/src/declarative/qml/v8/qjsvalue_impl_p.h
index 6e1cc4bbaf..9fad4c2be3 100644
--- a/src/declarative/qml/v8/qjsvalue_impl_p.h
+++ b/src/declarative/qml/v8/qjsvalue_impl_p.h
@@ -974,7 +974,7 @@ QScriptPassPointer<QJSValuePrivate> QJSValuePrivate::call(QJSValuePrivate* thisO
return new QJSValuePrivate(e, result);
}
-inline QScriptPassPointer<QJSValuePrivate> QJSValuePrivate::construct(int argc, v8::Handle<v8::Value> *argv)
+inline QScriptPassPointer<QJSValuePrivate> QJSValuePrivate::callAsConstructor(int argc, v8::Handle<v8::Value> *argv)
{
QV8Engine *e = engine();
@@ -995,7 +995,7 @@ inline QScriptPassPointer<QJSValuePrivate> QJSValuePrivate::construct(int argc,
return new QJSValuePrivate(e, result);
}
-inline QScriptPassPointer<QJSValuePrivate> QJSValuePrivate::construct(const QJSValueList& args)
+inline QScriptPassPointer<QJSValuePrivate> QJSValuePrivate::callAsConstructor(const QJSValueList& args)
{
if (!isCallable())
return InvalidValue();
@@ -1006,11 +1006,11 @@ inline QScriptPassPointer<QJSValuePrivate> QJSValuePrivate::construct(const QJSV
int argc = args.size();
QVarLengthArray<v8::Handle<v8::Value>, 8> argv(argc);
if (!prepareArgumentsForCall(argv.data(), args)) {
- qWarning("QJSValue::construct() failed: cannot construct function with argument created in a different engine");
+ qWarning("QJSValue::callAsConstructor() failed: cannot construct function with argument created in a different engine");
return InvalidValue();
}
- return construct(argc, argv.data());
+ return callAsConstructor(argc, argv.data());
}
/*! \internal
diff --git a/src/declarative/qml/v8/qjsvalue_p.h b/src/declarative/qml/v8/qjsvalue_p.h
index c3677e351d..87bcfda62a 100644
--- a/src/declarative/qml/v8/qjsvalue_p.h
+++ b/src/declarative/qml/v8/qjsvalue_p.h
@@ -138,9 +138,9 @@ public:
inline QScriptPassPointer<QJSValuePrivate> call(QJSValuePrivate* thisObject, const QJSValueList& args);
inline QScriptPassPointer<QJSValuePrivate> call(QJSValuePrivate* thisObject, const QJSValue& arguments);
inline QScriptPassPointer<QJSValuePrivate> call(QJSValuePrivate* thisObject, int argc, v8::Handle< v8::Value >* argv);
- inline QScriptPassPointer<QJSValuePrivate> construct(int argc, v8::Handle<v8::Value> *argv);
- inline QScriptPassPointer<QJSValuePrivate> construct(const QJSValueList& args);
- inline QScriptPassPointer<QJSValuePrivate> construct(const QJSValue& arguments);
+ inline QScriptPassPointer<QJSValuePrivate> callAsConstructor(int argc, v8::Handle<v8::Value> *argv);
+ inline QScriptPassPointer<QJSValuePrivate> callAsConstructor(const QJSValueList& args);
+ inline QScriptPassPointer<QJSValuePrivate> callAsConstructor(const QJSValue& arguments);
inline bool assignEngine(QV8Engine *engine);
inline QV8Engine *engine() const;