diff options
Diffstat (limited to 'src/qml/jsruntime/qv4vtable_p.h')
-rw-r--r-- | src/qml/jsruntime/qv4vtable_p.h | 151 |
1 files changed, 105 insertions, 46 deletions
diff --git a/src/qml/jsruntime/qv4vtable_p.h b/src/qml/jsruntime/qv4vtable_p.h index 9dda104cd1..0532fdc32d 100644 --- a/src/qml/jsruntime/qv4vtable_p.h +++ b/src/qml/jsruntime/qv4vtable_p.h @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2018 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtQml module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2018 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #ifndef QV4VTABLE_P_H #define QV4VTABLE_P_H @@ -51,14 +15,16 @@ // #include "qv4global_p.h" +#include <QtCore/qmetaobject.h> QT_BEGIN_NAMESPACE +class QObject; namespace QV4 { struct Lookup; -struct Q_QML_PRIVATE_EXPORT OwnPropertyKeyIterator { +struct Q_QML_EXPORT OwnPropertyKeyIterator { virtual ~OwnPropertyKeyIterator() = 0; virtual PropertyKey next(const Object *o, Property *p = nullptr, PropertyAttributes *attrs = nullptr) = 0; }; @@ -84,18 +50,21 @@ struct VTable typedef ReturnedValue (*InstanceOf)(const Object *typeObject, const Value &var); typedef ReturnedValue (*Call)(const FunctionObject *, const Value *thisObject, const Value *argv, int argc); + typedef void (*CallWithMetaTypes)(const FunctionObject *, QObject *, void **, const QMetaType *, int); typedef ReturnedValue (*CallAsConstructor)(const FunctionObject *, const Value *argv, int argc, const Value *newTarget); typedef ReturnedValue (*ResolveLookupGetter)(const Object *, ExecutionEngine *, Lookup *); typedef bool (*ResolveLookupSetter)(Object *, ExecutionEngine *, Lookup *, const Value &); + typedef int (*Metacall)(Object *, QMetaObject::Call, int, void **); + const VTable * const parent; quint16 inlinePropertyOffset; quint16 nInlineProperties; quint8 isExecutionContext; quint8 isString; quint8 isObject; - quint8 isFunctionObject; + quint8 isTailCallable; quint8 isErrorObject; quint8 isArrayData; quint8 isStringOrSymbol; @@ -123,11 +92,89 @@ struct VTable Call call; CallAsConstructor callAsConstructor; + CallWithMetaTypes callWithMetaTypes; ResolveLookupGetter resolveLookupGetter; ResolveLookupSetter resolveLookupSetter; + + Metacall metacall; }; +template<VTable::CallWithMetaTypes call> +struct VTableCallWithMetaTypesWrapper { constexpr static VTable::CallWithMetaTypes c = call; }; + +template<VTable::Call call> +struct VTableCallWrapper { constexpr static VTable::Call c = call; }; + +template<class Class> +constexpr VTable::CallWithMetaTypes vtableMetaTypesCallEntry() +{ + // If Class overrides virtualCallWithMetaTypes, return that. + // Otherwise, if it overrides virtualCall, return convertAndCall. + // Otherwise, just return whatever the base class had. + + // A simple == on methods is not considered constexpr, so we have to jump through some hoops. + + static_assert( + std::is_same_v< + VTableCallWithMetaTypesWrapper<Class::virtualCallWithMetaTypes>, + VTableCallWithMetaTypesWrapper<Class::SuperClass::virtualCallWithMetaTypes>> + || !std::is_same_v< + VTableCallWithMetaTypesWrapper<Class::virtualCallWithMetaTypes>, + VTableCallWithMetaTypesWrapper<nullptr>>, + "You mustn't override virtualCallWithMetaTypes with nullptr"); + + static_assert( + std::is_same_v< + VTableCallWithMetaTypesWrapper<Class::virtualConvertAndCall>, + VTableCallWithMetaTypesWrapper<Class::SuperClass::virtualConvertAndCall>> + || !std::is_same_v< + VTableCallWithMetaTypesWrapper<Class::virtualConvertAndCall>, + VTableCallWithMetaTypesWrapper<nullptr>>, + "You mustn't override virtualConvertAndCall with nullptr"); + + if constexpr ( + std::is_same_v< + VTableCallWithMetaTypesWrapper<Class::virtualCallWithMetaTypes>, + VTableCallWithMetaTypesWrapper<Class::SuperClass::virtualCallWithMetaTypes>> + && !std::is_same_v< + VTableCallWrapper<Class::virtualCall>, + VTableCallWrapper<Class::SuperClass::virtualCall>>) { + // Converting from metatypes to JS signature is easy. + return Class::virtualConvertAndCall; + } + + return Class::virtualCallWithMetaTypes; +} + +template<class Class> +constexpr VTable::Call vtableJsTypesCallEntry() +{ + // If Class overrides virtualCall, return that. + // Otherwise, if it overrides virtualCallWithMetaTypes, fail. + // (We cannot determine the target types to call virtualCallWithMetaTypes in that case) + // Otherwise, just return whatever the base class had. + + // A simple == on methods is not considered constexpr, so we have to jump through some hoops. + + static_assert( + !std::is_same_v< + VTableCallWrapper<Class::virtualCall>, + VTableCallWrapper<Class::SuperClass::virtualCall>> + || std::is_same_v< + VTableCallWithMetaTypesWrapper<Class::virtualCallWithMetaTypes>, + VTableCallWithMetaTypesWrapper<Class::SuperClass::virtualCallWithMetaTypes>>, + "If you override virtualCallWithMetaTypes, override virtualCall, too"); + + static_assert( + std::is_same_v< + VTableCallWrapper<Class::virtualCall>, + VTableCallWrapper<Class::SuperClass::virtualCall>> + || VTableCallWrapper<Class::virtualCall>::c != nullptr, + "You mustn't override virtualCall with nullptr"); + + return Class::virtualCall; +} struct VTableBase { protected: @@ -150,9 +197,19 @@ protected: static constexpr VTable::Call virtualCall = nullptr; static constexpr VTable::CallAsConstructor virtualCallAsConstructor = nullptr; + static constexpr VTable::CallWithMetaTypes virtualCallWithMetaTypes = nullptr; + static constexpr VTable::CallWithMetaTypes virtualConvertAndCall = nullptr; static constexpr VTable::ResolveLookupGetter virtualResolveLookupGetter = nullptr; static constexpr VTable::ResolveLookupSetter virtualResolveLookupSetter = nullptr; + + static constexpr VTable::Metacall virtualMetacall = nullptr; + + template<class Class> + friend constexpr VTable::CallWithMetaTypes vtableMetaTypesCallEntry(); + + template<class Class> + friend constexpr VTable::Call vtableJsTypesCallEntry(); }; #define DEFINE_MANAGED_VTABLE_INT(classname, parentVTable) \ @@ -164,7 +221,7 @@ protected: classname::IsExecutionContext, \ classname::IsString, \ classname::IsObject, \ - classname::IsFunctionObject, \ + classname::IsTailCallable, \ classname::IsErrorObject, \ classname::IsArrayData, \ classname::IsStringOrSymbol, \ @@ -190,11 +247,13 @@ protected: classname::virtualOwnPropertyKeys, \ classname::virtualInstanceOf, \ \ - classname::virtualCall, \ - classname::virtualCallAsConstructor, \ + QV4::vtableJsTypesCallEntry<classname>(), \ + classname::virtualCallAsConstructor, \ + QV4::vtableMetaTypesCallEntry<classname>(), \ \ classname::virtualResolveLookupGetter, \ - classname::virtualResolveLookupSetter \ + classname::virtualResolveLookupSetter, \ + classname::virtualMetacall \ } #define DEFINE_MANAGED_VTABLE(classname) \ @@ -202,7 +261,7 @@ const QV4::VTable classname::static_vtbl = DEFINE_MANAGED_VTABLE_INT(classname, #define V4_OBJECT2(DataClass, superClass) \ private: \ - DataClass() Q_DECL_EQ_DELETE; \ + DataClass() = delete; \ Q_DISABLE_COPY(DataClass) \ public: \ Q_MANAGED_CHECK \ @@ -217,7 +276,7 @@ const QV4::VTable classname::static_vtbl = DEFINE_MANAGED_VTABLE_INT(classname, dptr->_checkIsInitialized(); \ return dptr; \ } \ - Q_STATIC_ASSERT(std::is_trivial< QV4::Heap::DataClass >::value); + Q_STATIC_ASSERT(std::is_trivial_v<QV4::Heap::DataClass>); #define V4_PROTOTYPE(p) \ static QV4::Object *defaultPrototype(QV4::ExecutionEngine *e) \ |