#pragma once
#include <wtf/Brigand.h>
#include <wtf/HashMap.h>
#include <wtf/StdLibExtras.h>
#include <wtf/text/WTFString.h>
namespace JSC {
class ArrayBuffer;
class ArrayBufferView;
class JSValue;
class JSObject;
template<typename> class Strong;
}
namespace WebCore {
template<typename> class DOMPromise;
template<typename T>
struct IDLType {
using ImplementationType = T;
using ParameterType = T;
using NullableType = std::optional<ImplementationType>;
static NullableType nullValue() { return std::nullopt; }
static bool isNullValue(const NullableType& value) { return !value; }
static ImplementationType extractValueFromNullable(const NullableType& value) { return value.value(); }
};
struct IDLUnsupportedType : IDLType<void> { };
struct IDLNull : IDLType<std::nullptr_t> { };
struct IDLAny : IDLType<JSC::JSValue> { };
struct IDLBoolean : IDLType<bool> { };
template<typename NumericType> struct IDLNumber : IDLType<NumericType> { };
template<typename IntegerType> struct IDLInteger : IDLNumber<IntegerType> { };
struct IDLByte : IDLInteger<int8_t> { };
struct IDLOctet : IDLInteger<uint8_t> { };
struct IDLShort : IDLInteger<int16_t> { };
struct IDLUnsignedShort : IDLInteger<uint16_t> { };
struct IDLLong : IDLInteger<int32_t> { };
struct IDLUnsignedLong : IDLInteger<uint32_t> { };
struct IDLLongLong : IDLInteger<int64_t> { };
struct IDLUnsignedLongLong : IDLInteger<uint64_t> { };
template<typename FloatingPointType, bool unrestricted = false> struct IDLFloatingPoint : IDLNumber<FloatingPointType> {
static constexpr bool isUnrestricted = unrestricted;
};
struct IDLFloat : IDLFloatingPoint<float> { };
struct IDLUnrestrictedFloat : IDLFloatingPoint<float, true> { };
struct IDLDouble : IDLFloatingPoint<double> { };
struct IDLUnrestrictedDouble : IDLFloatingPoint<double, true> { };
struct IDLString : IDLType<String> {
using ParameterType = const String&;
using NullableType = String;
static String nullValue() { return String(); }
static bool isNullValue(const String& value) { return value.isNull(); }
template <typename U> static U&& extractValueFromNullable(U&& value) { return std::forward<U>(value); }
};
struct IDLDOMString : IDLString { };
struct IDLByteString : IDLString { };
struct IDLUSVString : IDLString { };
struct IDLObject : IDLType<JSC::Strong<JSC::JSObject>> {
using NullableType = JSC::Strong<JSC::JSObject>;
static inline std::nullptr_t nullValue() { return nullptr; }
template<typename U> static inline bool isNullValue(U&& value) { return !value; }
template<typename U> static inline U&& extractValueFromNullable(U&& value) { return std::forward<U>(value); }
};
template<typename T> struct IDLWrapper : IDLType<RefPtr<T>> {
using RawType = T;
using ParameterType = T&;
using NullableType = RefPtr<T>;
static inline std::nullptr_t nullValue() { return nullptr; }
template<typename U> static inline bool isNullValue(U&& value) { return !value; }
template<typename U> static inline U&& extractValueFromNullable(U&& value) { return std::forward<U>(value); }
};
template<typename T> struct IDLInterface : IDLWrapper<T> { };
template<typename T> struct IDLCallbackInterface : IDLWrapper<T> { };
template<typename T> struct IDLCallbackFunction : IDLWrapper<T> { };
template<typename T> struct IDLDictionary : IDLType<T> {
using ParameterType = const T&;
};
template<typename T> struct IDLEnumeration : IDLType<T> { };
template<typename T> struct IDLNullable : IDLType<typename T::NullableType> {
using InnerType = T;
};
template<typename T> struct IDLSequence : IDLType<Vector<typename T::ImplementationType>> {
using InnerType = T;
using ParameterType = const Vector<typename T::ImplementationType>&;
};
template<typename T> struct IDLFrozenArray : IDLType<Vector<typename T::ImplementationType>> {
using InnerType = T;
using ParameterType = const Vector<typename T::ImplementationType>&;
};
template<typename K, typename V> struct IDLRecord : IDLType<HashMap<typename K::ImplementationType, typename V::ImplementationType>> {
using KeyType = K;
using ValueType = V;
using ParameterType = const HashMap<typename K::ImplementationType, typename V::ImplementationType>&;
};
template<typename T> struct IDLPromise : IDLType<DOMPromise<T>> {
using InnerType = T;
};
struct IDLError : IDLUnsupportedType { };
struct IDLDOMException : IDLUnsupportedType { };
template<typename... Ts>
struct IDLUnion : IDLType<Variant<typename Ts::ImplementationType...>> {
using TypeList = brigand::list<Ts...>;
using ParameterType = const Variant<typename Ts::ImplementationType...>&;
};
struct IDLDate : IDLType<double> {
using NullableType = double;
static double nullValue() { return std::numeric_limits<double>::quiet_NaN(); }
static bool isNullValue(double value) { return std::isnan(value); }
static double extractValueFromNullable(double value) { return value; }
};
template<typename T> struct IDLSerializedScriptValue : IDLWrapper<T> { };
template<typename T> struct IDLEventListener : IDLWrapper<T> { };
template<typename T> struct IDLXPathNSResolver : IDLWrapper<T> { };
struct IDLJSON : IDLType<String> {
using ParameterType = const String&;
using NullableType = String;
static String nullValue() { return String(); }
static bool isNullValue(const String& value) { return value.isNull(); }
template <typename U> static U&& extractValueFromNullable(U&& value) { return std::forward<U>(value); }
};
using IDLBufferSource = IDLUnion<IDLInterface<JSC::ArrayBufferView>, IDLInterface<JSC::ArrayBuffer>>;
template<typename T>
struct IsIDLInterface : public std::integral_constant<bool, WTF::IsTemplate<T, IDLInterface>::value> { };
template<typename T>
struct IsIDLDictionary : public std::integral_constant<bool, WTF::IsTemplate<T, IDLDictionary>::value> { };
template<typename T>
struct IsIDLEnumeration : public std::integral_constant<bool, WTF::IsTemplate<T, IDLEnumeration>::value> { };
template<typename T>
struct IsIDLSequence : public std::integral_constant<bool, WTF::IsTemplate<T, IDLSequence>::value> { };
template<typename T>
struct IsIDLFrozenArray : public std::integral_constant<bool, WTF::IsTemplate<T, IDLFrozenArray>::value> { };
template<typename T>
struct IsIDLRecord : public std::integral_constant<bool, WTF::IsTemplate<T, IDLRecord>::value> { };
template<typename T>
struct IsIDLNumber : public std::integral_constant<bool, WTF::IsBaseOfTemplate<IDLNumber, T>::value> { };
template<typename T>
struct IsIDLInteger : public std::integral_constant<bool, WTF::IsBaseOfTemplate<IDLInteger, T>::value> { };
}