Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(128)

Unified Diff: third_party/WebKit/Source/bindings/core/v8/IDLTypes.h

Issue 2725673002: WIP bindings: Expand usage of NativeValueTraits. (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/bindings/core/v8/IDLTypes.h
diff --git a/third_party/WebKit/Source/bindings/core/v8/IDLTypes.h b/third_party/WebKit/Source/bindings/core/v8/IDLTypes.h
new file mode 100644
index 0000000000000000000000000000000000000000..eb17c7ddeeda7ea03c68a225820393e1518acb06
--- /dev/null
+++ b/third_party/WebKit/Source/bindings/core/v8/IDLTypes.h
@@ -0,0 +1,335 @@
+// Copyright (c) 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef IDLTypes_h
+#define IDLTypes_h
+
+#include <type_traits>
+#include "bindings/core/v8/NativeValueTraits.h"
+#include "bindings/core/v8/SerializedScriptValue.h"
+#include "bindings/core/v8/V8Binding.h"
+#include "core/CoreExport.h"
+#include "platform/heap/Handle.h"
+#include "wtf/TypeTraits.h"
+#include "wtf/text/WTFString.h"
+
+namespace blink {
+
+namespace idl {
+
+struct CORE_EXPORT Boolean final {};
+
+struct CORE_EXPORT Byte final {};
+struct CORE_EXPORT Octet final {};
+struct CORE_EXPORT Short final {};
+struct CORE_EXPORT UnsignedShort final {};
+struct CORE_EXPORT Long final {};
+struct CORE_EXPORT UnsignedLong final {};
+struct CORE_EXPORT LongLong final {};
+struct CORE_EXPORT UnsignedLongLong final {};
+
+struct CORE_EXPORT ByteString final {};
+struct CORE_EXPORT String final {};
+struct CORE_EXPORT USVString final {};
+
+struct CORE_EXPORT Double final {};
+struct CORE_EXPORT UnrestrictedDouble final {};
+
+struct CORE_EXPORT Float final {};
+struct CORE_EXPORT UnrestrictedFloat final {};
+
+struct CORE_EXPORT Date final {};
+
+template <typename SequenceType>
+struct CORE_EXPORT Sequence final {};
+
+} // namespace idl
+
+class DOMWindow;
+
+// Boolean
+// -------
+template <>
+struct NativeValueTraits<idl::Boolean> {
+ using ImplType = bool;
+
+ CORE_EXPORT static inline bool nativeValue(v8::Isolate* isolate,
+ v8::Local<v8::Value> value,
+ ExceptionState& exceptionState) {
+ return toBoolean(isolate, value, exceptionState);
+ }
+};
+
+// Integers
+// --------
+template <>
+struct NativeValueTraits<idl::Byte> {
+ using ImplType = int8_t;
+
+ CORE_EXPORT static inline int8_t nativeValue(v8::Isolate* isolate,
+ v8::Local<v8::Value> value,
+ ExceptionState& exceptionState,
+ IntegerConversionConfiguration conversionMode = NormalConversion) {
+ return toInt8(isolate, value, conversionMode, exceptionState);
+ }
+};
+
+template <>
+struct NativeValueTraits<idl::Octet> {
+ using ImplType = uint8_t;
+
+ CORE_EXPORT static inline uint8_t nativeValue(v8::Isolate* isolate,
+ v8::Local<v8::Value> value,
+ ExceptionState& exceptionState,
+ IntegerConversionConfiguration conversionMode = NormalConversion) {
+ return toUInt8(isolate, value, conversionMode, exceptionState);
+ }
+};
+
+template <>
+struct NativeValueTraits<idl::Short> {
+ using ImplType = int16_t;
+
+ CORE_EXPORT static inline int16_t nativeValue(v8::Isolate* isolate,
+ v8::Local<v8::Value> value,
+ ExceptionState& exceptionState,
+ IntegerConversionConfiguration conversionMode = NormalConversion) {
+ return toInt16(isolate, value, conversionMode, exceptionState);
+ }
+};
+
+template <>
+struct NativeValueTraits<idl::UnsignedShort> {
+ using ImplType = uint16_t;
+
+ CORE_EXPORT static inline uint16_t nativeValue(v8::Isolate* isolate,
+ v8::Local<v8::Value> value,
+ ExceptionState& exceptionState,
+ IntegerConversionConfiguration conversionMode = NormalConversion) {
+ return toUInt16(isolate, value, conversionMode, exceptionState);
+ }
+};
+
+template <>
+struct NativeValueTraits<idl::Long> {
+ using ImplType = int32_t;
+
+ CORE_EXPORT static inline int32_t nativeValue(v8::Isolate* isolate,
+ v8::Local<v8::Value> value,
+ ExceptionState& exceptionState,
+ IntegerConversionConfiguration conversionMode = NormalConversion) {
+ return toInt32(isolate, value, conversionMode, exceptionState);
+ }
+};
+
+template <>
+struct NativeValueTraits<idl::UnsignedLong> {
+ using ImplType = uint32_t;
+
+ CORE_EXPORT static inline uint32_t nativeValue(v8::Isolate* isolate,
+ v8::Local<v8::Value> value,
+ ExceptionState& exceptionState,
+ IntegerConversionConfiguration conversionMode = NormalConversion) {
+ return toUInt32(isolate, value, conversionMode, exceptionState);
+ }
+};
+
+template <>
+struct NativeValueTraits<idl::LongLong> {
+ using ImplType = int64_t;
+
+ CORE_EXPORT static inline int64_t nativeValue(v8::Isolate* isolate,
+ v8::Local<v8::Value> value,
+ ExceptionState& exceptionState,
+ IntegerConversionConfiguration conversionMode = NormalConversion) {
+ return toInt64(isolate, value, conversionMode, exceptionState);
+ }
+};
+
+template <>
+struct NativeValueTraits<idl::UnsignedLongLong> {
+ using ImplType = uint64_t;
+
+ CORE_EXPORT static inline uint64_t nativeValue(v8::Isolate* isolate,
+ v8::Local<v8::Value> value,
+ ExceptionState& exceptionState,
+ IntegerConversionConfiguration conversionMode = NormalConversion) {
+ return toUInt64(isolate, value, conversionMode, exceptionState);
+ }
+};
+
+// Strings
+// -------
+template <>
+struct NativeValueTraits<idl::ByteString> {
+ using ImplType = String;
+
+ CORE_EXPORT static inline String nativeValue(v8::Isolate* isolate,
+ v8::Local<v8::Value> value,
+ ExceptionState& exceptionState) {
+ return toByteString(isolate, value, exceptionState);
+ }
+};
+
+template <>
+struct NativeValueTraits<idl::String> {
+ using ImplType = String;
+
+ template <V8StringResourceMode Mode = DefaultMode>
+ CORE_EXPORT static inline String nativeValue(v8::Isolate* isolate,
+ v8::Local<v8::Value> value,
+ ExceptionState& exceptionState) {
+ V8StringResource<Mode> s(value);
+ if (!s.prepare(isolate, exceptionState))
+ return String();
+ return s;
+ }
+};
+
+template <>
+struct NativeValueTraits<idl::USVString> {
+ using ImplType = String;
+
+ CORE_EXPORT static inline String nativeValue(v8::Isolate* isolate,
+ v8::Local<v8::Value> value,
+ ExceptionState& exceptionState) {
+ return toUSVString(isolate, value, exceptionState);
+ }
+};
+
+// Floats and doubles
+// ------------------
+template <>
+struct NativeValueTraits<idl::Double> {
+ using ImplType = double;
+
+ CORE_EXPORT static inline double nativeValue(v8::Isolate* isolate,
+ v8::Local<v8::Value> value,
+ ExceptionState& exceptionState) {
+ return toRestrictedDouble(isolate, value, exceptionState);
+ }
+};
+
+template <>
+struct NativeValueTraits<idl::UnrestrictedDouble> {
+ using ImplType = double;
+
+ CORE_EXPORT static inline double nativeValue(v8::Isolate* isolate,
+ v8::Local<v8::Value> value,
+ ExceptionState& exceptionState) {
+ return toDouble(isolate, value, exceptionState);
+ }
+};
+
+template <>
+struct NativeValueTraits<idl::Float> {
+ using ImplType = float;
+
+ CORE_EXPORT static inline float nativeValue(v8::Isolate* isolate,
+ v8::Local<v8::Value> value,
+ ExceptionState& exceptionState) {
+ return toRestrictedFloat(isolate, value, exceptionState);
+ }
+};
+
+template <>
+struct NativeValueTraits<idl::UnrestrictedFloat> {
+ using ImplType = float;
+
+ CORE_EXPORT static inline float nativeValue(v8::Isolate* isolate,
+ v8::Local<v8::Value> value,
+ ExceptionState& exceptionState) {
+ return toFloat(isolate, value, exceptionState);
+ }
+};
+
+// Type-specific overloads.
+// ------------------------
+template <>
+struct NativeValueTraits<DOMWindow> {
+ using ImplType = DOMWindow;
+
+ CORE_EXPORT static inline DOMWindow* nativeValue(
+ v8::Isolate* isolate,
+ v8::Local<v8::Value> value,
+ ExceptionState& exceptionState) {
+ return toDOMWindow(isolate, value);
+ }
+};
+
+template <>
+struct NativeValueTraits<SerializedScriptValue> {
+ using ImplType = SerializedScriptValue;
+
+ CORE_EXPORT static inline PassRefPtr<SerializedScriptValue> nativeValue(
+ v8::Isolate* isolate,
+ v8::Local<v8::Value> value,
+ ExceptionState& exceptionState) {
+ return SerializedScriptValue::serialize(isolate, value, nullptr, nullptr, exceptionState);
+ }
+};
+
+template <>
+struct NativeValueTraits<idl::Date> {
+ using ImplType = double;
+
+ CORE_EXPORT static inline double nativeValue(v8::Isolate* isolate,
+ v8::Local<v8::Value> value,
+ ExceptionState& exceptionState) {
+ return toCoreDate(isolate, value, exceptionState);
+ }
+};
+
+template <typename T>
+struct NativeValueTraits<Member<T>> {
+ using ImplType = Member<T>;
+
+ CORE_EXPORT static inline T* nativeValue(v8::Isolate* isolate,
+ v8::Local<v8::Value> value,
+ ExceptionState& exceptionState) {
+ return NativeValueTraits<T>::nativeValue(isolate, value, exceptionState);
+ }
+};
+
+template <typename T>
+struct NativeValueTraits<T> {
+ using ImplType = T;
+
+ CORE_EXPORT static inline T* nativeValue(v8::Isolate* isolate,
+ v8::Local<v8::Value> value,
+ ExceptionState& exceptionState) {
+ return V8TypeOf<T>::Type::toImplWithTypeCheck(isolate, value);
+ }
+};
+
+// Sequences
+// ---------
+template <typename T>
+struct NativeValueTraits<idl::Sequence<T>> {
+ private:
+ using MemberImplType = typename NativeValueTraits<T>::ImplType;
+ using FullMemberImplType = typename std::conditional<WTF::IsGarbageCollectedType<MemberImplType>::value,
+ Member<MemberImplType>,
+ MemberImplType>::type;
+
+ public:
+ // This template metaprogramming black magic intends to cover the following cases:
+ // * The vector's member type is an Oilpan type: use HeapVector<Member<T>>
+ // * The vector's member type is an IDL union or dictionary type: use HeapVector<T>
+ // * Everything else: use a simple Vector<T>
+ using ImplType =
+ typename std::conditional<WTF::IsGarbageCollectedType<MemberImplType>::value ||
+ std::is_class<typename V8TypeOf<MemberImplType>::Type>::value,
+ HeapVector<FullMemberImplType>,
+ Vector<FullMemberImplType>>::type;
+
+ CORE_EXPORT static inline ImplType
+ nativeValue(v8::Isolate* isolate, v8::Local<v8::Value> value, ExceptionState& exceptionState, int index = 0) {
+ return toImplArray<ImplType>(value, index, isolate, exceptionState);
+ }
+};
+
+} // namespace blink
+
+#endif // IDLTypes_h

Powered by Google App Engine
This is Rietveld 408576698