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

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

Issue 2329463004: ABANDONED CL: Changes needed to make things compile after running rewrite_to_chrome_style tool. (Closed)
Patch Set: More fixes - things build fine at this point. Created 3 years, 8 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 18 matching lines...) Expand all
29 {{member.rvalue_cpp_type}} {{cpp_class}}::getAs{{member.type_name}}() const { 29 {{member.rvalue_cpp_type}} {{cpp_class}}::getAs{{member.type_name}}() const {
30 DCHECK(is{{member.type_name}}()); 30 DCHECK(is{{member.type_name}}());
31 return m_{{member.cpp_name}}; 31 return m_{{member.cpp_name}};
32 } 32 }
33 33
34 void {{cpp_class}}::set{{member.type_name}}({{member.rvalue_cpp_type}} value) { 34 void {{cpp_class}}::set{{member.type_name}}({{member.rvalue_cpp_type}} value) {
35 DCHECK(isNull()); 35 DCHECK(isNull());
36 {% if member.enum_values %} 36 {% if member.enum_values %}
37 NonThrowableExceptionState exceptionState; 37 NonThrowableExceptionState exceptionState;
38 {{declare_enum_validation_variable(member.enum_values) | indent(2)}} 38 {{declare_enum_validation_variable(member.enum_values) | indent(2)}}
39 if (!isValidEnum(value, validValues, WTF_ARRAY_LENGTH(validValues), "{{member. type_name}}", exceptionState)) { 39 if (!IsValidEnum(value, validValues, WTF_ARRAY_LENGTH(validValues), "{{member. type_name}}", exceptionState)) {
40 NOTREACHED(); 40 NOTREACHED();
41 return; 41 return;
42 } 42 }
43 {% endif %} 43 {% endif %}
44 m_{{member.cpp_name}} = value; 44 m_{{member.cpp_name}} = value;
45 m_type = {{member.specific_type_enum}}; 45 m_type = {{member.specific_type_enum}};
46 } 46 }
47 47
48 {{cpp_class}} {{cpp_class}}::from{{member.type_name}}({{member.rvalue_cpp_type}} value) { 48 {{cpp_class}} {{cpp_class}}::from{{member.type_name}}({{member.rvalue_cpp_type}} value) {
49 {{cpp_class}} container; 49 {{cpp_class}} container;
50 container.set{{member.type_name}}(value); 50 container.set{{member.type_name}}(value);
51 return container; 51 return container;
52 } 52 }
53 53
54 {% endfor %} 54 {% endfor %}
55 {{cpp_class}}::{{cpp_class}}(const {{cpp_class}}&) = default; 55 {{cpp_class}}::{{cpp_class}}(const {{cpp_class}}&) = default;
56 {{cpp_class}}::~{{cpp_class}}() = default; 56 {{cpp_class}}::~{{cpp_class}}() = default;
57 {{cpp_class}}& {{cpp_class}}::operator=(const {{cpp_class}}&) = default; 57 {{cpp_class}}& {{cpp_class}}::operator=(const {{cpp_class}}&) = default;
58 58
59 DEFINE_TRACE({{cpp_class}}) { 59 DEFINE_TRACE({{cpp_class}}) {
60 {% for member in members if member.is_traceable %} 60 {% for member in members if member.is_traceable %}
61 visitor->trace(m_{{member.cpp_name}}); 61 visitor->Trace(m_{{member.cpp_name}});
62 {% endfor %} 62 {% endfor %}
63 } 63 }
64 64
65 void {{v8_class}}::toImpl(v8::Isolate* isolate, v8::Local<v8::Value> v8Value, {{ cpp_class}}& impl, UnionTypeConversionMode conversionMode, ExceptionState& excep tionState) { 65 void {{v8_class}}::toImpl(v8::Isolate* isolate, v8::Local<v8::Value> v8Value, {{ cpp_class}}& impl, UnionTypeConversionMode conversionMode, ExceptionState& excep tionState) {
66 if (v8Value.IsEmpty()) 66 if (v8Value.IsEmpty())
67 return; 67 return;
68 68
69 {# The numbers in the following comments refer to the steps described in 69 {# The numbers in the following comments refer to the steps described in
70 http://heycam.github.io/webidl/#es-union #} 70 http://heycam.github.io/webidl/#es-union #}
71 {# 1. null or undefined #} 71 {# 1. null or undefined #}
72 if (conversionMode == UnionTypeConversionMode::Nullable && isUndefinedOrNull(v 8Value)) 72 if (conversionMode == UnionTypeConversionMode::kNullable && IsUndefinedOrNull( v8Value))
73 return; 73 return;
74 74
75 {% if dictionary_type %} 75 {% if dictionary_type %}
76 {# 3. Dictionaries for null or undefined #} 76 {# 3. Dictionaries for null or undefined #}
77 if (isUndefinedOrNull(v8Value)) { 77 if (IsUndefinedOrNull(v8Value)) {
78 {{v8_value_to_local_cpp_value(dictionary_type) | indent}} 78 {{v8_value_to_local_cpp_value(dictionary_type) | indent}}
79 impl.set{{dictionary_type.type_name}}(cppValue); 79 impl.set{{dictionary_type.type_name}}(cppValue);
80 return; 80 return;
81 } 81 }
82 82
83 {% endif %} 83 {% endif %}
84 {# 4. Platform objects (interfaces) #} 84 {# 4. Platform objects (interfaces) #}
85 {% for interface in interface_types %} 85 {% for interface in interface_types %}
86 {{assign_and_return_if_hasinstance(interface) | indent(2)}} 86 {{assign_and_return_if_hasinstance(interface) | indent(2)}}
87 87
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 if (v8Value->IsObject()) { 123 if (v8Value->IsObject()) {
124 {{v8_value_to_local_cpp_value(record_type) | indent}} 124 {{v8_value_to_local_cpp_value(record_type) | indent}}
125 impl.set{{record_type.type_name}}(cppValue); 125 impl.set{{record_type.type_name}}(cppValue);
126 return; 126 return;
127 } 127 }
128 128
129 {% endif %} 129 {% endif %}
130 {# TODO(bashi): Support 11.5 Callback interface when we need it #} 130 {# TODO(bashi): Support 11.5 Callback interface when we need it #}
131 {# 11.6. Objects #} 131 {# 11.6. Objects #}
132 {% if object_type %} 132 {% if object_type %}
133 if (isUndefinedOrNull(v8Value) || v8Value->IsObject()) { 133 if (IsUndefinedOrNull(v8Value) || v8Value->IsObject()) {
134 {{v8_value_to_local_cpp_value(object_type) | indent}} 134 {{v8_value_to_local_cpp_value(object_type) | indent}}
135 impl.set{{object_type.type_name}}(cppValue); 135 impl.set{{object_type.type_name}}(cppValue);
136 return; 136 return;
137 } 137 }
138 138
139 {% endif %} 139 {% endif %}
140 {# 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
141 we have fallback conversions. (step 16 and 17) #} 141 we have fallback conversions. (step 16 and 17) #}
142 {% if boolean_type %} 142 {% if boolean_type %}
143 {# 12. Boolean #} 143 {# 12. Boolean #}
(...skipping 11 matching lines...) Expand all
155 return; 155 return;
156 } 156 }
157 157
158 {% endif %} 158 {% endif %}
159 {% if string_type %} 159 {% if string_type %}
160 {# 14. String #} 160 {# 14. String #}
161 { 161 {
162 {{v8_value_to_local_cpp_value(string_type) | indent}} 162 {{v8_value_to_local_cpp_value(string_type) | indent}}
163 {% if string_type.enum_values %} 163 {% if string_type.enum_values %}
164 {{declare_enum_validation_variable(string_type.enum_values) | indent}} 164 {{declare_enum_validation_variable(string_type.enum_values) | indent}}
165 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))
166 return; 166 return;
167 {% endif %} 167 {% endif %}
168 impl.set{{string_type.type_name}}(cppValue); 168 impl.set{{string_type.type_name}}(cppValue);
169 return; 169 return;
170 } 170 }
171 171
172 {# 15. Number (fallback) #} 172 {# 15. Number (fallback) #}
173 {% elif numeric_type %} 173 {% elif numeric_type %}
174 { 174 {
175 {{v8_value_to_local_cpp_value(numeric_type) | indent}} 175 {{v8_value_to_local_cpp_value(numeric_type) | indent}}
176 impl.set{{numeric_type.type_name}}(cppValue); 176 impl.set{{numeric_type.type_name}}(cppValue);
177 return; 177 return;
178 } 178 }
179 179
180 {# 16. Boolean (fallback) #} 180 {# 16. Boolean (fallback) #}
181 {% elif boolean_type %} 181 {% elif boolean_type %}
182 { 182 {
183 impl.setBoolean(v8Value->BooleanValue()); 183 impl.setBoolean(v8Value->BooleanValue());
184 return; 184 return;
185 } 185 }
186 186
187 {% else %} 187 {% else %}
188 {# 17. TypeError #} 188 {# 17. TypeError #}
189 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}}'");
190 {% endif %} 190 {% endif %}
191 } 191 }
192 192
193 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) {
194 switch (impl.m_type) { 194 switch (impl.m_type) {
195 case {{cpp_class}}::SpecificTypeNone: 195 case {{cpp_class}}::SpecificTypeNone:
196 {# FIXME: We might want to return undefined in some cases #} 196 {# FIXME: We might want to return undefined in some cases #}
197 return v8::Null(isolate); 197 return v8::Null(isolate);
198 {% for member in members %} 198 {% for member in members %}
199 case {{cpp_class}}::{{member.specific_type_enum}}: 199 case {{cpp_class}}::{{member.specific_type_enum}}:
200 return {{member.cpp_value_to_v8_value}}; 200 return {{member.cpp_value_to_v8_value}};
201 {% endfor %} 201 {% endfor %}
202 default: 202 default:
203 NOTREACHED(); 203 NOTREACHED();
204 } 204 }
205 return v8::Local<v8::Value>(); 205 return v8::Local<v8::Value>();
206 } 206 }
207 207
208 {{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) {
209 {{cpp_class}} impl; 209 {{cpp_class}} impl;
210 {{v8_class}}::toImpl(isolate, value, impl, UnionTypeConversionMode::NotNullabl e, exceptionState); 210 {{v8_class}}::toImpl(isolate, value, impl, UnionTypeConversionMode::kNotNullab le, exceptionState);
211 return impl; 211 return impl;
212 } 212 }
213 213
214 } // namespace blink 214 } // namespace blink
215 215
216 {% endfilter %}{# format_blink_cpp_source_code #} 216 {% endfilter %}{# format_blink_cpp_source_code #}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698