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

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

Issue 2709983004: WIP bindings: Add support for the record<K,V> WebIDL type. (Closed)
Patch Set: Rebased patch using NativeValueTraits for IDL types 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..edddf2817d9a8fb30a874695c171a412b5e01cdc
--- /dev/null
+++ b/third_party/WebKit/Source/bindings/core/v8/IDLTypes.h
@@ -0,0 +1,392 @@
+// 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 {
Yuki 2017/03/02 07:47:28 Do we have a consensus to introduce a new nested n
Raphael Kubo da Costa (rakuco) 2017/03/02 08:16:24 We don't, I introduced this namespace while writin
Yuki 2017/03/02 13:00:24 I'm fine with either way. "IDLFoo" seems okay to
+
+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 {};
+
+struct CORE_EXPORT Promise final {};
+
+template <typename SequenceType>
+struct CORE_EXPORT Sequence final {};
+
+template <typename KeyType, typename ValueType>
+struct CORE_EXPORT Record 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);
+ }
+};
+
+// Promises
+// --------
+template <>
+struct NativeValueTraits<idl::Promise> {
+ using ImplType = ScriptPromise;
+ static inline ScriptPromise nativeValue(v8::Isolate* isolate,
+ v8::Local<v8::Value> value,
+ ExceptionState& exceptionState) {
+ return ScriptPromise::cast(ScriptState::current(isolate), value);
+ }
+};
+
+// 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);
+ }
+};
+
+// Type helpers
+// ------------
+template <typename T>
+struct MaybeWrapped {
+ using ImplType = typename std::
+ conditional<WTF::IsGarbageCollectedType<T>::value, Member<T>, T>::type;
+};
+
+template <typename T>
+struct NeedsHeapVector {
+ static const bool value = WTF::IsGarbageCollectedType<T>::value ||
+ std::is_class<typename V8TypeOf<T>::Type>::value;
+};
+
+// Sequences
+// ---------
+template <typename T>
+struct NativeValueTraits<idl::Sequence<T>> {
+ private:
+ using CppType = typename NativeValueTraits<T>::ImplType;
+ using MaybeWrappedCppType = typename MaybeWrapped<CppType>::ImplType;
+
+ public:
+ using ImplType = typename std::conditional<NeedsHeapVector<CppType>::value,
+ HeapVector<MaybeWrappedCppType>,
+ Vector<MaybeWrappedCppType>>::type;
+
+ CORE_EXPORT static inline ImplType nativeValue(v8::Isolate* isolate,
+ v8::Local<v8::Value> value,
+ ExceptionState& exceptionState,
+ int index = 0) {
+ return toImplArray<ImplType, T>(value, index, isolate, exceptionState);
+ }
+};
+
+// Records
+// -------
+template <typename K, typename V>
+struct NativeValueTraits<idl::Record<K, V>> {
+ private:
+ using ValueCppType = typename NativeValueTraits<V>::ImplType;
+ using MaybeWrappedValueCppType =
+ typename MaybeWrapped<ValueCppType>::ImplType;
+
+ public:
+ using ImplType = typename std::conditional<
+ NeedsHeapVector<ValueCppType>::value,
+ HeapVector<std::pair<String, MaybeWrappedValueCppType>>,
+ Vector<std::pair<String, MaybeWrappedValueCppType>>>::type;
+
+ CORE_EXPORT static inline ImplType nativeValue(
+ v8::Isolate* isolate,
+ v8::Local<v8::Value> value,
+ ExceptionState& exceptionState) {
+ return toImplRecord<K, V, ImplType>(isolate, value, exceptionState);
+ }
+};
+
+} // namespace blink
+
+#endif // IDLTypes_h

Powered by Google App Engine
This is Rietveld 408576698