diff options
Diffstat (limited to 'src/declarative/qml/v8')
-rw-r--r-- | src/declarative/qml/v8/qjsvalue.cpp | 50 | ||||
-rw-r--r-- | src/declarative/qml/v8/qjsvalue.h | 1 | ||||
-rw-r--r-- | src/declarative/qml/v8/qjsvalue_impl_p.h | 8 | ||||
-rw-r--r-- | src/declarative/qml/v8/qjsvalue_p.h | 6 |
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; |