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

Side by Side Diff: Source/bindings/templates/union_container.cpp

Issue 953123003: IDL: Put generated union type containers in separate files (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 // This file has been auto-generated by {{code_generator}}. DO NOT MODIFY! 5 // This file has been auto-generated by {{code_generator}}. DO NOT MODIFY!
6 6
7 #include "config.h" 7 #include "config.h"
8 #include "{{header_filename}}" 8 #include "{{cpp_class}}.h"
9 9
10 {% macro assign_and_return_if_hasinstance(member) %} 10 {% macro assign_and_return_if_hasinstance(member) %}
11 if (V8{{member.type_name}}::hasInstance(v8Value, isolate)) { 11 if (V8{{member.type_name}}::hasInstance(v8Value, isolate)) {
12 {{member.cpp_local_type}} cppValue = V8{{member.type_name}}::toImpl(v8::Loca l<v8::Object>::Cast(v8Value)); 12 {{member.cpp_local_type}} cppValue = V8{{member.type_name}}::toImpl(v8::Loca l<v8::Object>::Cast(v8Value));
13 impl.set{{member.type_name}}(cppValue); 13 impl.set{{member.type_name}}(cppValue);
14 return; 14 return;
15 } 15 }
16 {% endmacro %} 16 {% endmacro %}
17 {% for filename in cpp_includes %}
18 #include "{{filename}}"
19 {% endfor %}
20 17
21 namespace blink { 18 namespace blink {
22 19
23 {% for container in containers %} 20 {{cpp_class}}::{{cpp_class}}()
24 {{container.cpp_class}}::{{container.cpp_class}}()
25 : m_type(SpecificTypeNone) 21 : m_type(SpecificTypeNone)
26 { 22 {
27 } 23 }
28 24
29 {% for member in container.members %} 25 {% for member in members %}
30 {{member.rvalue_cpp_type}} {{container.cpp_class}}::getAs{{member.type_name}}() const 26 {{member.rvalue_cpp_type}} {{cpp_class}}::getAs{{member.type_name}}() const
31 { 27 {
32 ASSERT(is{{member.type_name}}()); 28 ASSERT(is{{member.type_name}}());
33 return m_{{member.cpp_name}}; 29 return m_{{member.cpp_name}};
34 } 30 }
35 31
36 void {{container.cpp_class}}::set{{member.type_name}}({{member.rvalue_cpp_type}} value) 32 void {{cpp_class}}::set{{member.type_name}}({{member.rvalue_cpp_type}} value)
37 { 33 {
38 ASSERT(isNull()); 34 ASSERT(isNull());
39 {% if member.enum_validation_expression %} 35 {% if member.enum_validation_expression %}
40 String string = value; 36 String string = value;
41 if (!({{member.enum_validation_expression}})) { 37 if (!({{member.enum_validation_expression}})) {
42 ASSERT_NOT_REACHED(); 38 ASSERT_NOT_REACHED();
43 return; 39 return;
44 } 40 }
45 {% endif %} 41 {% endif %}
46 m_{{member.cpp_name}} = value; 42 m_{{member.cpp_name}} = value;
47 m_type = {{member.specific_type_enum}}; 43 m_type = {{member.specific_type_enum}};
48 } 44 }
49 45
50 {{container.cpp_class}} {{container.cpp_class}}::from{{member.type_name}}({{memb er.rvalue_cpp_type}} value) 46 {{cpp_class}} {{cpp_class}}::from{{member.type_name}}({{member.rvalue_cpp_type}} value)
51 { 47 {
52 {{container.cpp_class}} container; 48 {{cpp_class}} container;
53 container.set{{member.type_name}}(value); 49 container.set{{member.type_name}}(value);
54 return container; 50 return container;
55 } 51 }
56 52
57 {% endfor %} 53 {% endfor %}
58 {% if container.needs_trace %} 54 {% if needs_trace %}
59 DEFINE_TRACE({{container.cpp_class}}) 55 DEFINE_TRACE({{cpp_class}})
60 { 56 {
61 {% for member in container.members if member.is_traceable %} 57 {% for member in members if member.is_traceable %}
62 visitor->trace(m_{{member.cpp_name}}); 58 visitor->trace(m_{{member.cpp_name}});
63 {% endfor %} 59 {% endfor %}
64 } 60 }
65 61
66 {% endif %} 62 {% endif %}
67 void V8{{container.cpp_class}}::toImpl(v8::Isolate* isolate, v8::Local<v8::Value > v8Value, {{container.cpp_class}}& impl, ExceptionState& exceptionState) 63 void {{v8_class}}::toImpl(v8::Isolate* isolate, v8::Local<v8::Value> v8Value, {{ cpp_class}}& impl, ExceptionState& exceptionState)
68 { 64 {
69 if (v8Value.IsEmpty()) 65 if (v8Value.IsEmpty())
70 return; 66 return;
71 67
72 {# The numbers in the following comments refer to the steps described in 68 {# The numbers in the following comments refer to the steps described in
73 http://heycam.github.io/webidl/#es-union 69 http://heycam.github.io/webidl/#es-union
74 NOTE: Step 1 (null or undefined) is handled in *OrNull::toImpl() 70 NOTE: Step 1 (null or undefined) is handled in *OrNull::toImpl()
75 FIXME: Implement all necessary steps #} 71 FIXME: Implement all necessary steps #}
76 {# 3. Platform objects (interfaces) #} 72 {# 3. Platform objects (interfaces) #}
77 {% for interface in container.interface_types %} 73 {% for interface in interface_types %}
78 {{assign_and_return_if_hasinstance(interface) | indent}} 74 {{assign_and_return_if_hasinstance(interface) | indent}}
79 75
80 {% endfor %} 76 {% endfor %}
81 {# 8. ArrayBuffer #} 77 {# 8. ArrayBuffer #}
82 {% if container.array_buffer_type %} 78 {% if array_buffer_type %}
83 {{assign_and_return_if_hasinstance(container.array_buffer_type) | indent}} 79 {{assign_and_return_if_hasinstance(array_buffer_type) | indent}}
84 80
85 {% endif %} 81 {% endif %}
86 {# 9., 10. ArrayBufferView #} 82 {# 9., 10. ArrayBufferView #}
87 {# FIXME: Individual typed arrays (e.g. Uint8Array) aren't supported yet. #} 83 {# FIXME: Individual typed arrays (e.g. Uint8Array) aren't supported yet. #}
88 {% if container.array_buffer_view_type %} 84 {% if array_buffer_view_type %}
89 {{assign_and_return_if_hasinstance(container.array_buffer_view_type) | inden t}} 85 {{assign_and_return_if_hasinstance(array_buffer_view_type) | indent}}
90 86
91 {% endif %} 87 {% endif %}
92 {% if container.dictionary_type %} 88 {% if dictionary_type %}
93 {# 12. Dictionaries #} 89 {# 12. Dictionaries #}
94 {# FIXME: This should also check "object but not Date or RegExp". Add checks 90 {# FIXME: This should also check "object but not Date or RegExp". Add checks
95 when we implement conversions for Date and RegExp. #} 91 when we implement conversions for Date and RegExp. #}
96 if (isUndefinedOrNull(v8Value) || v8Value->IsObject()) { 92 if (isUndefinedOrNull(v8Value) || v8Value->IsObject()) {
97 {% if container.dictionary_type.type_name != 'Dictionary' %} 93 {% if dictionary_type.type_name != 'Dictionary' %}
98 {{container.dictionary_type.cpp_local_type}} cppValue; 94 {{dictionary_type.cpp_local_type}} cppValue;
99 {% endif %} 95 {% endif %}
100 {{container.dictionary_type.v8_value_to_local_cpp_value}}; 96 {{dictionary_type.v8_value_to_local_cpp_value}};
101 impl.set{{container.dictionary_type.type_name}}(cppValue); 97 impl.set{{dictionary_type.type_name}}(cppValue);
102 return; 98 return;
103 } 99 }
104 100
105 {% endif %} 101 {% endif %}
106 {% if container.array_or_sequence_type %} 102 {% if array_or_sequence_type %}
107 {# 13. Arrays/Sequences #} 103 {# 13. Arrays/Sequences #}
108 {# FIXME: This should also check "object but not Date or RegExp". Add checks 104 {# FIXME: This should also check "object but not Date or RegExp". Add checks
109 when we implement conversions for Date and RegExp. #} 105 when we implement conversions for Date and RegExp. #}
110 {# FIXME: Should check for sequences too, not just Array instances. #} 106 {# FIXME: Should check for sequences too, not just Array instances. #}
111 if (v8Value->IsArray()) { 107 if (v8Value->IsArray()) {
112 {{container.array_or_sequence_type.v8_value_to_local_cpp_value}}; 108 {{array_or_sequence_type.v8_value_to_local_cpp_value}};
113 impl.set{{container.array_or_sequence_type.type_name}}(cppValue); 109 impl.set{{array_or_sequence_type.type_name}}(cppValue);
114 return; 110 return;
115 } 111 }
116 112
117 {% endif %} 113 {% endif %}
118 {# FIXME: In some cases, we can omit boolean and numeric type checks because 114 {# FIXME: In some cases, we can omit boolean and numeric type checks because
119 we have fallback conversions. (step 17 and 18) #} 115 we have fallback conversions. (step 17 and 18) #}
120 {% if container.boolean_type %} 116 {% if boolean_type %}
121 {# 14. Boolean #} 117 {# 14. Boolean #}
122 if (v8Value->IsBoolean()) { 118 if (v8Value->IsBoolean()) {
123 impl.setBoolean(v8Value->ToBoolean()->Value()); 119 impl.setBoolean(v8Value->ToBoolean()->Value());
124 return; 120 return;
125 } 121 }
126 122
127 {% endif %} 123 {% endif %}
128 {% if container.numeric_type %} 124 {% if numeric_type %}
129 {# 15. Number #} 125 {# 15. Number #}
130 if (v8Value->IsNumber()) { 126 if (v8Value->IsNumber()) {
131 {{container.numeric_type.v8_value_to_local_cpp_value}}; 127 {{numeric_type.v8_value_to_local_cpp_value}};
132 impl.set{{container.numeric_type.type_name}}(cppValue); 128 impl.set{{numeric_type.type_name}}(cppValue);
133 return; 129 return;
134 } 130 }
135 131
136 {% endif %} 132 {% endif %}
137 {% if container.string_type %} 133 {% if string_type %}
138 {# 16. String #} 134 {# 16. String #}
139 { 135 {
140 {{container.string_type.v8_value_to_local_cpp_value}}; 136 {{string_type.v8_value_to_local_cpp_value}};
141 {% if container.string_type.enum_validation_expression %} 137 {% if string_type.enum_validation_expression %}
142 String string = cppValue; 138 String string = cppValue;
143 if (!({{container.string_type.enum_validation_expression}})) { 139 if (!({{string_type.enum_validation_expression}})) {
144 exceptionState.throwTypeError("'" + string + "' is not a valid enum value."); 140 exceptionState.throwTypeError("'" + string + "' is not a valid enum value.");
145 return; 141 return;
146 } 142 }
147 {% endif %} 143 {% endif %}
148 impl.set{{container.string_type.type_name}}(cppValue); 144 impl.set{{string_type.type_name}}(cppValue);
149 return; 145 return;
150 } 146 }
151 147
152 {# 17. Number (fallback) #} 148 {# 17. Number (fallback) #}
153 {% elif container.numeric_type %} 149 {% elif numeric_type %}
154 { 150 {
155 {{container.numeric_type.v8_value_to_local_cpp_value}}; 151 {{numeric_type.v8_value_to_local_cpp_value}};
156 impl.set{{container.numeric_type.type_name}}(cppValue); 152 impl.set{{numeric_type.type_name}}(cppValue);
157 return; 153 return;
158 } 154 }
159 155
160 {# 18. Boolean (fallback) #} 156 {# 18. Boolean (fallback) #}
161 {% elif container.boolean_type %} 157 {% elif boolean_type %}
162 { 158 {
163 impl.setBoolean(v8Value->ToBoolean()->Value()); 159 impl.setBoolean(v8Value->ToBoolean()->Value());
164 return; 160 return;
165 } 161 }
166 162
167 {% else %} 163 {% else %}
168 {# 19. TypeError #} 164 {# 19. TypeError #}
169 exceptionState.throwTypeError("The provided value is not of type '{{containe r.type_string}}'"); 165 exceptionState.throwTypeError("The provided value is not of type '{{type_str ing}}'");
170 {% endif %} 166 {% endif %}
171 } 167 }
172 168
173 v8::Local<v8::Value> toV8(const {{container.cpp_class}}& impl, v8::Local<v8::Obj ect> creationContext, v8::Isolate* isolate) 169 v8::Local<v8::Value> toV8(const {{cpp_class}}& impl, v8::Local<v8::Object> creat ionContext, v8::Isolate* isolate)
174 { 170 {
175 switch (impl.m_type) { 171 switch (impl.m_type) {
176 case {{container.cpp_class}}::SpecificTypeNone: 172 case {{cpp_class}}::SpecificTypeNone:
177 {# FIXME: We might want to return undefined in some cases #} 173 {# FIXME: We might want to return undefined in some cases #}
178 return v8::Null(isolate); 174 return v8::Null(isolate);
179 {% for member in container.members %} 175 {% for member in members %}
180 case {{container.cpp_class}}::{{member.specific_type_enum}}: 176 case {{cpp_class}}::{{member.specific_type_enum}}:
181 return {{member.cpp_value_to_v8_value}}; 177 return {{member.cpp_value_to_v8_value}};
182 {% endfor %} 178 {% endfor %}
183 default: 179 default:
184 ASSERT_NOT_REACHED(); 180 ASSERT_NOT_REACHED();
185 } 181 }
186 return v8::Local<v8::Value>(); 182 return v8::Local<v8::Value>();
187 } 183 }
188 184
189 {{container.cpp_class}} NativeValueTraits<{{container.cpp_class}}>::nativeValue( const v8::Local<v8::Value>& value, v8::Isolate* isolate, ExceptionState& excepti onState) 185 {{cpp_class}} NativeValueTraits<{{cpp_class}}>::nativeValue(const v8::Local<v8:: Value>& value, v8::Isolate* isolate, ExceptionState& exceptionState)
190 { 186 {
191 {{container.cpp_class}} impl; 187 {{cpp_class}} impl;
192 V8{{container.cpp_class}}::toImpl(isolate, value, impl, exceptionState); 188 {{v8_class}}::toImpl(isolate, value, impl, exceptionState);
193 return impl; 189 return impl;
194 } 190 }
195 191
196 {% endfor %}
197 } // namespace blink 192 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698