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

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

Issue 2730183003: bindings: Add C++ versions of WebIDL types and generalize 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..71e9d35f9d3053c408d98a161a25e8968eca6015
--- /dev/null
+++ b/third_party/WebKit/Source/bindings/core/v8/IDLTypes.h
@@ -0,0 +1,82 @@
+// 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/IDLTypesBase.h"
+#include "bindings/core/v8/NativeValueTraits.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 {
+
+class ScriptPromise;
+
+// Boolean
+struct CORE_EXPORT IDLBoolean final : public IDLBaseHelper<bool> {};
+
+// Integers
+struct CORE_EXPORT IDLByte final : public IDLBaseHelper<int8_t> {};
+struct CORE_EXPORT IDLOctet final : public IDLBaseHelper<uint8_t> {};
+struct CORE_EXPORT IDLShort final : public IDLBaseHelper<int16_t> {};
+struct CORE_EXPORT IDLUnsignedShort final : public IDLBaseHelper<uint16_t> {};
+struct CORE_EXPORT IDLLong final : public IDLBaseHelper<int32_t> {};
+struct CORE_EXPORT IDLUnsignedLong final : public IDLBaseHelper<uint32_t> {};
+struct CORE_EXPORT IDLLongLong final : public IDLBaseHelper<int64_t> {};
+struct CORE_EXPORT IDLUnsignedLongLong final : public IDLBaseHelper<uint64_t> {
+};
+
+// Strings
+struct CORE_EXPORT IDLByteString final : public IDLBaseHelper<String> {};
+struct CORE_EXPORT IDLString final : public IDLBaseHelper<String> {};
+struct CORE_EXPORT IDLUSVString final : public IDLBaseHelper<String> {};
+
+// Double
+struct CORE_EXPORT IDLDouble final : public IDLBaseHelper<double> {};
+struct CORE_EXPORT IDLUnrestrictedDouble final : public IDLBaseHelper<double> {
+};
+
+// Float
+struct CORE_EXPORT IDLFloat final : public IDLBaseHelper<float> {};
+struct CORE_EXPORT IDLUnrestrictedFloat final : public IDLBaseHelper<float> {};
+
+struct CORE_EXPORT IDLDate final : public IDLBaseHelper<double> {};
+
+// Promise
+struct CORE_EXPORT IDLPromise final : public IDLBaseHelper<ScriptPromise> {};
+
+// Template helpers for type introspection
+template <typename T>
+struct MaybeWrapped {
Yuki 2017/03/06 07:39:42 MaybeWrapped and NeedsHeapVector are used only ins
Raphael Kubo da Costa (rakuco) 2017/03/06 07:47:22 They're only used by IDLSequence at the moment, bu
Yuki 2017/03/06 07:58:19 I don't think that this is a super great idea, but
+ 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;
+};
+
+// Sequence
+template <typename T>
+struct CORE_EXPORT IDLSequence final : public IDLBase {
+ 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;
+};
+
+} // namespace blink
+
+#endif // IDLTypes_h

Powered by Google App Engine
This is Rietveld 408576698