diff options
author | Lars Knoll <lars.knoll@qt.io> | 2017-01-05 22:21:35 +0100 |
---|---|---|
committer | Lars Knoll <lars.knoll@qt.io> | 2017-01-25 08:31:28 +0000 |
commit | 25552c1404dff66ae9681e57f2b9a8be08d3828a (patch) | |
tree | f0f00a1e53d1eedc0ee93f32243555a4d43eeeaa /src/qml/jsruntime | |
parent | 381e3151aea83806fb5bea2407fef67de3cc5014 (diff) |
Convert more builtin functions to the new calling convention
Change-Id: I053215261e1186aff25f29e0967219ef667f7678
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src/qml/jsruntime')
-rw-r--r-- | src/qml/jsruntime/qv4qobjectwrapper.cpp | 65 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4qobjectwrapper_p.h | 4 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4scopedvalue_p.h | 6 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4sequenceobject.cpp | 64 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4sequenceobject_p.h | 6 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4variantobject.cpp | 47 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4variantobject_p.h | 8 |
7 files changed, 100 insertions, 100 deletions
diff --git a/src/qml/jsruntime/qv4qobjectwrapper.cpp b/src/qml/jsruntime/qv4qobjectwrapper.cpp index 77dbb18b50..7260e71fab 100644 --- a/src/qml/jsruntime/qv4qobjectwrapper.cpp +++ b/src/qml/jsruntime/qv4qobjectwrapper.cpp @@ -826,40 +826,39 @@ struct QObjectSlotDispatcher : public QtPrivate::QSlotObjectBase } // namespace QV4 -ReturnedValue QObjectWrapper::method_connect(CallContext *ctx) +void QObjectWrapper::method_connect(const BuiltinFunction *, Scope &scope, CallData *callData) { - if (ctx->argc() == 0) - V4THROW_ERROR("Function.prototype.connect: no arguments given"); + if (callData->argc == 0) + THROW_GENERIC_ERROR("Function.prototype.connect: no arguments given"); - QPair<QObject *, int> signalInfo = extractQtSignal(ctx->thisObject()); + QPair<QObject *, int> signalInfo = extractQtSignal(callData->thisObject); QObject *signalObject = signalInfo.first; int signalIndex = signalInfo.second; // in method range, not signal range! if (signalIndex < 0) - V4THROW_ERROR("Function.prototype.connect: this object is not a signal"); + THROW_GENERIC_ERROR("Function.prototype.connect: this object is not a signal"); if (!signalObject) - V4THROW_ERROR("Function.prototype.connect: cannot connect to deleted QObject"); + THROW_GENERIC_ERROR("Function.prototype.connect: cannot connect to deleted QObject"); if (signalObject->metaObject()->method(signalIndex).methodType() != QMetaMethod::Signal) - V4THROW_ERROR("Function.prototype.connect: this object is not a signal"); + THROW_GENERIC_ERROR("Function.prototype.connect: this object is not a signal"); - QV4::Scope scope(ctx); QV4::ScopedFunctionObject f(scope); QV4::ScopedValue thisObject (scope, QV4::Encode::undefined()); - if (ctx->argc() == 1) { - f = ctx->args()[0]; - } else if (ctx->argc() >= 2) { - thisObject = ctx->args()[0]; - f = ctx->args()[1]; + if (callData->argc == 1) { + f = callData->args[0]; + } else if (callData->argc >= 2) { + thisObject = callData->args[0]; + f = callData->args[1]; } if (!f) - V4THROW_ERROR("Function.prototype.connect: target is not a function"); + THROW_GENERIC_ERROR("Function.prototype.connect: target is not a function"); if (!thisObject->isUndefined() && !thisObject->isObject()) - V4THROW_ERROR("Function.prototype.connect: target this is not an object"); + THROW_GENERIC_ERROR("Function.prototype.connect: target this is not an object"); QV4::QObjectSlotDispatcher *slot = new QV4::QObjectSlotDispatcher; slot->signalIndex = signalIndex; @@ -874,49 +873,47 @@ ReturnedValue QObjectWrapper::method_connect(CallContext *ctx) } QObjectPrivate::connect(signalObject, signalIndex, slot, Qt::AutoConnection); - return Encode::undefined(); + RETURN_UNDEFINED(); } -ReturnedValue QObjectWrapper::method_disconnect(CallContext *ctx) +void QObjectWrapper::method_disconnect(const BuiltinFunction *, Scope &scope, CallData *callData) { - if (ctx->argc() == 0) - V4THROW_ERROR("Function.prototype.disconnect: no arguments given"); - - QV4::Scope scope(ctx); + if (callData->argc == 0) + THROW_GENERIC_ERROR("Function.prototype.disconnect: no arguments given"); - QPair<QObject *, int> signalInfo = extractQtSignal(ctx->thisObject()); + QPair<QObject *, int> signalInfo = extractQtSignal(callData->thisObject); QObject *signalObject = signalInfo.first; int signalIndex = signalInfo.second; if (signalIndex == -1) - V4THROW_ERROR("Function.prototype.disconnect: this object is not a signal"); + THROW_GENERIC_ERROR("Function.prototype.disconnect: this object is not a signal"); if (!signalObject) - V4THROW_ERROR("Function.prototype.disconnect: cannot disconnect from deleted QObject"); + THROW_GENERIC_ERROR("Function.prototype.disconnect: cannot disconnect from deleted QObject"); if (signalIndex < 0 || signalObject->metaObject()->method(signalIndex).methodType() != QMetaMethod::Signal) - V4THROW_ERROR("Function.prototype.disconnect: this object is not a signal"); + THROW_GENERIC_ERROR("Function.prototype.disconnect: this object is not a signal"); QV4::ScopedFunctionObject functionValue(scope); QV4::ScopedValue functionThisValue(scope, QV4::Encode::undefined()); - if (ctx->argc() == 1) { - functionValue = ctx->args()[0]; - } else if (ctx->argc() >= 2) { - functionThisValue = ctx->args()[0]; - functionValue = ctx->args()[1]; + if (callData->argc == 1) { + functionValue = callData->args[0]; + } else if (callData->argc >= 2) { + functionThisValue = callData->args[0]; + functionValue = callData->args[1]; } if (!functionValue) - V4THROW_ERROR("Function.prototype.disconnect: target is not a function"); + THROW_GENERIC_ERROR("Function.prototype.disconnect: target is not a function"); if (!functionThisValue->isUndefined() && !functionThisValue->isObject()) - V4THROW_ERROR("Function.prototype.disconnect: target this is not an object"); + THROW_GENERIC_ERROR("Function.prototype.disconnect: target this is not an object"); QPair<QObject *, int> functionData = QObjectMethod::extractQtMethod(functionValue); void *a[] = { - ctx->d()->engine, + scope.engine, functionValue.ptr, functionThisValue.ptr, functionData.first, @@ -925,7 +922,7 @@ ReturnedValue QObjectWrapper::method_disconnect(CallContext *ctx) QObjectPrivate::disconnect(signalObject, signalIndex, reinterpret_cast<void**>(&a)); - return Encode::undefined(); + RETURN_UNDEFINED(); } static void markChildQObjectsRecursively(QObject *parent, QV4::ExecutionEngine *e) diff --git a/src/qml/jsruntime/qv4qobjectwrapper_p.h b/src/qml/jsruntime/qv4qobjectwrapper_p.h index c7c4f4dd77..b09e06cec5 100644 --- a/src/qml/jsruntime/qv4qobjectwrapper_p.h +++ b/src/qml/jsruntime/qv4qobjectwrapper_p.h @@ -197,8 +197,8 @@ protected: static void advanceIterator(Managed *m, ObjectIterator *it, Value *name, uint *index, Property *p, PropertyAttributes *attributes); static void markObjects(Heap::Base *that, QV4::ExecutionEngine *e); - static ReturnedValue method_connect(CallContext *ctx); - static ReturnedValue method_disconnect(CallContext *ctx); + static void method_connect(const BuiltinFunction *, Scope &scope, CallData *callData); + static void method_disconnect(const BuiltinFunction *, Scope &scope, CallData *callData); private: Q_NEVER_INLINE static ReturnedValue wrap_slowPath(ExecutionEngine *engine, QObject *object); diff --git a/src/qml/jsruntime/qv4scopedvalue_p.h b/src/qml/jsruntime/qv4scopedvalue_p.h index 6cdc6200e7..6775028272 100644 --- a/src/qml/jsruntime/qv4scopedvalue_p.h +++ b/src/qml/jsruntime/qv4scopedvalue_p.h @@ -94,6 +94,12 @@ struct ScopedValue; return; \ } while (false) +#define THROW_GENERIC_ERROR(str) \ + do { \ + scope.result = scope.engine->throwError(QString::fromUtf8(str)); \ + return; \ + } while (false) + struct Scope { inline Scope(ExecutionContext *ctx) : engine(ctx->d()->engine) diff --git a/src/qml/jsruntime/qv4sequenceobject.cpp b/src/qml/jsruntime/qv4sequenceobject.cpp index 58da7b9f68..8ce10e326d 100644 --- a/src/qml/jsruntime/qv4sequenceobject.cpp +++ b/src/qml/jsruntime/qv4sequenceobject.cpp @@ -404,28 +404,28 @@ public: struct CompareFunctor { - CompareFunctor(QV4::ExecutionContext *ctx, const QV4::Value &compareFn) - : m_ctx(ctx), m_compareFn(&compareFn) + CompareFunctor(QV4::ExecutionEngine *v4, const QV4::Value &compareFn) + : m_v4(v4), m_compareFn(&compareFn) {} bool operator()(typename Container::value_type lhs, typename Container::value_type rhs) { - QV4::Scope scope(m_ctx); + QV4::Scope scope(m_v4); ScopedObject compare(scope, m_compareFn); ScopedCallData callData(scope, 2); - callData->args[0] = convertElementToValue(this->m_ctx->d()->engine, lhs); - callData->args[1] = convertElementToValue(this->m_ctx->d()->engine, rhs); - callData->thisObject = this->m_ctx->d()->engine->globalObject; + callData->args[0] = convertElementToValue(m_v4, lhs); + callData->args[1] = convertElementToValue(m_v4, rhs); + callData->thisObject = m_v4->globalObject; compare->call(scope, callData); return scope.result.toNumber() < 0; } private: - QV4::ExecutionContext *m_ctx; + QV4::ExecutionEngine *m_v4; const QV4::Value *m_compareFn; }; - void sort(QV4::CallContext *ctx) + void sort(const BuiltinFunction *, Scope &scope, CallData *callData) { if (d()->isReference) { if (!d()->object) @@ -433,9 +433,8 @@ public: loadReference(); } - QV4::Scope scope(ctx); - if (ctx->argc() == 1 && ctx->args()[0].as<FunctionObject>()) { - CompareFunctor cf(ctx, ctx->args()[0]); + if (callData->argc == 1 && callData->args[0].as<FunctionObject>()) { + CompareFunctor cf(scope.engine, callData->args[0]); std::sort(d()->container->begin(), d()->container->end(), cf); } else { DefaultCompareFunctor cf; @@ -446,45 +445,43 @@ public: storeReference(); } - static QV4::ReturnedValue method_get_length(QV4::CallContext *ctx) + static void method_get_length(const BuiltinFunction *, Scope &scope, CallData *callData) { - QV4::Scope scope(ctx); - QV4::Scoped<QQmlSequence<Container> > This(scope, ctx->thisObject().as<QQmlSequence<Container> >()); + QV4::Scoped<QQmlSequence<Container> > This(scope, callData->thisObject.as<QQmlSequence<Container> >()); if (!This) - return ctx->engine()->throwTypeError(); + THROW_TYPE_ERROR(); if (This->d()->isReference) { if (!This->d()->object) - return QV4::Encode(0); + RETURN_RESULT(Encode(0)); This->loadReference(); } - return QV4::Encode(This->d()->container->count()); + RETURN_RESULT(Encode(This->d()->container->count())); } - static QV4::ReturnedValue method_set_length(QV4::CallContext* ctx) + static void method_set_length(const BuiltinFunction *, Scope &scope, CallData *callData) { - QV4::Scope scope(ctx); - QV4::Scoped<QQmlSequence<Container> > This(scope, ctx->thisObject().as<QQmlSequence<Container> >()); + QV4::Scoped<QQmlSequence<Container> > This(scope, callData->thisObject.as<QQmlSequence<Container> >()); if (!This) - return ctx->engine()->throwTypeError(); + THROW_TYPE_ERROR(); - quint32 newLength = ctx->args()[0].toUInt32(); + quint32 newLength = callData->args[0].toUInt32(); /* Qt containers have int (rather than uint) allowable indexes. */ if (newLength > INT_MAX) { generateWarning(scope.engine, QLatin1String("Index out of range during length set")); - return QV4::Encode::undefined(); + RETURN_UNDEFINED(); } /* Read the sequence from the QObject property if we're a reference */ if (This->d()->isReference) { if (!This->d()->object) - return QV4::Encode::undefined(); + RETURN_UNDEFINED(); This->loadReference(); } /* Determine whether we need to modify the sequence */ qint32 newCount = static_cast<qint32>(newLength); qint32 count = This->d()->container->count(); if (newCount == count) { - return QV4::Encode::undefined(); + RETURN_UNDEFINED(); } else if (newCount > count) { /* according to ECMA262r3 we need to insert */ /* undefined values increasing length to newLength. */ @@ -506,7 +503,7 @@ public: /* write back. already checked that object is non-null, so skip that check here. */ This->storeReference(); } - return QV4::Encode::undefined(); + RETURN_UNDEFINED(); } QVariant toVariant() const @@ -625,26 +622,25 @@ void SequencePrototype::init() } #undef REGISTER_QML_SEQUENCE_METATYPE -QV4::ReturnedValue SequencePrototype::method_sort(QV4::CallContext *ctx) +void SequencePrototype::method_sort(const BuiltinFunction *b, Scope &scope, CallData *callData) { - QV4::Scope scope(ctx); - QV4::ScopedObject o(scope, ctx->thisObject()); + QV4::ScopedObject o(scope, callData->thisObject); if (!o || !o->isListType()) - return ctx->engine()->throwTypeError(); + THROW_TYPE_ERROR(); - if (ctx->argc() >= 2) - return o.asReturnedValue(); + if (callData->argc >= 2) + RETURN_RESULT(o); #define CALL_SORT(SequenceElementType, SequenceElementTypeName, SequenceType, DefaultValue) \ if (QQml##SequenceElementTypeName##List *s = o->as<QQml##SequenceElementTypeName##List>()) { \ - s->sort(ctx); \ + s->sort(b, scope, callData); \ } else FOREACH_QML_SEQUENCE_TYPE(CALL_SORT) #undef CALL_SORT {} - return o.asReturnedValue(); + RETURN_RESULT(o); } #define IS_SEQUENCE(unused1, unused2, SequenceType, unused3) \ diff --git a/src/qml/jsruntime/qv4sequenceobject_p.h b/src/qml/jsruntime/qv4sequenceobject_p.h index c0416ad639..6f96b9f760 100644 --- a/src/qml/jsruntime/qv4sequenceobject_p.h +++ b/src/qml/jsruntime/qv4sequenceobject_p.h @@ -67,12 +67,12 @@ struct SequencePrototype : public QV4::Object { void init(); - static ReturnedValue method_valueOf(QV4::CallContext *ctx) + static void method_valueOf(const BuiltinFunction *, Scope &scope, CallData *callData) { - return ctx->thisObject().toString(ctx->engine())->asReturnedValue(); + scope.result = callData->thisObject.toString(scope.engine); } - static ReturnedValue method_sort(QV4::CallContext *ctx); + static void method_sort(const BuiltinFunction *, Scope &scope, CallData *callData); static bool isSequenceType(int sequenceTypeId); static ReturnedValue newSequence(QV4::ExecutionEngine *engine, int sequenceTypeId, QObject *object, int propertyIndex, bool *succeeded); diff --git a/src/qml/jsruntime/qv4variantobject.cpp b/src/qml/jsruntime/qv4variantobject.cpp index 455a7ccb65..5cab4c5386 100644 --- a/src/qml/jsruntime/qv4variantobject.cpp +++ b/src/qml/jsruntime/qv4variantobject.cpp @@ -113,67 +113,68 @@ void VariantPrototype::init() defineDefaultProperty(engine()->id_toString(), method_toString, 0); } -QV4::ReturnedValue VariantPrototype::method_preserve(CallContext *ctx) +void VariantPrototype::method_preserve(const BuiltinFunction *, Scope &scope, CallData *callData) { - Scope scope(ctx); - Scoped<VariantObject> o(scope, ctx->thisObject().as<QV4::VariantObject>()); + Scoped<VariantObject> o(scope, callData->thisObject.as<QV4::VariantObject>()); if (o && o->d()->isScarce()) o->d()->addVmePropertyReference(); - return Encode::undefined(); + RETURN_UNDEFINED(); } -QV4::ReturnedValue VariantPrototype::method_destroy(CallContext *ctx) +void VariantPrototype::method_destroy(const BuiltinFunction *, Scope &scope, CallData *callData) { - Scope scope(ctx); - Scoped<VariantObject> o(scope, ctx->thisObject().as<QV4::VariantObject>()); + Scoped<VariantObject> o(scope, callData->thisObject.as<QV4::VariantObject>()); if (o) { if (o->d()->isScarce()) o->d()->addVmePropertyReference(); o->d()->data() = QVariant(); } - return Encode::undefined(); + RETURN_UNDEFINED(); } -QV4::ReturnedValue VariantPrototype::method_toString(CallContext *ctx) +void VariantPrototype::method_toString(const BuiltinFunction *, Scope &scope, CallData *callData) { - Scope scope(ctx); - Scoped<VariantObject> o(scope, ctx->thisObject().as<QV4::VariantObject>()); + Scoped<VariantObject> o(scope, callData->thisObject.as<QV4::VariantObject>()); if (!o) - return Encode::undefined(); + RETURN_UNDEFINED(); QString result = o->d()->data().toString(); if (result.isEmpty() && !o->d()->data().canConvert(QVariant::String)) { result = QLatin1String("QVariant(") + QLatin1String(o->d()->data().typeName()) + QLatin1Char(')'); } - return Encode(ctx->d()->engine->newString(result)); + scope.result = scope.engine->newString(result); } -QV4::ReturnedValue VariantPrototype::method_valueOf(CallContext *ctx) +void VariantPrototype::method_valueOf(const BuiltinFunction *, Scope &scope, CallData *callData) { - Scope scope(ctx); - Scoped<VariantObject> o(scope, ctx->thisObject().as<QV4::VariantObject>()); + Scoped<VariantObject> o(scope, callData->thisObject.as<QV4::VariantObject>()); if (o) { QVariant v = o->d()->data(); switch (v.type()) { case QVariant::Invalid: - return Encode::undefined(); + scope.result = Encode::undefined(); + return; case QVariant::String: - return Encode(ctx->d()->engine->newString(v.toString())); + scope.result = scope.engine->newString(v.toString()); + return; case QVariant::Int: - return Encode(v.toInt()); + scope.result = Encode(v.toInt()); + return; case QVariant::Double: case QVariant::UInt: - return Encode(v.toDouble()); + scope.result = Encode(v.toDouble()); + return; case QVariant::Bool: - return Encode(v.toBool()); + scope.result = Encode(v.toBool()); + return; default: if (QMetaType::typeFlags(v.userType()) & QMetaType::IsEnumeration) - return Encode(v.toInt()); + RETURN_RESULT(Encode(v.toInt())); break; } } - return ctx->thisObject().asReturnedValue(); + scope.result = callData->thisObject; } QT_END_NAMESPACE diff --git a/src/qml/jsruntime/qv4variantobject_p.h b/src/qml/jsruntime/qv4variantobject_p.h index 9a04069c12..ef51b6632d 100644 --- a/src/qml/jsruntime/qv4variantobject_p.h +++ b/src/qml/jsruntime/qv4variantobject_p.h @@ -107,10 +107,10 @@ struct VariantPrototype : VariantObject public: void init(); - static ReturnedValue method_preserve(CallContext *ctx); - static ReturnedValue method_destroy(CallContext *ctx); - static ReturnedValue method_toString(CallContext *ctx); - static ReturnedValue method_valueOf(CallContext *ctx); + static void method_preserve(const BuiltinFunction *, Scope &scope, CallData *callData); + static void method_destroy(const BuiltinFunction *, Scope &scope, CallData *callData); + static void method_toString(const BuiltinFunction *, Scope &scope, CallData *callData); + static void method_valueOf(const BuiltinFunction *, Scope &scope, CallData *callData); }; } |