Move parseFontFaceDescriptor to CSSPropertyParser.cpp
[chromium-blink-merge.git] / third_party / WebKit / Source / bindings / templates / union.h
blobb41b8fc0132c0001595e8a83864713f24a05e3d4
1 {% include 'copyright_block.txt' %}
2 #ifndef {{macro_guard}}
3 #define {{macro_guard}}
5 {% for filename in header_includes %}
6 #include "{{filename}}"
7 {% endfor %}
9 namespace blink {
11 {% for decl in header_forward_decls %}
12 class {{decl}};
13 {% endfor %}
15 {% for container in containers %}
16 class {{exported}}{{container.cpp_class}} final {
17 ALLOW_ONLY_INLINE_ALLOCATION();
18 public:
19 {{container.cpp_class}}();
20 bool isNull() const { return m_type == SpecificTypeNone; }
22 {% for member in container.members %}
23 bool is{{member.type_name}}() const { return m_type == {{member.specific_type_enum}}; }
24 {{member.rvalue_cpp_type}} getAs{{member.type_name}}() const;
25 void set{{member.type_name}}({{member.rvalue_cpp_type}});
26 static {{container.cpp_class}} from{{member.type_name}}({{member.rvalue_cpp_type}});
28 {% endfor %}
29 {{container.cpp_class}}(const {{container.cpp_class}}&);
30 ~{{container.cpp_class}}();
31 {{container.cpp_class}}& operator=(const {{container.cpp_class}}&);
32 DECLARE_TRACE();
34 private:
35 enum SpecificTypes {
36 SpecificTypeNone,
37 {% for member in container.members %}
38 {{member.specific_type_enum}},
39 {% endfor %}
41 SpecificTypes m_type;
43 {% for member in container.members %}
44 {{member.cpp_type}} m_{{member.cpp_name}};
45 {% endfor %}
47 friend {{exported}}v8::Local<v8::Value> toV8(const {{container.cpp_class}}&, v8::Local<v8::Object>, v8::Isolate*);
50 class V8{{container.cpp_class}} final {
51 public:
52 {{exported}}static void toImpl(v8::Isolate*, v8::Local<v8::Value>, {{container.cpp_class}}&, ExceptionState&);
55 {{exported}}v8::Local<v8::Value> toV8(const {{container.cpp_class}}&, v8::Local<v8::Object>, v8::Isolate*);
57 template <class CallbackInfo>
58 inline void v8SetReturnValue(const CallbackInfo& callbackInfo, {{container.cpp_class}}& impl)
60 v8SetReturnValue(callbackInfo, toV8(impl, callbackInfo.Holder(), callbackInfo.GetIsolate()));
63 template <>
64 struct NativeValueTraits<{{container.cpp_class}}> {
65 {{exported}}static {{container.cpp_class}} nativeValue(v8::Isolate*, v8::Local<v8::Value>, ExceptionState&);
68 {% endfor %}
69 {% for cpp_type in nullable_cpp_types %}
70 class V8{{cpp_type}}OrNull final {
71 public:
72 static void toImpl(v8::Isolate* isolate, v8::Local<v8::Value> v8Value, {{cpp_type}}& impl, ExceptionState& exceptionState)
74 {# http://heycam.github.io/webidl/#es-union #}
75 {# 1. null or undefined #}
76 if (isUndefinedOrNull(v8Value))
77 return;
78 V8{{cpp_type}}::toImpl(isolate, v8Value, impl, exceptionState);
82 {% endfor %}
83 } // namespace blink
85 // We need to set canInitializeWithMemset=true because HeapVector supports
86 // items that can initialize with memset or have a vtable. It is safe to
87 // set canInitializeWithMemset=true for a union type object in practice.
88 // See https://codereview.chromium.org/1118993002/#msg5 for more details.
89 {% for container in containers %}
90 WTF_ALLOW_MOVE_AND_INIT_WITH_MEM_FUNCTIONS(blink::{{container.cpp_class}});
91 {% endfor %}
93 #endif // {{macro_guard}}