OLD | NEW |
1 {% include 'copyright_block.txt' %} | 1 {% include 'copyright_block.txt' %} |
2 #ifndef {{macro_guard}} | 2 #ifndef {{cpp_class}}_h |
3 #define {{macro_guard}} | 3 #define {{cpp_class}}_h |
4 | 4 |
5 {% for filename in header_includes %} | 5 {% for filename in header_includes %} |
6 #include "{{filename}}" | 6 #include "{{filename}}" |
7 {% endfor %} | 7 {% endfor %} |
8 | 8 |
9 namespace blink { | 9 namespace blink { |
10 | 10 |
11 {% for decl in header_forward_decls %} | 11 {% for decl in header_forward_decls %} |
12 class {{decl}}; | 12 class {{decl}}; |
13 {% endfor %} | 13 {% endfor %} |
14 | 14 |
15 {% for container in containers %} | 15 class {{exported}}{{cpp_class}} final { |
16 class {{exported}}{{container.cpp_class}} final { | |
17 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(); | 16 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(); |
18 public: | 17 public: |
19 {{container.cpp_class}}(); | 18 {{cpp_class}}(); |
20 bool isNull() const { return m_type == SpecificTypeNone; } | 19 bool isNull() const { return m_type == SpecificTypeNone; } |
21 | 20 |
22 {% for member in container.members %} | 21 {% for member in members %} |
23 bool is{{member.type_name}}() const { return m_type == {{member.specific_typ
e_enum}}; } | 22 bool is{{member.type_name}}() const { return m_type == {{member.specific_typ
e_enum}}; } |
24 {{member.rvalue_cpp_type}} getAs{{member.type_name}}() const; | 23 {{member.rvalue_cpp_type}} getAs{{member.type_name}}() const; |
25 void set{{member.type_name}}({{member.rvalue_cpp_type}}); | 24 void set{{member.type_name}}({{member.rvalue_cpp_type}}); |
26 static {{container.cpp_class}} from{{member.type_name}}({{member.rvalue_cpp_
type}}); | 25 static {{cpp_class}} from{{member.type_name}}({{member.rvalue_cpp_type}}); |
27 | 26 |
28 {% endfor %} | 27 {% endfor %} |
29 {{container.cpp_class}}(const {{container.cpp_class}}&); | 28 {{cpp_class}}(const {{cpp_class}}&); |
30 ~{{container.cpp_class}}(); | 29 ~{{cpp_class}}(); |
31 {{container.cpp_class}}& operator=(const {{container.cpp_class}}&); | 30 {{cpp_class}}& operator=(const {{cpp_class}}&); |
32 DECLARE_TRACE(); | 31 DECLARE_TRACE(); |
33 | 32 |
34 private: | 33 private: |
35 enum SpecificTypes { | 34 enum SpecificTypes { |
36 SpecificTypeNone, | 35 SpecificTypeNone, |
37 {% for member in container.members %} | 36 {% for member in members %} |
38 {{member.specific_type_enum}}, | 37 {{member.specific_type_enum}}, |
39 {% endfor %} | 38 {% endfor %} |
40 }; | 39 }; |
41 SpecificTypes m_type; | 40 SpecificTypes m_type; |
42 | 41 |
43 {% for member in container.members %} | 42 {% for member in members %} |
44 {{member.cpp_type}} m_{{member.cpp_name}}; | 43 {{member.cpp_type}} m_{{member.cpp_name}}; |
45 {% endfor %} | 44 {% endfor %} |
46 | 45 |
47 friend {{exported}}v8::Local<v8::Value> toV8(const {{container.cpp_class}}&,
v8::Local<v8::Object>, v8::Isolate*); | 46 friend {{exported}}v8::Local<v8::Value> toV8(const {{cpp_class}}&, v8::Local
<v8::Object>, v8::Isolate*); |
48 }; | 47 }; |
49 | 48 |
50 class V8{{container.cpp_class}} final { | 49 class {{v8_class}} final { |
51 public: | 50 public: |
52 {{exported}}static void toImpl(v8::Isolate*, v8::Local<v8::Value>, {{contain
er.cpp_class}}&, UnionTypeConversionMode, ExceptionState&); | 51 {{exported}}static void toImpl(v8::Isolate*, v8::Local<v8::Value>, {{cpp_cla
ss}}&, UnionTypeConversionMode, ExceptionState&); |
53 }; | 52 }; |
54 | 53 |
55 {{exported}}v8::Local<v8::Value> toV8(const {{container.cpp_class}}&, v8::Local<
v8::Object>, v8::Isolate*); | 54 {{exported}}v8::Local<v8::Value> toV8(const {{cpp_class}}&, v8::Local<v8::Object
>, v8::Isolate*); |
56 | 55 |
57 template <class CallbackInfo> | 56 template <class CallbackInfo> |
58 inline void v8SetReturnValue(const CallbackInfo& callbackInfo, {{container.cpp_c
lass}}& impl) | 57 inline void v8SetReturnValue(const CallbackInfo& callbackInfo, {{cpp_class}}& im
pl) |
59 { | 58 { |
60 v8SetReturnValue(callbackInfo, toV8(impl, callbackInfo.Holder(), callbackInf
o.GetIsolate())); | 59 v8SetReturnValue(callbackInfo, toV8(impl, callbackInfo.Holder(), callbackInf
o.GetIsolate())); |
61 } | 60 } |
62 | 61 |
63 template <> | 62 template <> |
64 struct NativeValueTraits<{{container.cpp_class}}> { | 63 struct NativeValueTraits<{{cpp_class}}> { |
65 {{exported}}static {{container.cpp_class}} nativeValue(v8::Isolate*, v8::Loc
al<v8::Value>, ExceptionState&); | 64 {{exported}}static {{cpp_class}} nativeValue(v8::Isolate*, v8::Local<v8::Val
ue>, ExceptionState&); |
66 }; | 65 }; |
67 | 66 |
68 {% endfor %} | |
69 } // namespace blink | 67 } // namespace blink |
70 | 68 |
71 // We need to set canInitializeWithMemset=true because HeapVector supports | 69 // We need to set canInitializeWithMemset=true because HeapVector supports |
72 // items that can initialize with memset or have a vtable. It is safe to | 70 // items that can initialize with memset or have a vtable. It is safe to |
73 // set canInitializeWithMemset=true for a union type object in practice. | 71 // set canInitializeWithMemset=true for a union type object in practice. |
74 // See https://codereview.chromium.org/1118993002/#msg5 for more details. | 72 // See https://codereview.chromium.org/1118993002/#msg5 for more details. |
75 {% for container in containers %} | 73 WTF_ALLOW_MOVE_AND_INIT_WITH_MEM_FUNCTIONS(blink::{{cpp_class}}); |
76 WTF_ALLOW_MOVE_AND_INIT_WITH_MEM_FUNCTIONS(blink::{{container.cpp_class}}); | |
77 {% endfor %} | |
78 | 74 |
79 #endif // {{macro_guard}} | 75 #endif // {{cpp_class}}_h |
OLD | NEW |