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

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

Issue 2732093003: bindings: Add support for the record<K,V> WebIDL type. (Closed)
Patch Set: s/isolate->GetCurrentContext()/context/ Created 3 years, 9 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2017 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef IDLTypes_h 5 #ifndef IDLTypes_h
6 #define IDLTypes_h 6 #define IDLTypes_h
7 7
8 #include <type_traits> 8 #include <type_traits>
9 #include "bindings/core/v8/IDLTypesBase.h" 9 #include "bindings/core/v8/IDLTypesBase.h"
10 #include "bindings/core/v8/NativeValueTraits.h" 10 #include "bindings/core/v8/NativeValueTraits.h"
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 struct IDLDate final : public IDLBaseHelper<double> {}; 47 struct IDLDate final : public IDLBaseHelper<double> {};
48 48
49 // Promise 49 // Promise
50 struct IDLPromise final : public IDLBaseHelper<ScriptPromise> {}; 50 struct IDLPromise final : public IDLBaseHelper<ScriptPromise> {};
51 51
52 // Sequence 52 // Sequence
53 template <typename T> 53 template <typename T>
54 struct IDLSequence final : public IDLBase { 54 struct IDLSequence final : public IDLBase {
55 private: 55 private:
56 using CppType = typename NativeValueTraits<T>::ImplType; 56 using CppType = typename NativeValueTraits<T>::ImplType;
57 using MaybeWrappedCppType = 57 using MaybeMemberCppType =
58 typename std::conditional<WTF::IsGarbageCollectedType<CppType>::value, 58 typename std::conditional<WTF::IsGarbageCollectedType<CppType>::value,
59 Member<CppType>, 59 Member<CppType>,
60 CppType>::type; 60 CppType>::type;
61 61
62 public: 62 public:
63 // Two kinds of types need HeapVector: 63 // Two kinds of types need HeapVector:
64 // 1. Oilpan types, which are wrapped by Member<>. 64 // 1. Oilpan types, which are wrapped by Member<>.
65 // 2. IDL unions and dictionaries, which are not Oilpan types themselves (and 65 // 2. IDL unions and dictionaries, which are not Oilpan types themselves (and
66 // are thus not wrapped by Member<>) but have a trace() method and can 66 // are thus not wrapped by Member<>) but have a trace() method and can
67 // contain Oilpan members. They both also happen to specialize V8TypeOf, 67 // contain Oilpan members. They both also happen to specialize V8TypeOf,
68 // which we use to recognize them. 68 // which we use to recognize them.
69 using ImplType = typename std::conditional< 69 using ImplType = typename std::conditional<
70 std::is_same<MaybeWrappedCppType, Member<CppType>>::value || 70 std::is_same<MaybeMemberCppType, Member<CppType>>::value ||
71 std::is_class<typename V8TypeOf<CppType>::Type>::value, 71 std::is_class<typename V8TypeOf<CppType>::Type>::value,
72 HeapVector<MaybeWrappedCppType>, 72 HeapVector<MaybeMemberCppType>,
73 Vector<CppType>>::type; 73 Vector<CppType>>::type;
74 }; 74 };
75 75
76 // Record
77 template <typename Key, typename Value>
78 struct IDLRecord final : public IDLBase {
79 static_assert(std::is_same<Key, IDLByteString>::value ||
80 std::is_same<Key, IDLString>::value ||
81 std::is_same<Key, IDLUSVString>::value,
82 "IDLRecord keys must be of a WebIDL string type");
83
84 private:
85 // Record keys are always strings, so we do not need to introspect them.
86 using ValueCppType = typename NativeValueTraits<Value>::ImplType;
87 using MaybeMemberValueCppType = typename std::conditional<
88 WTF::IsGarbageCollectedType<ValueCppType>::value,
89 Member<ValueCppType>,
90 ValueCppType>::type;
91
92 public:
93 // Two kinds of types need HeapVector:
94 // 1. Oilpan types, which are wrapped by Member<>.
95 // 2. IDL unions and dictionaries, which are not Oilpan types themselves (and
96 // are thus not wrapped by Member<>) but have a trace() method and can
97 // contain Oilpan members. They both also happen to specialize V8TypeOf,
98 // which we use to recognize them.
99 using ImplType = typename std::conditional<
100 std::is_same<MaybeMemberValueCppType, Member<ValueCppType>>::value ||
101 std::is_class<typename V8TypeOf<ValueCppType>::Type>::value,
102 HeapVector<std::pair<String, MaybeMemberValueCppType>>,
103 Vector<std::pair<String, ValueCppType>>>::type;
104 };
105
76 } // namespace blink 106 } // namespace blink
77 107
78 #endif // IDLTypes_h 108 #endif // IDLTypes_h
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/bindings/core/v8/BUILD.gn ('k') | third_party/WebKit/Source/bindings/core/v8/IDLTypesTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698