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

Side by Side Diff: third_party/WebKit/Source/bindings/templates/union_container.cpp.tmpl

Issue 2709983004: WIP bindings: Add support for the record<K,V> WebIDL type. (Closed)
Patch Set: Rebased patch using NativeValueTraits for IDL types 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 {% from 'utilities.cpp.tmpl' import declare_enum_validation_variable %} 1 {% from 'utilities.cpp.tmpl' import declare_enum_validation_variable %}
2 {% from 'utilities.cpp.tmpl' import v8_value_to_local_cpp_value %} 2 {% from 'utilities.cpp.tmpl' import v8_value_to_local_cpp_value %}
3 {#############################################################################} 3 {#############################################################################}
4 {% macro assign_and_return_if_hasinstance(member) %} 4 {% macro assign_and_return_if_hasinstance(member) %}
5 {% if member.is_array_buffer_or_view_type %} 5 {% if member.is_array_buffer_or_view_type %}
6 if (v8Value->Is{{member.type_name}}()) { 6 if (v8Value->Is{{member.type_name}}()) {
7 {% else %} 7 {% else %}
8 if (V8{{member.type_name}}::hasInstance(v8Value, isolate)) { 8 if (V8{{member.type_name}}::hasInstance(v8Value, isolate)) {
9 {% endif %} 9 {% endif %}
10 {{member.cpp_local_type}} cppValue = V8{{member.type_name}}::toImpl(v8::Local< v8::Object>::Cast(v8Value)); 10 {{member.cpp_local_type}} cppValue = V8{{member.type_name}}::toImpl(v8::Local< v8::Object>::Cast(v8Value));
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 {{assign_and_return_if_hasinstance(array_buffer_type) | indent(2)}} 91 {{assign_and_return_if_hasinstance(array_buffer_type) | indent(2)}}
92 92
93 {% endif %} 93 {% endif %}
94 {# 9., 10. ArrayBufferView #} 94 {# 9., 10. ArrayBufferView #}
95 {# FIXME: Individual typed arrays (e.g. Uint8Array) aren\'t supported yet. #} 95 {# FIXME: Individual typed arrays (e.g. Uint8Array) aren\'t supported yet. #}
96 {% if array_buffer_view_type %} 96 {% if array_buffer_view_type %}
97 {{assign_and_return_if_hasinstance(array_buffer_view_type) | indent(2)}} 97 {{assign_and_return_if_hasinstance(array_buffer_view_type) | indent(2)}}
98 98
99 {% endif %} 99 {% endif %}
100 {% if array_or_sequence_type %} 100 {% if array_or_sequence_type %}
101 {# 12.1, 12.2. Arrays and Sequences #} 101 {# 11.1, 11.2. Arrays and Sequences #}
102 {# FIXME: This should also check "object but not RegExp". Add checks 102 {# FIXME: This should also check "object but not RegExp". Add checks
103 when we implement conversions for Date and RegExp. #} 103 when we implement conversions for Date and RegExp. #}
104 {# TODO(bashi): Should check @@iterator symbol instead. #} 104 {# TODO(bashi): Should check @@iterator symbol instead. #}
105 if (v8Value->IsArray()) { 105 if (v8Value->IsArray()) {
106 {{v8_value_to_local_cpp_value(array_or_sequence_type) | indent}} 106 {{v8_value_to_local_cpp_value(array_or_sequence_type) | indent}}
107 impl.set{{array_or_sequence_type.type_name}}(cppValue); 107 impl.set{{array_or_sequence_type.type_name}}(cppValue);
108 return; 108 return;
109 } 109 }
110 110
111 {% endif %} 111 {% endif %}
112 {% if dictionary_type %} 112 {% if dictionary_type %}
113 {# 12.3. Dictionaries #} 113 {# 11.3. Dictionaries #}
114 if (v8Value->IsObject()) { 114 if (v8Value->IsObject()) {
115 {{v8_value_to_local_cpp_value(dictionary_type) | indent}} 115 {{v8_value_to_local_cpp_value(dictionary_type) | indent}}
116 impl.set{{dictionary_type.type_name}}(cppValue); 116 impl.set{{dictionary_type.type_name}}(cppValue);
117 return; 117 return;
118 } 118 }
119 119
120 {% endif %} 120 {% endif %}
121 {# TODO(bashi): Support 12.4 Callback interface when we need it #} 121 {# 11.4. Records #}
122 {# 12.5. Objects #} 122 {% if record_type %}
123 if (v8Value->IsObject()) {
124 {{v8_value_to_local_cpp_value(record_type) | indent}}
125 impl.set{{record_type.type_name}}(cppValue);
126 return;
127 }
128
129 {% endif %}
130 {# TODO(bashi): Support 11.5 Callback interface when we need it #}
131 {# 11.6. Objects #}
123 {% if object_type %} 132 {% if object_type %}
124 if (isUndefinedOrNull(v8Value) || v8Value->IsObject()) { 133 if (isUndefinedOrNull(v8Value) || v8Value->IsObject()) {
125 {{v8_value_to_local_cpp_value(object_type) | indent}} 134 {{v8_value_to_local_cpp_value(object_type) | indent}}
126 impl.set{{object_type.type_name}}(cppValue); 135 impl.set{{object_type.type_name}}(cppValue);
127 return; 136 return;
128 } 137 }
129 138
130 {% endif %} 139 {% endif %}
131 {# FIXME: In some cases, we can omit boolean and numeric type checks because 140 {# FIXME: In some cases, we can omit boolean and numeric type checks because
132 we have fallback conversions. (step 16 and 17) #} 141 we have fallback conversions. (step 16 and 17) #}
133 {% if boolean_type %} 142 {% if boolean_type %}
134 {# 13. Boolean #} 143 {# 12. Boolean #}
135 if (v8Value->IsBoolean()) { 144 if (v8Value->IsBoolean()) {
136 impl.setBoolean(v8Value.As<v8::Boolean>()->Value()); 145 impl.setBoolean(v8Value.As<v8::Boolean>()->Value());
137 return; 146 return;
138 } 147 }
139 148
140 {% endif %} 149 {% endif %}
141 {% if numeric_type %} 150 {% if numeric_type %}
142 {# 14. Number #} 151 {# 13. Number #}
143 if (v8Value->IsNumber()) { 152 if (v8Value->IsNumber()) {
144 {{v8_value_to_local_cpp_value(numeric_type) | indent}} 153 {{v8_value_to_local_cpp_value(numeric_type) | indent}}
145 impl.set{{numeric_type.type_name}}(cppValue); 154 impl.set{{numeric_type.type_name}}(cppValue);
146 return; 155 return;
147 } 156 }
148 157
149 {% endif %} 158 {% endif %}
150 {% if string_type %} 159 {% if string_type %}
151 {# 15. String #} 160 {# 14. String #}
152 { 161 {
153 {{v8_value_to_local_cpp_value(string_type) | indent}} 162 {{v8_value_to_local_cpp_value(string_type) | indent}}
154 {% if string_type.enum_values %} 163 {% if string_type.enum_values %}
155 {{declare_enum_validation_variable(string_type.enum_values) | indent}} 164 {{declare_enum_validation_variable(string_type.enum_values) | indent}}
156 if (!isValidEnum(cppValue, validValues, WTF_ARRAY_LENGTH(validValues), "{{st ring_type.type_name}}", exceptionState)) 165 if (!isValidEnum(cppValue, validValues, WTF_ARRAY_LENGTH(validValues), "{{st ring_type.type_name}}", exceptionState))
157 return; 166 return;
158 {% endif %} 167 {% endif %}
159 impl.set{{string_type.type_name}}(cppValue); 168 impl.set{{string_type.type_name}}(cppValue);
160 return; 169 return;
161 } 170 }
162 171
163 {# 16. Number (fallback) #} 172 {# 15. Number (fallback) #}
164 {% elif numeric_type %} 173 {% elif numeric_type %}
165 { 174 {
166 {{v8_value_to_local_cpp_value(numeric_type) | indent}} 175 {{v8_value_to_local_cpp_value(numeric_type) | indent}}
167 impl.set{{numeric_type.type_name}}(cppValue); 176 impl.set{{numeric_type.type_name}}(cppValue);
168 return; 177 return;
169 } 178 }
170 179
171 {# 17. Boolean (fallback) #} 180 {# 16. Boolean (fallback) #}
172 {% elif boolean_type %} 181 {% elif boolean_type %}
173 { 182 {
174 impl.setBoolean(v8Value->BooleanValue()); 183 impl.setBoolean(v8Value->BooleanValue());
175 return; 184 return;
176 } 185 }
177 186
178 {% else %} 187 {% else %}
179 {# 18. TypeError #} 188 {# 17. TypeError #}
180 exceptionState.throwTypeError("The provided value is not of type '{{type_strin g}}'"); 189 exceptionState.throwTypeError("The provided value is not of type '{{type_strin g}}'");
181 {% endif %} 190 {% endif %}
182 } 191 }
183 192
184 v8::Local<v8::Value> ToV8(const {{cpp_class}}& impl, v8::Local<v8::Object> creat ionContext, v8::Isolate* isolate) { 193 v8::Local<v8::Value> ToV8(const {{cpp_class}}& impl, v8::Local<v8::Object> creat ionContext, v8::Isolate* isolate) {
185 switch (impl.m_type) { 194 switch (impl.m_type) {
186 case {{cpp_class}}::SpecificTypeNone: 195 case {{cpp_class}}::SpecificTypeNone:
187 {# FIXME: We might want to return undefined in some cases #} 196 {# FIXME: We might want to return undefined in some cases #}
188 return v8::Null(isolate); 197 return v8::Null(isolate);
189 {% for member in members %} 198 {% for member in members %}
190 case {{cpp_class}}::{{member.specific_type_enum}}: 199 case {{cpp_class}}::{{member.specific_type_enum}}:
191 return {{member.cpp_value_to_v8_value}}; 200 return {{member.cpp_value_to_v8_value}};
192 {% endfor %} 201 {% endfor %}
193 default: 202 default:
194 NOTREACHED(); 203 NOTREACHED();
195 } 204 }
196 return v8::Local<v8::Value>(); 205 return v8::Local<v8::Value>();
197 } 206 }
198 207
199 {{cpp_class}} NativeValueTraits<{{cpp_class}}>::nativeValue(v8::Isolate* isolate , v8::Local<v8::Value> value, ExceptionState& exceptionState) { 208 {{cpp_class}} NativeValueTraits<{{cpp_class}}>::nativeValue(v8::Isolate* isolate , v8::Local<v8::Value> value, ExceptionState& exceptionState) {
200 {{cpp_class}} impl; 209 {{cpp_class}} impl;
201 {{v8_class}}::toImpl(isolate, value, impl, UnionTypeConversionMode::NotNullabl e, exceptionState); 210 {{v8_class}}::toImpl(isolate, value, impl, UnionTypeConversionMode::NotNullabl e, exceptionState);
202 return impl; 211 return impl;
203 } 212 }
204 213
205 } // namespace blink 214 } // namespace blink
206 215
207 {% endfilter %}{# format_blink_cpp_source_code #} 216 {% endfilter %}{# format_blink_cpp_source_code #}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698