Changeset 271358 in webkit
- Timestamp:
- Jan 11, 2021, 5:04:27 AM (6 years ago)
- Location:
- trunk/Source
- Files:
-
- 7 edited
-
WTF/ChangeLog (modified) (1 diff)
-
WTF/wtf/EnumTraits.h (modified) (2 diffs)
-
WebCore/ChangeLog (modified) (1 diff)
-
WebCore/platform/ContextMenuItem.h (modified) (1 diff)
-
WebKit/ChangeLog (modified) (1 diff)
-
WebKit/Scripts/webkit/messages.py (modified) (1 diff)
-
WebKit/Scripts/webkit/tests/MessageNames.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WTF/ChangeLog
r271332 r271358 1 2021-01-11 Kimmo Kinnunen <kkinnunen@apple.com> 2 3 WebKit::IPC::Encoder needs definitions of all custom enum values at the Encoder definition time 4 https://bugs.webkit.org/show_bug.cgi?id=220410 5 6 Reviewed by Darin Adler. 7 8 Change WTF::EnumTraits to have either EnumTraits::values or EnumTraits::isValidEnum(). 9 Previously, if clients wanted to check isValidEnum for custom enum, they had to: 10 1) Define HasCustomIsValidEnum<TheirEnum> : true_type {}; 11 2) Define new function template isValidEnum() for TheirEnum 12 3) Ensure that their isValidEnum() was defined before the definition of the call to 13 the isValidEnum(). 14 15 This has the problem that isValidEnum() cannot be called in generic code, because 16 at the definition time generic code typically does not have all the types in scope 17 that will be used at instantiation time. 18 Each isValidEnum() is their own function template, C++ does not have function template 19 specialization. 20 21 After the change, clients need to: 22 1) Define EnumTraits<TheirEnum> { bool isValidEnum(...) } 23 24 Fix by using the fact that WTF::EnumTraits is a class and that can have template 25 specializations. 26 27 Consistent with the EnumTraits::values case: 28 a) Automatic case? --> Define EnumTraits::values 29 b) Manual/custom case? --> Define EnumTraits::isValidEnum() 30 31 * wtf/EnumTraits.h: 32 (WTF::isValidEnum): 33 1 34 2021-01-08 Yusuke Suzuki <ysuzuki@apple.com> 2 35 -
trunk/Source/WTF/wtf/EnumTraits.h
r262092 r271358 52 52 }; 53 53 54 template<typename U> class HasCustomIsValidEnum : public std::false_type { }; 55 56 template<typename E, typename T, std::enable_if_t<std::is_enum<E>::value && !std::is_same<std::underlying_type_t<E>, bool>::value && !HasCustomIsValidEnum<E>::value>* = nullptr> 57 constexpr bool isValidEnum(T t) 54 template<typename E, typename T, typename = std::enable_if_t<!std::is_same_v<std::underlying_type_t<E>, bool>>> 55 constexpr auto isValidEnum(T t) -> decltype(EnumValueChecker<T, typename EnumTraits<E>::values>::isValidEnum(t), bool()) 58 56 { 59 57 static_assert(sizeof(T) >= sizeof(std::underlying_type_t<E>), "Integral type must be at least the size of the underlying enum type"); … … 62 60 } 63 61 64 template<typename E, typename T, std::enable_if_t<std::is_same<std::underlying_type_t<E>, bool>::value>* = nullptr> 62 template<typename E, typename T, typename = std::enable_if_t<!std::is_same_v<std::underlying_type_t<E>, bool>>> 63 auto isValidEnum(T t) -> decltype(EnumTraits<E>::isValidEnum(t), bool()) 64 { 65 return EnumTraits<E>::isValidEnum(t); 66 } 67 68 template<typename E, typename T, typename = std::enable_if_t<std::is_same_v<std::underlying_type_t<E>, bool>>> 65 69 constexpr bool isValidEnum(T t) 66 70 { -
trunk/Source/WebCore/ChangeLog
r271357 r271358 1 2021-01-11 Kimmo Kinnunen <kkinnunen@apple.com> 2 3 WebKit::IPC::Encoder needs definitions of all custom enum values at the Encoder definition time 4 https://bugs.webkit.org/show_bug.cgi?id=220410 5 6 Reviewed by Darin Adler. 7 8 Change WTF::EnumTraits to have either EnumTraits::values or EnumTraits::isValidEnum(). 9 10 Change here needed to conform to the new protocol. Fixes an issue with the template usage 11 in WebKit::IPC::Encoder, see WebKit and WTF ChangeLogs for discussion. 12 13 * platform/ContextMenuItem.h: 14 (WTF::EnumTraits<WebCore::ContextMenuAction>::isValidEnum): 15 1 16 2021-01-07 Sergio Villar Senin <svillar@igalia.com> 2 17 -
trunk/Source/WebCore/platform/ContextMenuItem.h
r270974 r271358 209 209 210 210 template<> 211 class HasCustomIsValidEnum<WebCore::ContextMenuAction> : public std::true_type { }; 212 213 template<typename E, typename T, std::enable_if_t<std::is_same_v<E, WebCore::ContextMenuAction>>* = nullptr> 214 bool isValidEnum(T action) 215 { 216 static_assert(sizeof(T) == sizeof(E), "isValidEnum<WebCore::ContextMenuAction> should only be called with 32-bit types"); 217 return WebCore::isValidContextMenuAction(static_cast<E>(action)); 211 struct EnumTraits<WebCore::ContextMenuAction> { 212 template<typename T> 213 static std::enable_if_t<sizeof(T) == sizeof(WebCore::ContextMenuAction), bool> isValidEnum(T action) 214 { 215 return WebCore::isValidContextMenuAction(static_cast<WebCore::ContextMenuAction>(action)); 216 }; 218 217 }; 219 218 -
trunk/Source/WebKit/ChangeLog
r271354 r271358 1 2021-01-11 Kimmo Kinnunen <kkinnunen@apple.com> 2 3 WebKit::IPC::Encoder needs definitions of all custom enum values at the Encoder definition time 4 https://bugs.webkit.org/show_bug.cgi?id=220410 5 6 Reviewed by Darin Adler. 7 8 Change WTF::EnumTraits to have either EnumTraits::values or EnumTraits::isValidEnum(). 9 10 Fixes the upcoming problem where Encoder::encode(E) function is moved from Encoder 11 to other class, such as EncoderBase, and where we do not want to add redundant includes. 12 See the WTF/ ChangeLog for discussiong wrt why they were needed before. 13 14 * Scripts/webkit/messages.py: 15 * Scripts/webkit/tests/MessageNames.h: 16 (WTF::EnumTraits<IPC::MessageName>::isValidEnum): 17 1 18 2021-01-11 Carlos Garcia Campos <cgarcia@igalia.com> 2 19 -
trunk/Source/WebKit/Scripts/webkit/messages.py
r271243 r271358 989 989 result.append('\n') 990 990 result.append('template<>\n') 991 result.append('class HasCustomIsValidEnum<IPC::MessageName> : public std::true_type { };\n') 992 result.append('template<typename E, typename T, std::enable_if_t<std::is_same_v<E, IPC::MessageName>>* = nullptr>\n') 993 result.append('bool isValidEnum(T messageName)\n') 994 result.append('{\n') 995 result.append(' static_assert(sizeof(T) == sizeof(E), "isValidEnum<IPC::MessageName> should only be called with 16-bit types");\n') 996 result.append(' static_assert(std::is_unsigned<T>::value, "isValidEnum<IPC::MessageName> should only be called with unsigned types");\n') 997 result.append(' if (messageName > static_cast<std::underlying_type<IPC::MessageName>::type>(IPC::MessageName::Last))\n') 998 result.append(' return false;\n') 999 result.append(' return IPC::isValidMessageName(static_cast<E>(messageName));\n') 991 result.append('struct EnumTraits<IPC::MessageName> {\n') 992 result.append(' template<typename T>\n') 993 result.append(' static std::enable_if_t<sizeof(T) == sizeof(IPC::MessageName) && std::is_unsigned_v<T>, bool> isValidEnum(T messageName)\n') 994 result.append(' {\n') 995 result.append(' if (messageName > WTF::enumToUnderlyingType(IPC::MessageName::Last))\n') 996 result.append(' return false;\n') 997 result.append(' return IPC::isValidMessageName(static_cast<IPC::MessageName>(messageName));\n') 998 result.append(' }\n') 1000 999 result.append('};\n') 1001 1000 result.append('\n') -
trunk/Source/WebKit/Scripts/webkit/tests/MessageNames.h
r271243 r271358 116 116 117 117 template<> 118 class HasCustomIsValidEnum<IPC::MessageName> : public std::true_type { }; 119 template<typename E, typename T, std::enable_if_t<std::is_same_v<E, IPC::MessageName>>* = nullptr> 120 bool isValidEnum(T messageName) 121 { 122 static_assert(sizeof(T) == sizeof(E), "isValidEnum<IPC::MessageName> should only be called with 16-bit types"); 123 static_assert(std::is_unsigned<T>::value, "isValidEnum<IPC::MessageName> should only be called with unsigned types"); 124 if (messageName > static_cast<std::underlying_type<IPC::MessageName>::type>(IPC::MessageName::Last)) 125 return false; 126 return IPC::isValidMessageName(static_cast<E>(messageName)); 118 struct EnumTraits<IPC::MessageName> { 119 template<typename T> 120 static std::enable_if_t<sizeof(T) == sizeof(IPC::MessageName) && std::is_unsigned_v<T>, bool> isValidEnum(T messageName) 121 { 122 if (messageName > WTF::enumToUnderlyingType(IPC::MessageName::Last)) 123 return false; 124 return IPC::isValidMessageName(static_cast<IPC::MessageName>(messageName)); 125 } 127 126 }; 128 127
Note:
See TracChangeset
for help on using the changeset viewer.