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

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: Rebasing the fixes... Created 3 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
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 26 matching lines...) Expand all
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 {# TODO(bashi): Support 12.4 Callback interface when we need it #}
122 {# 12.5. Objects #} 122 {# 12.5. Objects #}
123 {% if object_type %} 123 {% if object_type %}
124 if (isUndefinedOrNull(v8Value) || v8Value->IsObject()) { 124 if (IsUndefinedOrNull(v8Value) || v8Value->IsObject()) {
125 {{v8_value_to_local_cpp_value(object_type) | indent}} 125 {{v8_value_to_local_cpp_value(object_type) | indent}}
126 impl.set{{object_type.type_name}}(cppValue); 126 impl.set{{object_type.type_name}}(cppValue);
127 return; 127 return;
128 } 128 }
129 129
130 {% endif %} 130 {% endif %}
131 {# FIXME: In some cases, we can omit boolean and numeric type checks because 131 {# FIXME: In some cases, we can omit boolean and numeric type checks because
132 we have fallback conversions. (step 16 and 17) #} 132 we have fallback conversions. (step 16 and 17) #}
133 {% if boolean_type %} 133 {% if boolean_type %}
134 {# 13. Boolean #} 134 {# 13. Boolean #}
(...skipping 11 matching lines...) Expand all
146 return; 146 return;
147 } 147 }
148 148
149 {% endif %} 149 {% endif %}
150 {% if string_type %} 150 {% if string_type %}
151 {# 15. String #} 151 {# 15. String #}
152 { 152 {
153 {{v8_value_to_local_cpp_value(string_type) | indent}} 153 {{v8_value_to_local_cpp_value(string_type) | indent}}
154 {% if string_type.enum_values %} 154 {% if string_type.enum_values %}
155 {{declare_enum_validation_variable(string_type.enum_values) | indent}} 155 {{declare_enum_validation_variable(string_type.enum_values) | indent}}
156 if (!isValidEnum(cppValue, validValues, WTF_ARRAY_LENGTH(validValues), "{{st ring_type.type_name}}", exceptionState)) 156 if (!IsValidEnum(cppValue, validValues, WTF_ARRAY_LENGTH(validValues), "{{st ring_type.type_name}}", exceptionState))
157 return; 157 return;
158 {% endif %} 158 {% endif %}
159 impl.set{{string_type.type_name}}(cppValue); 159 impl.set{{string_type.type_name}}(cppValue);
160 return; 160 return;
161 } 161 }
162 162
163 {# 16. Number (fallback) #} 163 {# 16. Number (fallback) #}
164 {% elif numeric_type %} 164 {% elif numeric_type %}
165 { 165 {
166 {{v8_value_to_local_cpp_value(numeric_type) | indent}} 166 {{v8_value_to_local_cpp_value(numeric_type) | indent}}
167 impl.set{{numeric_type.type_name}}(cppValue); 167 impl.set{{numeric_type.type_name}}(cppValue);
168 return; 168 return;
169 } 169 }
170 170
171 {# 17. Boolean (fallback) #} 171 {# 17. Boolean (fallback) #}
172 {% elif boolean_type %} 172 {% elif boolean_type %}
173 { 173 {
174 impl.setBoolean(v8Value->BooleanValue()); 174 impl.setBoolean(v8Value->BooleanValue());
175 return; 175 return;
176 } 176 }
177 177
178 {% else %} 178 {% else %}
179 {# 18. TypeError #} 179 {# 18. TypeError #}
180 exceptionState.throwTypeError("The provided value is not of type '{{type_strin g}}'"); 180 exceptionState.ThrowTypeError("The provided value is not of type '{{type_strin g}}'");
181 {% endif %} 181 {% endif %}
182 } 182 }
183 183
184 v8::Local<v8::Value> ToV8(const {{cpp_class}}& impl, v8::Local<v8::Object> creat ionContext, v8::Isolate* isolate) { 184 v8::Local<v8::Value> ToV8(const {{cpp_class}}& impl, v8::Local<v8::Object> creat ionContext, v8::Isolate* isolate) {
185 switch (impl.m_type) { 185 switch (impl.m_type) {
186 case {{cpp_class}}::SpecificTypeNone: 186 case {{cpp_class}}::SpecificTypeNone:
187 {# FIXME: We might want to return undefined in some cases #} 187 {# FIXME: We might want to return undefined in some cases #}
188 return v8::Null(isolate); 188 return v8::Null(isolate);
189 {% for member in members %} 189 {% for member in members %}
190 case {{cpp_class}}::{{member.specific_type_enum}}: 190 case {{cpp_class}}::{{member.specific_type_enum}}:
191 return {{member.cpp_value_to_v8_value}}; 191 return {{member.cpp_value_to_v8_value}};
192 {% endfor %} 192 {% endfor %}
193 default: 193 default:
194 NOTREACHED(); 194 NOTREACHED();
195 } 195 }
196 return v8::Local<v8::Value>(); 196 return v8::Local<v8::Value>();
197 } 197 }
198 198
199 {{cpp_class}} NativeValueTraits<{{cpp_class}}>::nativeValue(v8::Isolate* isolate , v8::Local<v8::Value> value, ExceptionState& exceptionState) { 199 {{cpp_class}} NativeValueTraits<{{cpp_class}}>::NativeValue(v8::Isolate* isolate , v8::Local<v8::Value> value, ExceptionState& exceptionState) {
200 {{cpp_class}} impl; 200 {{cpp_class}} impl;
201 {{v8_class}}::toImpl(isolate, value, impl, UnionTypeConversionMode::NotNullabl e, exceptionState); 201 {{v8_class}}::toImpl(isolate, value, impl, UnionTypeConversionMode::kNotNullab le, exceptionState);
202 return impl; 202 return impl;
203 } 203 }
204 204
205 } // namespace blink 205 } // namespace blink
206 206
207 {% endfilter %}{# format_blink_cpp_source_code #} 207 {% endfilter %}{# format_blink_cpp_source_code #}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698