REVERT-simplify-blink-NativeValueTraitsBase.patch 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747
  1. From 940af9f2c87b436559b97c53763aa9eaaf1254eb Mon Sep 17 00:00:00 2001
  2. From: Jeremy Roman <jbroman@chromium.org>
  3. Date: Wed, 15 Nov 2023 16:24:54 +0000
  4. Subject: [PATCH] Use C++20 features to simplify blink::NativeValueTraitsBase.
  5. These allow some of the metaprogramming bits to be simplified a little.
  6. Change-Id: I052b4397586d21348401616e1792afdb9662f975
  7. Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5030335
  8. Reviewed-by: Yuki Shiino <yukishiino@chromium.org>
  9. Commit-Queue: Jeremy Roman <jbroman@chromium.org>
  10. Cr-Commit-Position: refs/heads/main@{#1224978}
  11. ---
  12. .../bindings/core/v8/native_value_traits.h | 54 ++----
  13. .../v8/native_value_traits_buffer_sources.cc | 166 ++++++++----------
  14. .../core/v8/native_value_traits_impl.h | 159 +++++++----------
  15. 3 files changed, 151 insertions(+), 228 deletions(-)
  16. diff --git a/third_party/blink/renderer/bindings/core/v8/native_value_traits.h b/third_party/blink/renderer/bindings/core/v8/native_value_traits.h
  17. index 7fc91d14acc71a2..1e5a0790df6da81 100644
  18. --- a/third_party/blink/renderer/bindings/core/v8/native_value_traits.h
  19. +++ b/third_party/blink/renderer/bindings/core/v8/native_value_traits.h
  20. @@ -5,6 +5,7 @@
  21. #ifndef THIRD_PARTY_BLINK_RENDERER_BINDINGS_CORE_V8_NATIVE_VALUE_TRAITS_H_
  22. #define THIRD_PARTY_BLINK_RENDERER_BINDINGS_CORE_V8_NATIVE_VALUE_TRAITS_H_
  23. +#include <concepts>
  24. #include <type_traits>
  25. #include "third_party/blink/renderer/bindings/core/v8/idl_types_base.h"
  26. @@ -30,7 +31,7 @@ class ExceptionState;
  27. // return toInt32(isolate, value, exceptionState, NormalConversion);
  28. // }
  29. // }
  30. -template <typename T, typename SFINAEHelper = void>
  31. +template <typename T>
  32. struct NativeValueTraits;
  33. // This declaration serves only as a blueprint for specializations: the
  34. @@ -45,22 +46,15 @@ struct NativeValueTraits;
  35. namespace bindings {
  36. -template <typename T, typename = void>
  37. -struct NativeValueTraitsHasIsNull : std::false_type {};
  38. -
  39. template <typename T>
  40. -struct NativeValueTraitsHasIsNull<
  41. - T,
  42. - std::void_t<decltype(std::declval<T>().IsNull())>> : std::true_type {};
  43. +struct ImplTypeFor {
  44. + using type = T;
  45. +};
  46. template <typename T>
  47. -struct NativeValueTraitsHasNullValue {
  48. - // true if |T| supports IDL null value.
  49. - static constexpr bool value =
  50. - // ScriptValue, String, and union types have IsNull member function.
  51. - bindings::NativeValueTraitsHasIsNull<T>::value ||
  52. - // Pointer types have nullptr as IDL null value.
  53. - std::is_pointer<T>::value;
  54. + requires std::derived_from<T, IDLBase>
  55. +struct ImplTypeFor<T> {
  56. + using type = typename T::ImplType;
  57. };
  58. } // namespace bindings
  59. @@ -78,37 +72,17 @@ struct NativeValueTraitsHasNullValue {
  60. // If present, |NullValue()| will be used when converting from the nullable type
  61. // T?, and should be used if the impl type has an existing "null" state. If not
  62. // present, WTF::Optional will be used to wrap the type.
  63. -template <typename T, typename SFINAEHelper = void>
  64. -struct NativeValueTraitsBase {
  65. - STATIC_ONLY(NativeValueTraitsBase);
  66. -
  67. - using ImplType = T;
  68. -
  69. - static constexpr bool has_null_value =
  70. - bindings::NativeValueTraitsHasNullValue<ImplType>::value;
  71. -
  72. - template <typename... ExtraArgs>
  73. - static decltype(auto) ArgumentValue(v8::Isolate* isolate,
  74. - int argument_index,
  75. - v8::Local<v8::Value> value,
  76. - ExceptionState& exception_state,
  77. - ExtraArgs... extra_args) {
  78. - return NativeValueTraits<std::remove_pointer_t<T>>::NativeValue(
  79. - isolate, value, exception_state,
  80. - std::forward<ExtraArgs>(extra_args)...);
  81. - }
  82. -};
  83. -
  84. template <typename T>
  85. -struct NativeValueTraitsBase<
  86. - T,
  87. - std::enable_if_t<std::is_base_of<IDLBase, T>::value>> {
  88. +struct NativeValueTraitsBase {
  89. STATIC_ONLY(NativeValueTraitsBase);
  90. - using ImplType = typename T::ImplType;
  91. + using ImplType = bindings::ImplTypeFor<T>::type;
  92. + // Pointer types have nullptr as IDL null value.
  93. + // ScriptValue, String, and union types have IsNull member function.
  94. static constexpr bool has_null_value =
  95. - bindings::NativeValueTraitsHasNullValue<ImplType>::value;
  96. + std::is_pointer_v<ImplType> ||
  97. + requires(ImplType value) { value.IsNull(); };
  98. template <typename... ExtraArgs>
  99. static decltype(auto) ArgumentValue(v8::Isolate* isolate,
  100. diff --git a/third_party/blink/renderer/bindings/core/v8/native_value_traits_buffer_sources.cc b/third_party/blink/renderer/bindings/core/v8/native_value_traits_buffer_sources.cc
  101. index 508ea6d8eea481e..18de71d84023f0c 100644
  102. --- a/third_party/blink/renderer/bindings/core/v8/native_value_traits_buffer_sources.cc
  103. +++ b/third_party/blink/renderer/bindings/core/v8/native_value_traits_buffer_sources.cc
  104. @@ -7,6 +7,7 @@
  105. #include "third_party/blink/renderer/core/core_export.h"
  106. #include "third_party/blink/renderer/core/execution_context/execution_context.h"
  107. #include "third_party/blink/renderer/core/frame/web_feature.h"
  108. +#include "third_party/blink/renderer/core/typed_arrays/flexible_array_buffer_view.h"
  109. #include "third_party/blink/renderer/core/typed_arrays/typed_flexible_array_buffer_view.h"
  110. namespace blink {
  111. @@ -698,12 +699,11 @@ DOMArrayBufferBase* NativeValueTraits<
  112. // ArrayBufferView
  113. template <typename T>
  114. -NotShared<T> NativeValueTraits<
  115. - NotShared<T>,
  116. - typename std::enable_if_t<std::is_base_of<DOMArrayBufferView, T>::value>>::
  117. - NativeValue(v8::Isolate* isolate,
  118. - v8::Local<v8::Value> value,
  119. - ExceptionState& exception_state) {
  120. + requires std::derived_from<T, DOMArrayBufferView>
  121. +NotShared<T> NativeValueTraits<NotShared<T>>::NativeValue(
  122. + v8::Isolate* isolate,
  123. + v8::Local<v8::Value> value,
  124. + ExceptionState& exception_state) {
  125. return NativeValueImpl<
  126. RecipeTrait<NotShared<T>>, ToDOMViewType<T, kNotShared>,
  127. Nullablity::kIsNotNullable, BufferSizeCheck::kCheck,
  128. @@ -712,13 +712,12 @@ NotShared<T> NativeValueTraits<
  129. }
  130. template <typename T>
  131. -NotShared<T> NativeValueTraits<
  132. - NotShared<T>,
  133. - typename std::enable_if_t<std::is_base_of<DOMArrayBufferView, T>::value>>::
  134. - ArgumentValue(v8::Isolate* isolate,
  135. - int argument_index,
  136. - v8::Local<v8::Value> value,
  137. - ExceptionState& exception_state) {
  138. + requires std::derived_from<T, DOMArrayBufferView>
  139. +NotShared<T> NativeValueTraits<NotShared<T>>::ArgumentValue(
  140. + v8::Isolate* isolate,
  141. + int argument_index,
  142. + v8::Local<v8::Value> value,
  143. + ExceptionState& exception_state) {
  144. return ArgumentValueImpl<
  145. RecipeTrait<NotShared<T>>, ToDOMViewType<T, kNotShared>,
  146. Nullablity::kIsNotNullable, BufferSizeCheck::kCheck,
  147. @@ -729,12 +728,11 @@ NotShared<T> NativeValueTraits<
  148. // [AllowShared] ArrayBufferView
  149. template <typename T>
  150. -MaybeShared<T> NativeValueTraits<
  151. - MaybeShared<T>,
  152. - typename std::enable_if_t<std::is_base_of<DOMArrayBufferView, T>::value>>::
  153. - NativeValue(v8::Isolate* isolate,
  154. - v8::Local<v8::Value> value,
  155. - ExceptionState& exception_state) {
  156. + requires std::derived_from<T, DOMArrayBufferView>
  157. +MaybeShared<T> NativeValueTraits<MaybeShared<T>>::NativeValue(
  158. + v8::Isolate* isolate,
  159. + v8::Local<v8::Value> value,
  160. + ExceptionState& exception_state) {
  161. return NativeValueImpl<RecipeTrait<MaybeShared<T>>,
  162. ToDOMViewType<T, kMaybeShared>,
  163. Nullablity::kIsNotNullable, BufferSizeCheck::kCheck,
  164. @@ -743,13 +741,12 @@ MaybeShared<T> NativeValueTraits<
  165. }
  166. template <typename T>
  167. -MaybeShared<T> NativeValueTraits<
  168. - MaybeShared<T>,
  169. - typename std::enable_if_t<std::is_base_of<DOMArrayBufferView, T>::value>>::
  170. - ArgumentValue(v8::Isolate* isolate,
  171. - int argument_index,
  172. - v8::Local<v8::Value> value,
  173. - ExceptionState& exception_state) {
  174. + requires std::derived_from<T, DOMArrayBufferView>
  175. +MaybeShared<T> NativeValueTraits<MaybeShared<T>>::ArgumentValue(
  176. + v8::Isolate* isolate,
  177. + int argument_index,
  178. + v8::Local<v8::Value> value,
  179. + ExceptionState& exception_state) {
  180. return ArgumentValueImpl<RecipeTrait<MaybeShared<T>>,
  181. ToDOMViewType<T, kMaybeShared>,
  182. Nullablity::kIsNotNullable, BufferSizeCheck::kCheck,
  183. @@ -760,12 +757,12 @@ MaybeShared<T> NativeValueTraits<
  184. // [AllowShared, BufferSourceTypeNoSizeLimit] ArrayBufferView
  185. template <typename T>
  186. -MaybeShared<T> NativeValueTraits<
  187. - IDLBufferSourceTypeNoSizeLimit<MaybeShared<T>>,
  188. - typename std::enable_if_t<std::is_base_of<DOMArrayBufferView, T>::value>>::
  189. - NativeValue(v8::Isolate* isolate,
  190. - v8::Local<v8::Value> value,
  191. - ExceptionState& exception_state) {
  192. + requires std::derived_from<T, DOMArrayBufferView>
  193. +MaybeShared<T>
  194. +NativeValueTraits<IDLBufferSourceTypeNoSizeLimit<MaybeShared<T>>>::NativeValue(
  195. + v8::Isolate* isolate,
  196. + v8::Local<v8::Value> value,
  197. + ExceptionState& exception_state) {
  198. return NativeValueImpl<
  199. RecipeTrait<MaybeShared<T>>, ToDOMViewType<T, kMaybeShared>,
  200. Nullablity::kIsNotNullable, BufferSizeCheck::kDoNotCheck,
  201. @@ -774,13 +771,12 @@ MaybeShared<T> NativeValueTraits<
  202. }
  203. template <typename T>
  204. -MaybeShared<T> NativeValueTraits<
  205. - IDLBufferSourceTypeNoSizeLimit<MaybeShared<T>>,
  206. - typename std::enable_if_t<std::is_base_of<DOMArrayBufferView, T>::value>>::
  207. - ArgumentValue(v8::Isolate* isolate,
  208. - int argument_index,
  209. - v8::Local<v8::Value> value,
  210. - ExceptionState& exception_state) {
  211. + requires std::derived_from<T, DOMArrayBufferView>
  212. +MaybeShared<T> NativeValueTraits<IDLBufferSourceTypeNoSizeLimit<
  213. + MaybeShared<T>>>::ArgumentValue(v8::Isolate* isolate,
  214. + int argument_index,
  215. + v8::Local<v8::Value> value,
  216. + ExceptionState& exception_state) {
  217. return ArgumentValueImpl<
  218. RecipeTrait<MaybeShared<T>>, ToDOMViewType<T, kMaybeShared>,
  219. Nullablity::kIsNotNullable, BufferSizeCheck::kDoNotCheck,
  220. @@ -791,12 +787,11 @@ MaybeShared<T> NativeValueTraits<
  221. // Nullable ArrayBufferView
  222. template <typename T>
  223. -NotShared<T> NativeValueTraits<
  224. - IDLNullable<NotShared<T>>,
  225. - typename std::enable_if_t<std::is_base_of<DOMArrayBufferView, T>::value>>::
  226. - NativeValue(v8::Isolate* isolate,
  227. - v8::Local<v8::Value> value,
  228. - ExceptionState& exception_state) {
  229. + requires std::derived_from<T, DOMArrayBufferView>
  230. +NotShared<T> NativeValueTraits<IDLNullable<NotShared<T>>>::NativeValue(
  231. + v8::Isolate* isolate,
  232. + v8::Local<v8::Value> value,
  233. + ExceptionState& exception_state) {
  234. return NativeValueImpl<
  235. RecipeTrait<NotShared<T>>, ToDOMViewType<T, kNotShared>,
  236. Nullablity::kIsNullable, BufferSizeCheck::kCheck,
  237. @@ -805,13 +800,12 @@ NotShared<T> NativeValueTraits<
  238. }
  239. template <typename T>
  240. -NotShared<T> NativeValueTraits<
  241. - IDLNullable<NotShared<T>>,
  242. - typename std::enable_if_t<std::is_base_of<DOMArrayBufferView, T>::value>>::
  243. - ArgumentValue(v8::Isolate* isolate,
  244. - int argument_index,
  245. - v8::Local<v8::Value> value,
  246. - ExceptionState& exception_state) {
  247. + requires std::derived_from<T, DOMArrayBufferView>
  248. +NotShared<T> NativeValueTraits<IDLNullable<NotShared<T>>>::ArgumentValue(
  249. + v8::Isolate* isolate,
  250. + int argument_index,
  251. + v8::Local<v8::Value> value,
  252. + ExceptionState& exception_state) {
  253. return ArgumentValueImpl<
  254. RecipeTrait<NotShared<T>>, ToDOMViewType<T, kNotShared>,
  255. Nullablity::kIsNullable, BufferSizeCheck::kCheck,
  256. @@ -822,12 +816,11 @@ NotShared<T> NativeValueTraits<
  257. // Nullable [AllowShared] ArrayBufferView
  258. template <typename T>
  259. -MaybeShared<T> NativeValueTraits<
  260. - IDLNullable<MaybeShared<T>>,
  261. - typename std::enable_if_t<std::is_base_of<DOMArrayBufferView, T>::value>>::
  262. - NativeValue(v8::Isolate* isolate,
  263. - v8::Local<v8::Value> value,
  264. - ExceptionState& exception_state) {
  265. + requires std::derived_from<T, DOMArrayBufferView>
  266. +MaybeShared<T> NativeValueTraits<IDLNullable<MaybeShared<T>>>::NativeValue(
  267. + v8::Isolate* isolate,
  268. + v8::Local<v8::Value> value,
  269. + ExceptionState& exception_state) {
  270. return NativeValueImpl<RecipeTrait<MaybeShared<T>>,
  271. ToDOMViewType<T, kMaybeShared>,
  272. Nullablity::kIsNullable, BufferSizeCheck::kCheck,
  273. @@ -836,13 +829,12 @@ MaybeShared<T> NativeValueTraits<
  274. }
  275. template <typename T>
  276. -MaybeShared<T> NativeValueTraits<
  277. - IDLNullable<MaybeShared<T>>,
  278. - typename std::enable_if_t<std::is_base_of<DOMArrayBufferView, T>::value>>::
  279. - ArgumentValue(v8::Isolate* isolate,
  280. - int argument_index,
  281. - v8::Local<v8::Value> value,
  282. - ExceptionState& exception_state) {
  283. + requires std::derived_from<T, DOMArrayBufferView>
  284. +MaybeShared<T> NativeValueTraits<IDLNullable<MaybeShared<T>>>::ArgumentValue(
  285. + v8::Isolate* isolate,
  286. + int argument_index,
  287. + v8::Local<v8::Value> value,
  288. + ExceptionState& exception_state) {
  289. return ArgumentValueImpl<RecipeTrait<MaybeShared<T>>,
  290. ToDOMViewType<T, kMaybeShared>,
  291. Nullablity::kIsNullable, BufferSizeCheck::kCheck,
  292. @@ -853,9 +845,9 @@ MaybeShared<T> NativeValueTraits<
  293. // Nullable [AllowShared, BufferSourceTypeNoSizeLimit] ArrayBufferView
  294. template <typename T>
  295. -MaybeShared<T> NativeValueTraits<
  296. - IDLNullable<IDLBufferSourceTypeNoSizeLimit<MaybeShared<T>>>,
  297. - typename std::enable_if_t<std::is_base_of<DOMArrayBufferView, T>::value>>::
  298. + requires std::derived_from<T, DOMArrayBufferView>
  299. +MaybeShared<T>
  300. +NativeValueTraits<IDLNullable<IDLBufferSourceTypeNoSizeLimit<MaybeShared<T>>>>::
  301. ArgumentValue(v8::Isolate* isolate,
  302. int argument_index,
  303. v8::Local<v8::Value> value,
  304. @@ -870,13 +862,11 @@ MaybeShared<T> NativeValueTraits<
  305. // [AllowShared, FlexibleArrayBufferView] ArrayBufferView
  306. template <typename T>
  307. -T NativeValueTraits<T,
  308. - typename std::enable_if_t<
  309. - std::is_base_of<FlexibleArrayBufferView, T>::value>>::
  310. - ArgumentValue(v8::Isolate* isolate,
  311. - int argument_index,
  312. - v8::Local<v8::Value> value,
  313. - ExceptionState& exception_state) {
  314. + requires std::derived_from<T, FlexibleArrayBufferView>
  315. +T NativeValueTraits<T>::ArgumentValue(v8::Isolate* isolate,
  316. + int argument_index,
  317. + v8::Local<v8::Value> value,
  318. + ExceptionState& exception_state) {
  319. return ArgumentValueImpl<RecipeTrait<T>, ToFlexibleArrayBufferView,
  320. Nullablity::kIsNotNullable, BufferSizeCheck::kCheck,
  321. ResizableAllowance::kDisallowResizable,
  322. @@ -888,13 +878,12 @@ T NativeValueTraits<T,
  323. // ArrayBufferView
  324. template <typename T>
  325. -T NativeValueTraits<IDLBufferSourceTypeNoSizeLimit<T>,
  326. - typename std::enable_if_t<
  327. - std::is_base_of<FlexibleArrayBufferView, T>::value>>::
  328. - ArgumentValue(v8::Isolate* isolate,
  329. - int argument_index,
  330. - v8::Local<v8::Value> value,
  331. - ExceptionState& exception_state) {
  332. + requires std::derived_from<T, FlexibleArrayBufferView>
  333. +T NativeValueTraits<IDLBufferSourceTypeNoSizeLimit<T>>::ArgumentValue(
  334. + v8::Isolate* isolate,
  335. + int argument_index,
  336. + v8::Local<v8::Value> value,
  337. + ExceptionState& exception_state) {
  338. return ArgumentValueImpl<
  339. RecipeTrait<T>, ToFlexibleArrayBufferView, Nullablity::kIsNotNullable,
  340. BufferSizeCheck::kDoNotCheck, ResizableAllowance::kDisallowResizable,
  341. @@ -905,13 +894,12 @@ T NativeValueTraits<IDLBufferSourceTypeNoSizeLimit<T>,
  342. // Nullable [AllowShared, FlexibleArrayBufferView] ArrayBufferView
  343. template <typename T>
  344. -T NativeValueTraits<IDLNullable<T>,
  345. - typename std::enable_if_t<
  346. - std::is_base_of<FlexibleArrayBufferView, T>::value>>::
  347. - ArgumentValue(v8::Isolate* isolate,
  348. - int argument_index,
  349. - v8::Local<v8::Value> value,
  350. - ExceptionState& exception_state) {
  351. + requires std::derived_from<T, FlexibleArrayBufferView>
  352. +T NativeValueTraits<IDLNullable<T>>::ArgumentValue(
  353. + v8::Isolate* isolate,
  354. + int argument_index,
  355. + v8::Local<v8::Value> value,
  356. + ExceptionState& exception_state) {
  357. return ArgumentValueImpl<RecipeTrait<T>, ToFlexibleArrayBufferView,
  358. Nullablity::kIsNullable, BufferSizeCheck::kCheck,
  359. ResizableAllowance::kDisallowResizable,
  360. diff --git a/third_party/blink/renderer/bindings/core/v8/native_value_traits_impl.h b/third_party/blink/renderer/bindings/core/v8/native_value_traits_impl.h
  361. index 899929dcf49f90a..5011503dcf1c0c8 100644
  362. --- a/third_party/blink/renderer/bindings/core/v8/native_value_traits_impl.h
  363. +++ b/third_party/blink/renderer/bindings/core/v8/native_value_traits_impl.h
  364. @@ -5,6 +5,9 @@
  365. #ifndef THIRD_PARTY_BLINK_RENDERER_BINDINGS_CORE_V8_NATIVE_VALUE_TRAITS_IMPL_H_
  366. #define THIRD_PARTY_BLINK_RENDERER_BINDINGS_CORE_V8_NATIVE_VALUE_TRAITS_IMPL_H_
  367. +#include <concepts>
  368. +#include <type_traits>
  369. +
  370. #include "third_party/abseil-cpp/absl/types/optional.h"
  371. #include "third_party/blink/renderer/bindings/core/v8/idl_types.h"
  372. #include "third_party/blink/renderer/bindings/core/v8/native_value_traits.h"
  373. @@ -715,9 +718,8 @@ struct CORE_EXPORT NativeValueTraits<
  374. };
  375. template <typename T>
  376. -struct NativeValueTraits<
  377. - T,
  378. - typename std::enable_if_t<std::is_base_of<DOMArrayBufferView, T>::value>> {
  379. + requires std::derived_from<T, DOMArrayBufferView>
  380. +struct NativeValueTraits<T> {
  381. // NotShared<T> or MaybeShared<T> should be used instead.
  382. static T* NativeValue(v8::Isolate* isolate,
  383. v8::Local<v8::Value> value,
  384. @@ -729,9 +731,8 @@ struct NativeValueTraits<
  385. };
  386. template <typename T>
  387. -struct NativeValueTraits<
  388. - IDLNullable<T>,
  389. - typename std::enable_if_t<std::is_base_of<DOMArrayBufferView, T>::value>> {
  390. + requires std::derived_from<T, DOMArrayBufferView>
  391. +struct NativeValueTraits<IDLNullable<T>> {
  392. // NotShared<T> or MaybeShared<T> should be used instead.
  393. static T* NativeValue(v8::Isolate* isolate,
  394. v8::Local<v8::Value> value,
  395. @@ -743,9 +744,8 @@ struct NativeValueTraits<
  396. };
  397. template <typename T>
  398. -struct NativeValueTraits<
  399. - NotShared<T>,
  400. - typename std::enable_if_t<std::is_base_of<DOMArrayBufferView, T>::value>>
  401. + requires std::derived_from<T, DOMArrayBufferView>
  402. +struct NativeValueTraits<NotShared<T>>
  403. : public NativeValueTraitsBase<NotShared<T>> {
  404. static NotShared<T> NativeValue(v8::Isolate* isolate,
  405. v8::Local<v8::Value> value,
  406. @@ -758,9 +758,8 @@ struct NativeValueTraits<
  407. };
  408. template <typename T>
  409. -struct NativeValueTraits<
  410. - IDLNullable<NotShared<T>>,
  411. - typename std::enable_if_t<std::is_base_of<DOMArrayBufferView, T>::value>>
  412. + requires std::derived_from<T, DOMArrayBufferView>
  413. +struct NativeValueTraits<IDLNullable<NotShared<T>>>
  414. : public NativeValueTraitsBase<NotShared<T>> {
  415. static NotShared<T> NativeValue(v8::Isolate* isolate,
  416. v8::Local<v8::Value> value,
  417. @@ -773,9 +772,8 @@ struct NativeValueTraits<
  418. };
  419. template <typename T>
  420. -struct NativeValueTraits<
  421. - MaybeShared<T>,
  422. - typename std::enable_if_t<std::is_base_of<DOMArrayBufferView, T>::value>>
  423. + requires std::derived_from<T, DOMArrayBufferView>
  424. +struct NativeValueTraits<MaybeShared<T>>
  425. : public NativeValueTraitsBase<MaybeShared<T>> {
  426. static MaybeShared<T> NativeValue(v8::Isolate* isolate,
  427. v8::Local<v8::Value> value,
  428. @@ -788,9 +786,8 @@ struct NativeValueTraits<
  429. };
  430. template <typename T>
  431. -struct NativeValueTraits<
  432. - IDLBufferSourceTypeNoSizeLimit<MaybeShared<T>>,
  433. - typename std::enable_if_t<std::is_base_of<DOMArrayBufferView, T>::value>>
  434. + requires std::derived_from<T, DOMArrayBufferView>
  435. +struct NativeValueTraits<IDLBufferSourceTypeNoSizeLimit<MaybeShared<T>>>
  436. : public NativeValueTraitsBase<MaybeShared<T>> {
  437. // FlexibleArrayBufferView uses this in its implementation, so we cannot
  438. // delete it.
  439. @@ -805,9 +802,8 @@ struct NativeValueTraits<
  440. };
  441. template <typename T>
  442. -struct NativeValueTraits<
  443. - IDLNullable<MaybeShared<T>>,
  444. - typename std::enable_if_t<std::is_base_of<DOMArrayBufferView, T>::value>>
  445. + requires std::derived_from<T, DOMArrayBufferView>
  446. +struct NativeValueTraits<IDLNullable<MaybeShared<T>>>
  447. : public NativeValueTraitsBase<MaybeShared<T>> {
  448. static MaybeShared<T> NativeValue(v8::Isolate* isolate,
  449. v8::Local<v8::Value> value,
  450. @@ -820,9 +816,9 @@ struct NativeValueTraits<
  451. };
  452. template <typename T>
  453. + requires std::derived_from<T, DOMArrayBufferView>
  454. struct NativeValueTraits<
  455. - IDLNullable<IDLBufferSourceTypeNoSizeLimit<MaybeShared<T>>>,
  456. - typename std::enable_if_t<std::is_base_of<DOMArrayBufferView, T>::value>>
  457. + IDLNullable<IDLBufferSourceTypeNoSizeLimit<MaybeShared<T>>>>
  458. : public NativeValueTraitsBase<MaybeShared<T>> {
  459. // BufferSourceTypeNoSizeLimit must be used only as arguments.
  460. static MaybeShared<T> NativeValue(v8::Isolate* isolate,
  461. @@ -836,11 +832,8 @@ struct NativeValueTraits<
  462. };
  463. template <typename T>
  464. -struct NativeValueTraits<
  465. - T,
  466. - typename std::enable_if_t<
  467. - std::is_base_of<FlexibleArrayBufferView, T>::value>>
  468. - : public NativeValueTraitsBase<T> {
  469. + requires std::derived_from<T, FlexibleArrayBufferView>
  470. +struct NativeValueTraits<T> : public NativeValueTraitsBase<T> {
  471. // FlexibleArrayBufferView must be used only as arguments.
  472. static T NativeValue(v8::Isolate* isolate,
  473. v8::Local<v8::Value> value,
  474. @@ -853,10 +846,8 @@ struct NativeValueTraits<
  475. };
  476. template <typename T>
  477. -struct NativeValueTraits<
  478. - IDLBufferSourceTypeNoSizeLimit<T>,
  479. - typename std::enable_if_t<
  480. - std::is_base_of<FlexibleArrayBufferView, T>::value>>
  481. + requires std::derived_from<T, FlexibleArrayBufferView>
  482. +struct NativeValueTraits<IDLBufferSourceTypeNoSizeLimit<T>>
  483. : public NativeValueTraitsBase<T> {
  484. // BufferSourceTypeNoSizeLimit and FlexibleArrayBufferView must be used only
  485. // as arguments.
  486. @@ -871,11 +862,8 @@ struct NativeValueTraits<
  487. };
  488. template <typename T>
  489. -struct NativeValueTraits<
  490. - IDLNullable<T>,
  491. - typename std::enable_if_t<
  492. - std::is_base_of<FlexibleArrayBufferView, T>::value>>
  493. - : public NativeValueTraitsBase<T> {
  494. + requires std::derived_from<T, FlexibleArrayBufferView>
  495. +struct NativeValueTraits<IDLNullable<T>> : public NativeValueTraitsBase<T> {
  496. // FlexibleArrayBufferView must be used only as arguments.
  497. static T NativeValue(v8::Isolate* isolate,
  498. v8::Local<v8::Value> value,
  499. @@ -1134,9 +1122,8 @@ NativeValueTraits<IDLSequence<T>>::NativeValue(
  500. }
  501. template <typename T>
  502. -struct NativeValueTraits<IDLNullable<IDLSequence<T>>,
  503. - typename std::enable_if_t<
  504. - NativeValueTraits<IDLSequence<T>>::has_null_value>>
  505. + requires NativeValueTraits<IDLSequence<T>>::has_null_value
  506. +struct NativeValueTraits<IDLNullable<IDLSequence<T>>>
  507. : public NativeValueTraitsBase<HeapVector<AddMemberIfNeeded<T>>*> {
  508. using ImplType = typename NativeValueTraits<IDLSequence<T>>::ImplType*;
  509. @@ -1203,9 +1190,8 @@ struct NativeValueTraits<IDLArray<T>>
  510. : public NativeValueTraits<IDLSequence<T>> {};
  511. template <typename T>
  512. -struct NativeValueTraits<IDLNullable<IDLArray<T>>,
  513. - typename std::enable_if_t<
  514. - NativeValueTraits<IDLSequence<T>>::has_null_value>>
  515. + requires NativeValueTraits<IDLSequence<T>>::has_null_value
  516. +struct NativeValueTraits<IDLNullable<IDLArray<T>>>
  517. : public NativeValueTraits<IDLNullable<IDLSequence<T>>> {};
  518. // Record types
  519. @@ -1335,10 +1321,8 @@ struct NativeValueTraits<IDLRecord<K, V>>
  520. // Callback function types
  521. template <typename T>
  522. -struct NativeValueTraits<
  523. - T,
  524. - typename std::enable_if_t<std::is_base_of<CallbackFunctionBase, T>::value>>
  525. - : public NativeValueTraitsBase<T*> {
  526. + requires std::derived_from<T, CallbackFunctionBase>
  527. +struct NativeValueTraits<T> : public NativeValueTraitsBase<T*> {
  528. static T* NativeValue(v8::Isolate* isolate,
  529. v8::Local<v8::Value> value,
  530. ExceptionState& exception_state) {
  531. @@ -1361,9 +1345,8 @@ struct NativeValueTraits<
  532. };
  533. template <typename T>
  534. -struct NativeValueTraits<
  535. - IDLNullable<T>,
  536. - typename std::enable_if_t<std::is_base_of<CallbackFunctionBase, T>::value>>
  537. + requires std::derived_from<T, CallbackFunctionBase>
  538. +struct NativeValueTraits<IDLNullable<T>>
  539. : public NativeValueTraitsBase<IDLNullable<T>> {
  540. static T* NativeValue(v8::Isolate* isolate,
  541. v8::Local<v8::Value> value,
  542. @@ -1392,10 +1375,8 @@ struct NativeValueTraits<
  543. // Callback interface types
  544. template <typename T>
  545. -struct NativeValueTraits<
  546. - T,
  547. - typename std::enable_if_t<std::is_base_of<CallbackInterfaceBase, T>::value>>
  548. - : public NativeValueTraitsBase<T*> {
  549. + requires std::derived_from<T, CallbackInterfaceBase>
  550. +struct NativeValueTraits<T> : public NativeValueTraitsBase<T*> {
  551. static T* NativeValue(v8::Isolate* isolate,
  552. v8::Local<v8::Value> value,
  553. ExceptionState& exception_state) {
  554. @@ -1418,9 +1399,8 @@ struct NativeValueTraits<
  555. };
  556. template <typename T>
  557. -struct NativeValueTraits<
  558. - IDLNullable<T>,
  559. - typename std::enable_if_t<std::is_base_of<CallbackInterfaceBase, T>::value>>
  560. + requires std::derived_from<T, CallbackInterfaceBase>
  561. +struct NativeValueTraits<IDLNullable<T>>
  562. : public NativeValueTraitsBase<IDLNullable<T>> {
  563. static T* NativeValue(v8::Isolate* isolate,
  564. v8::Local<v8::Value> value,
  565. @@ -1449,11 +1429,8 @@ struct NativeValueTraits<
  566. // Dictionary types
  567. template <typename T>
  568. -struct NativeValueTraits<
  569. - T,
  570. - typename std::enable_if_t<
  571. - std::is_base_of<bindings::DictionaryBase, T>::value>>
  572. - : public NativeValueTraitsBase<T*> {
  573. + requires std::derived_from<T, bindings::DictionaryBase>
  574. +struct NativeValueTraits<T> : public NativeValueTraitsBase<T*> {
  575. static T* NativeValue(v8::Isolate* isolate,
  576. v8::Local<v8::Value> value,
  577. ExceptionState& exception_state) {
  578. @@ -1464,14 +1441,11 @@ struct NativeValueTraits<
  579. // We don't support nullable dictionary types in general since it's quite
  580. // confusing and often misused.
  581. template <typename T>
  582. -struct NativeValueTraits<
  583. - IDLNullable<T>,
  584. - typename std::enable_if_t<
  585. - std::is_base_of<bindings::DictionaryBase, T>::value &&
  586. - (std::is_same<T, GPUColorTargetState>::value ||
  587. - std::is_same<T, GPURenderPassColorAttachment>::value ||
  588. - std::is_same<T, GPUVertexBufferLayout>::value)>>
  589. - : public NativeValueTraitsBase<T*> {
  590. + requires std::derived_from<T, bindings::DictionaryBase> &&
  591. + (std::same_as<T, GPUColorTargetState> ||
  592. + std::same_as<T, GPURenderPassColorAttachment> ||
  593. + std::same_as<T, GPUVertexBufferLayout>)
  594. +struct NativeValueTraits<IDLNullable<T>> : public NativeValueTraitsBase<T*> {
  595. static T* NativeValue(v8::Isolate* isolate,
  596. v8::Local<v8::Value> value,
  597. ExceptionState& exception_state) {
  598. @@ -1483,11 +1457,8 @@ struct NativeValueTraits<
  599. // Enumeration types
  600. template <typename T>
  601. -struct NativeValueTraits<
  602. - T,
  603. - typename std::enable_if_t<
  604. - std::is_base_of<bindings::EnumerationBase, T>::value>>
  605. - : public NativeValueTraitsBase<T> {
  606. + requires std::derived_from<T, bindings::EnumerationBase>
  607. +struct NativeValueTraits<T> : public NativeValueTraitsBase<T> {
  608. static T NativeValue(v8::Isolate* isolate,
  609. v8::Local<v8::Value> value,
  610. ExceptionState& exception_state) {
  611. @@ -1497,10 +1468,8 @@ struct NativeValueTraits<
  612. // Interface types
  613. template <typename T>
  614. -struct NativeValueTraits<
  615. - T,
  616. - typename std::enable_if_t<std::is_base_of<ScriptWrappable, T>::value>>
  617. - : public NativeValueTraitsBase<T*> {
  618. + requires std::derived_from<T, ScriptWrappable>
  619. +struct NativeValueTraits<T> : public NativeValueTraitsBase<T*> {
  620. static inline T* NativeValue(v8::Isolate* isolate,
  621. v8::Local<v8::Value> value,
  622. ExceptionState& exception_state) {
  623. @@ -1528,9 +1497,8 @@ struct NativeValueTraits<
  624. };
  625. template <typename T>
  626. -struct NativeValueTraits<
  627. - IDLNullable<T>,
  628. - typename std::enable_if_t<std::is_base_of<ScriptWrappable, T>::value>>
  629. + requires std::derived_from<T, ScriptWrappable>
  630. +struct NativeValueTraits<IDLNullable<T>>
  631. : public NativeValueTraitsBase<IDLNullable<T>> {
  632. static inline T* NativeValue(v8::Isolate* isolate,
  633. v8::Local<v8::Value> value,
  634. @@ -1565,10 +1533,8 @@ struct NativeValueTraits<
  635. };
  636. template <typename T>
  637. -struct NativeValueTraits<
  638. - T,
  639. - typename std::enable_if_t<std::is_base_of<bindings::UnionBase, T>::value>>
  640. - : public NativeValueTraitsBase<T*> {
  641. + requires std::derived_from<T, bindings::UnionBase>
  642. +struct NativeValueTraits<T> : public NativeValueTraitsBase<T*> {
  643. static T* NativeValue(v8::Isolate* isolate,
  644. v8::Local<v8::Value> value,
  645. ExceptionState& exception_state) {
  646. @@ -1584,10 +1550,8 @@ struct NativeValueTraits<
  647. };
  648. template <typename T>
  649. -struct NativeValueTraits<
  650. - IDLNullable<T>,
  651. - typename std::enable_if_t<std::is_base_of<bindings::UnionBase, T>::value>>
  652. - : public NativeValueTraitsBase<T*> {
  653. + requires std::derived_from<T, bindings::UnionBase>
  654. +struct NativeValueTraits<IDLNullable<T>> : public NativeValueTraitsBase<T*> {
  655. static T* NativeValue(v8::Isolate* isolate,
  656. v8::Local<v8::Value> value,
  657. ExceptionState& exception_state) {
  658. @@ -1608,9 +1572,8 @@ struct NativeValueTraits<
  659. // Nullable types
  660. template <typename InnerType>
  661. -struct NativeValueTraits<
  662. - IDLNullable<InnerType>,
  663. - typename std::enable_if_t<!NativeValueTraits<InnerType>::has_null_value>>
  664. + requires(!NativeValueTraits<InnerType>::has_null_value)
  665. +struct NativeValueTraits<IDLNullable<InnerType>>
  666. : public NativeValueTraitsBase<IDLNullable<InnerType>> {
  667. // https://webidl.spec.whatwg.org/#es-nullable-type
  668. using ImplType =
  669. @@ -1642,9 +1605,8 @@ struct NativeValueTraits<IDLNullable<IDLNullable<T>>>;
  670. // Optional types
  671. template <typename T>
  672. -struct NativeValueTraits<IDLOptional<T>,
  673. - typename std::enable_if_t<std::is_arithmetic<
  674. - typename NativeValueTraits<T>::ImplType>::value>>
  675. + requires std::is_arithmetic_v<typename NativeValueTraits<T>::ImplType>
  676. +struct NativeValueTraits<IDLOptional<T>>
  677. : public NativeValueTraitsBase<typename NativeValueTraits<T>::ImplType> {
  678. using ImplType = typename NativeValueTraits<T>::ImplType;
  679. @@ -1666,9 +1628,8 @@ struct NativeValueTraits<IDLOptional<T>,
  680. };
  681. template <typename T>
  682. -struct NativeValueTraits<IDLOptional<T>,
  683. - typename std::enable_if_t<std::is_pointer<
  684. - typename NativeValueTraits<T>::ImplType>::value>>
  685. + requires std::is_pointer_v<typename NativeValueTraits<T>::ImplType>
  686. +struct NativeValueTraits<IDLOptional<T>>
  687. : public NativeValueTraitsBase<typename NativeValueTraits<T>::ImplType> {
  688. using ImplType = typename NativeValueTraits<T>::ImplType;