/* * Copyright (C) 2016 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF * THE POSSIBILITY OF SUCH DAMAGE. */ #pragma once #include "StringAdaptors.h" #include #include #include #include #include #if ENABLE(WEBGL) #include "WebGLAny.h" #endif namespace JSC { class ArrayBuffer; class ArrayBufferView; class DataView; class JSValue; class JSObject; } namespace WebCore { class IDBKey; class IDBKeyData; class IDBValue; class JSWindowProxy; class DOMPromise; class ScheduledAction; #if ENABLE(WEBGL) class WebGLExtension; #endif template struct IDLType { using ImplementationType = T; using StorageType = T; using SequenceStorageType = T; using ParameterType = T; using NullableParameterType = std::optional; using InnerParameterType = T; using NullableInnerParameterType = std::optional; using NullableType = std::optional; static NullableType nullValue() { return std::nullopt; } static bool isNullValue(const NullableType& value) { return !value; } static ImplementationType extractValueFromNullable(const NullableType& value) { return value.value(); } }; // IDLUnsupportedType is a special type that serves as a base class for currently unsupported types. struct IDLUnsupportedType : IDLType { }; // IDLNull is a special type for use as a subtype in an IDLUnion that is nullable. struct IDLNull : IDLType { }; struct IDLAny : IDLType> { using SequenceStorageType = JSC::JSValue; using ParameterType = JSC::JSValue; using NullableParameterType = JSC::JSValue; using NullableType = JSC::Strong; static inline std::nullptr_t nullValue() { return nullptr; } template static inline bool isNullValue(U&& value) { return !value; } template static inline U&& extractValueFromNullable(U&& value) { return std::forward(value); } }; struct IDLUndefined : IDLType { }; struct IDLBoolean : IDLType { }; template struct IDLNumber : IDLType { }; template struct IDLInteger : IDLNumber { }; struct IDLByte : IDLInteger { }; struct IDLOctet : IDLInteger { }; struct IDLShort : IDLInteger { }; struct IDLUnsignedShort : IDLInteger { }; struct IDLLong : IDLInteger { }; struct IDLUnsignedLong : IDLInteger { }; struct IDLLongLong : IDLInteger { }; struct IDLUnsignedLongLong : IDLInteger { }; template struct IDLClampAdaptor : IDLInteger { using InnerType = T; }; template struct IDLEnforceRangeAdaptor : IDLInteger { using InnerType = T; }; template struct IDLFloatingPoint : IDLNumber { }; struct IDLFloat : IDLFloatingPoint { }; struct IDLUnrestrictedFloat : IDLFloatingPoint { }; struct IDLDouble : IDLFloatingPoint { }; struct IDLUnrestrictedDouble : IDLFloatingPoint { }; template struct IDLString : IDLType { using ParameterType = const StringType&; using NullableParameterType = const StringType&; using NullableType = StringType; static StringType nullValue() { return StringType(); } static bool isNullValue(const StringType& value) { return value.isNull(); } static bool isNullValue(const UncachedString& value) { return value.string.isNull(); } static bool isNullValue(const OwnedString& value) { return value.string.isNull(); } static bool isNullValue(const URL& value) { return value.isNull(); } template static U&& extractValueFromNullable(U&& value) { return std::forward(value); } }; struct IDLDOMString : IDLString { }; struct IDLByteString : IDLString { }; struct IDLUSVString : IDLString { }; template struct IDLLegacyNullToEmptyStringAdaptor : IDLString { using InnerType = T; }; template struct IDLAtomStringAdaptor : IDLString { using InnerType = T; }; template struct IDLRequiresExistingAtomStringAdaptor : IDLString { using InnerType = T; }; template struct IDLAllowSharedAdaptor : T { using InnerType = T; }; struct IDLObject : IDLType> { using NullableType = JSC::Strong; static inline NullableType nullValue() { return { }; } template static inline bool isNullValue(U&& value) { return !value; } template static inline U&& extractValueFromNullable(U&& value) { return std::forward(value); } }; template struct IDLWrapper : IDLType> { using RawType = T; using StorageType = Ref; using ParameterType = T&; using NullableParameterType = T*; using InnerParameterType = Ref; using NullableInnerParameterType = RefPtr; using NullableType = RefPtr; static inline std::nullptr_t nullValue() { return nullptr; } template static inline bool isNullValue(U&& value) { return !value; } template static inline U&& extractValueFromNullable(U&& value) { return std::forward(value); } }; template struct IDLInterface : IDLWrapper { }; template struct IDLCallbackInterface : IDLWrapper { }; template struct IDLCallbackFunction : IDLWrapper { }; template struct IDLDictionary : IDLType { using ParameterType = const T&; using NullableParameterType = const T&; }; template struct IDLEnumeration : IDLType { }; template struct IDLNullable : IDLType { using InnerType = T; using ParameterType = typename T::NullableParameterType; using NullableParameterType = typename T::NullableParameterType; using InnerParameterType = typename T::NullableInnerParameterType; using NullableInnerParameterType = typename T::NullableInnerParameterType; using NullableType = typename T::NullableType; static inline auto nullValue() -> decltype(T::nullValue()) { return T::nullValue(); } template static inline bool isNullValue(U&& value) { return T::isNullValue(std::forward(value)); } template static inline auto extractValueFromNullable(U&& value) -> decltype(T::extractValueFromNullable(std::forward(value))) { return T::extractValueFromNullable(std::forward(value)); } }; template struct IDLSequence : IDLType> { using InnerType = T; using ParameterType = const Vector&; using NullableParameterType = const std::optional>&; }; template struct IDLFrozenArray : IDLType> { using InnerType = T; using ParameterType = const Vector&; using NullableParameterType = const std::optional>&; }; template struct IDLRecord : IDLType>> { using KeyType = K; using ValueType = V; using ParameterType = const Vector>&; using NullableParameterType = const std::optional>>&; }; template struct IDLPromise : IDLWrapper { using InnerType = T; }; struct IDLError : IDLUnsupportedType { }; struct IDLDOMException : IDLUnsupportedType { }; template struct IDLUnion : IDLType> { using TypeList = brigand::list; using ParameterType = const Variant&; using NullableParameterType = const std::optional>&; }; template struct IDLBufferSource : IDLWrapper { }; struct IDLArrayBuffer : IDLBufferSource { }; // NOTE: WebIDL defines ArrayBufferView as an IDL union of all the TypedArray types. // and DataView. For convience in our implementation, we give it a distinct // type that maps to the shared based class of all those classes. struct IDLArrayBufferView : IDLBufferSource { }; struct IDLDataView : IDLBufferSource { }; template struct IDLTypedArray : IDLBufferSource { }; // NOTE: The specific typed array types are IDLTypedArray specialized on the typed array // implementation type, e.g. IDLFloat64Array is IDLTypedArray // Non-WebIDL extensions struct IDLDate : IDLType { using NullableType = double; static double nullValue() { return std::numeric_limits::quiet_NaN(); } static bool isNullValue(double value) { return std::isnan(value); } static double extractValueFromNullable(double value) { return value; } }; struct IDLJSON : IDLType { using ParameterType = const String&; using NullableParameterType = const String&; using NullableType = String; static String nullValue() { return String(); } static bool isNullValue(const String& value) { return value.isNull(); } template static U&& extractValueFromNullable(U&& value) { return std::forward(value); } }; struct IDLScheduledAction : IDLType> { }; template struct IDLSerializedScriptValue : IDLWrapper { }; template struct IDLEventListener : IDLWrapper { }; struct IDLIDBKey : IDLWrapper { }; struct IDLIDBKeyData : IDLWrapper { }; struct IDLIDBValue : IDLWrapper { }; #if ENABLE(WEBGL) struct IDLWebGLAny : IDLType { }; struct IDLWebGLExtension : IDLWrapper { }; #endif // Helper predicates template struct IsIDLInterface : public std::integral_constant::value> { }; template struct IsIDLDictionary : public std::integral_constant::value> { }; template struct IsIDLEnumeration : public std::integral_constant::value> { }; template struct IsIDLSequence : public std::integral_constant::value> { }; template struct IsIDLFrozenArray : public std::integral_constant::value> { }; template struct IsIDLRecord : public std::integral_constant::value> { }; template struct IsIDLString : public std::integral_constant::value> { }; template struct IsIDLStringOrEnumeration : public std::integral_constant::value || WTF::IsTemplate::value> { }; template struct IsIDLNumber : public std::integral_constant::value> { }; template struct IsIDLInteger : public std::integral_constant::value> { }; template struct IsIDLFloatingPoint : public std::integral_constant::value> { }; template struct IsIDLTypedArray : public std::integral_constant::value> { }; template struct IsIDLArrayBuffer : public std::integral_constant::value> { }; template struct IsIDLArrayBufferView : public std::integral_constant::value> { }; template struct IsIDLArrayBufferAllowShared : public std::integral_constant, T>::value> { }; template struct IsIDLArrayBufferViewAllowShared : public std::integral_constant, T>::value> { }; } // namespace WebCore