Index: third_party/WebKit/Source/bindings/core/v8/NativeValueTraits.h |
diff --git a/third_party/WebKit/Source/bindings/core/v8/NativeValueTraits.h b/third_party/WebKit/Source/bindings/core/v8/NativeValueTraits.h |
index 3bc77e548afbe3d997b21bdb675e06fdf1f05fac..f627788a2cfcea83c2492f221cd7be1aba00ff31 100644 |
--- a/third_party/WebKit/Source/bindings/core/v8/NativeValueTraits.h |
+++ b/third_party/WebKit/Source/bindings/core/v8/NativeValueTraits.h |
@@ -5,20 +5,65 @@ |
#ifndef NativeValueTraits_h |
#define NativeValueTraits_h |
-#include "v8/include/v8.h" |
+#include <v8.h> |
Yuki
2017/03/06 07:39:42
Don't change this #include.
Our new convention is
|
+#include <type_traits> |
+#include "bindings/core/v8/IDLTypesBase.h" |
#include "wtf/Allocator.h" |
namespace blink { |
class ExceptionState; |
-template <typename T, typename... Arguments> |
-struct NativeValueTraits { |
- STATIC_ONLY(NativeValueTraits); |
- static T nativeValue(v8::Isolate*, |
- v8::Local<v8::Value>, |
- ExceptionState&, |
- Arguments... args); |
+// NativeValueTraitsBase is supposed to be inherited by NativeValueTraits |
+// classes. They serve as a way to hold the ImplType typedef without requiring |
+// all NativeValueTraits specializations to declare it. |
+// |
+// The primary template below is used by NativeValueTraits specializations with |
+// types that do not inherit from IDLBase, in which case it is assumed the type |
+// of the specialization is also |ImplType|. The NativeValueTraitsBase |
+// specialization is used for IDLBase-based types, which are supposed to have |
+// their own |ImplType| typedefs. |
+template <typename T, typename U = void> |
Yuki
2017/03/06 08:14:19
Why do we need |U| here?
Raphael Kubo da Costa (rakuco)
2017/03/06 08:36:52
For the other NativeValueTraitsBase<> declaration
Yuki
2017/03/06 09:03:42
I see.
|
+struct NativeValueTraitsBase { |
+ using ImplType = T; |
+ STATIC_ONLY(NativeValueTraitsBase); |
+}; |
+ |
+template <typename T> |
+struct NativeValueTraitsBase< |
+ T, |
+ typename std::enable_if<std::is_base_of<IDLBase, T>::value>::type> { |
+ using ImplType = typename T::ImplType; |
+ STATIC_ONLY(NativeValueTraitsBase); |
+}; |
+ |
+// Primary template for NativeValueTraits. It is not supposed to be used |
+// directly: there needs to be a specialization for each type which represents |
+// a JavaScript type that will be converted to a C++ representation. |
+// Its main goal is to provide a standard interface for converting JS types |
+// into C++ ones. |
+// |
+// Example: |
+// template <> |
+// struct NativeValueTraits<IDLLong> : public NativeValueTraitsBase<IDLLong> { |
+// static inline int32_t nativeValue(v8::Isolate* isolate, |
+// v8::Local<v8::Value> value, |
+// ExceptionState& exceptionState) { |
+// return toInt32(isolate, value, exceptionState, NormalConversion); |
+// } |
+// } |
+// |
+// Note that there exist some specializations (particularly in V8Binding.h) for |
+// which T actually represents the final C++ type that a JavaScript value |
+// should be converted to. Introducing new specializations of this kind is |
+// discouraged. |
+template <typename T, typename... Args> |
Yuki
2017/03/06 07:39:42
I think that we don't need |Args| here.
We can add
Raphael Kubo da Costa (rakuco)
2017/03/06 08:06:07
|Args| is not needed indeed. I left it there to ke
Yuki
2017/03/06 08:14:19
Why and how does it break? Is there any NativeVal
Raphael Kubo da Costa (rakuco)
2017/03/06 08:36:52
The build failure looks like this:
In file includ
Yuki
2017/03/06 09:03:42
This seems a wrong solution. I now see an issue t
Raphael Kubo da Costa (rakuco)
2017/03/06 09:51:38
We're quite limited in what we can do here if the
Yuki
2017/03/06 10:13:03
What about the following?
template <typename CppT
Raphael Kubo da Costa (rakuco)
2017/03/06 10:40:36
How about being even more explicit with something
Yuki
2017/03/06 10:43:04
Looks good. Could you add a comment which code us
|
+struct NativeValueTraits : public NativeValueTraitsBase<T> { |
+ // This declaration serves only as a blueprint for specializations: the |
+ // return type can change, but all specializations are expected to provide a |
+ // nativeValue() method that takes the 3 arguments below. |
+ static inline typename NativeValueTraitsBase<T>::ImplType |
+ nativeValue(v8::Isolate*, v8::Local<v8::Value>, ExceptionState&); |
}; |
} // namespace blink |