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

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

Issue 946973005: IDL: Drop value conversion (V8 -> C++) macros from generated code (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: address comments 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "{{header_filename}}"
9 9
10 {% from 'conversions.cpp' import v8_value_to_local_cpp_value %}
10 {% macro assign_and_return_if_hasinstance(member) %} 11 {% macro assign_and_return_if_hasinstance(member) %}
11 if (V8{{member.type_name}}::hasInstance(v8Value, isolate)) { 12 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)); 13 {{member.cpp_local_type}} cppValue = V8{{member.type_name}}::toImpl(v8::Loca l<v8::Object>::Cast(v8Value));
13 impl.set{{member.type_name}}(cppValue); 14 impl.set{{member.type_name}}(cppValue);
14 return; 15 return;
15 } 16 }
16 {% endmacro %} 17 {% endmacro %}
17 {% for filename in cpp_includes %} 18 {% for filename in cpp_includes %}
18 #include "{{filename}}" 19 #include "{{filename}}"
19 {% endfor %} 20 {% endfor %}
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 {# FIXME: Individual typed arrays (e.g. Uint8Array) aren't supported yet. #} 88 {# FIXME: Individual typed arrays (e.g. Uint8Array) aren't supported yet. #}
88 {% if container.array_buffer_view_type %} 89 {% if container.array_buffer_view_type %}
89 {{assign_and_return_if_hasinstance(container.array_buffer_view_type) | inden t}} 90 {{assign_and_return_if_hasinstance(container.array_buffer_view_type) | inden t}}
90 91
91 {% endif %} 92 {% endif %}
92 {% if container.dictionary_type %} 93 {% if container.dictionary_type %}
93 {# 12. Dictionaries #} 94 {# 12. Dictionaries #}
94 {# FIXME: This should also check "object but not Date or RegExp". Add checks 95 {# FIXME: This should also check "object but not Date or RegExp". Add checks
95 when we implement conversions for Date and RegExp. #} 96 when we implement conversions for Date and RegExp. #}
96 if (isUndefinedOrNull(v8Value) || v8Value->IsObject()) { 97 if (isUndefinedOrNull(v8Value) || v8Value->IsObject()) {
97 {% if container.dictionary_type.type_name != 'Dictionary' %} 98 {{v8_value_to_local_cpp_value(container.dictionary_type) | indent(8)}}
98 {{container.dictionary_type.cpp_local_type}} cppValue;
99 {% endif %}
100 {{container.dictionary_type.v8_value_to_local_cpp_value}};
101 impl.set{{container.dictionary_type.type_name}}(cppValue); 99 impl.set{{container.dictionary_type.type_name}}(cppValue);
102 return; 100 return;
103 } 101 }
104 102
105 {% endif %} 103 {% endif %}
106 {% if container.array_or_sequence_type %} 104 {% if container.array_or_sequence_type %}
107 {# 13. Arrays/Sequences #} 105 {# 13. Arrays/Sequences #}
108 {# FIXME: This should also check "object but not Date or RegExp". Add checks 106 {# FIXME: This should also check "object but not Date or RegExp". Add checks
109 when we implement conversions for Date and RegExp. #} 107 when we implement conversions for Date and RegExp. #}
110 {# FIXME: Should check for sequences too, not just Array instances. #} 108 {# FIXME: Should check for sequences too, not just Array instances. #}
111 if (v8Value->IsArray()) { 109 if (v8Value->IsArray()) {
112 {{container.array_or_sequence_type.v8_value_to_local_cpp_value}}; 110 {{v8_value_to_local_cpp_value(container.array_or_sequence_type) | indent (8)}}
113 impl.set{{container.array_or_sequence_type.type_name}}(cppValue); 111 impl.set{{container.array_or_sequence_type.type_name}}(cppValue);
114 return; 112 return;
115 } 113 }
116 114
117 {% endif %} 115 {% endif %}
118 {# FIXME: In some cases, we can omit boolean and numeric type checks because 116 {# FIXME: In some cases, we can omit boolean and numeric type checks because
119 we have fallback conversions. (step 17 and 18) #} 117 we have fallback conversions. (step 17 and 18) #}
120 {% if container.boolean_type %} 118 {% if container.boolean_type %}
121 {# 14. Boolean #} 119 {# 14. Boolean #}
122 if (v8Value->IsBoolean()) { 120 if (v8Value->IsBoolean()) {
123 impl.setBoolean(v8Value->ToBoolean()->Value()); 121 impl.setBoolean(v8Value->ToBoolean()->Value());
124 return; 122 return;
125 } 123 }
126 124
127 {% endif %} 125 {% endif %}
128 {% if container.numeric_type %} 126 {% if container.numeric_type %}
129 {# 15. Number #} 127 {# 15. Number #}
130 if (v8Value->IsNumber()) { 128 if (v8Value->IsNumber()) {
131 {{container.numeric_type.v8_value_to_local_cpp_value}}; 129 {{v8_value_to_local_cpp_value(container.numeric_type) | indent(8)}}
132 impl.set{{container.numeric_type.type_name}}(cppValue); 130 impl.set{{container.numeric_type.type_name}}(cppValue);
133 return; 131 return;
134 } 132 }
135 133
136 {% endif %} 134 {% endif %}
137 {% if container.string_type %} 135 {% if container.string_type %}
138 {# 16. String #} 136 {# 16. String #}
139 { 137 {
140 {{container.string_type.v8_value_to_local_cpp_value}}; 138 {{v8_value_to_local_cpp_value(container.string_type) | indent(8)}}
141 {% if container.string_type.enum_validation_expression %} 139 {% if container.string_type.enum_validation_expression %}
142 String string = cppValue; 140 String string = cppValue;
143 if (!({{container.string_type.enum_validation_expression}})) { 141 if (!({{container.string_type.enum_validation_expression}})) {
144 exceptionState.throwTypeError("'" + string + "' is not a valid enum value."); 142 exceptionState.throwTypeError("'" + string + "' is not a valid enum value.");
145 return; 143 return;
146 } 144 }
147 {% endif %} 145 {% endif %}
148 impl.set{{container.string_type.type_name}}(cppValue); 146 impl.set{{container.string_type.type_name}}(cppValue);
149 return; 147 return;
150 } 148 }
151 149
152 {# 17. Number (fallback) #} 150 {# 17. Number (fallback) #}
153 {% elif container.numeric_type %} 151 {% elif container.numeric_type %}
154 { 152 {
155 {{container.numeric_type.v8_value_to_local_cpp_value}}; 153 {{v8_value_to_local_cpp_value(container.numeric_type) | indent(8)}}
156 impl.set{{container.numeric_type.type_name}}(cppValue); 154 impl.set{{container.numeric_type.type_name}}(cppValue);
157 return; 155 return;
158 } 156 }
159 157
160 {# 18. Boolean (fallback) #} 158 {# 18. Boolean (fallback) #}
161 {% elif container.boolean_type %} 159 {% elif container.boolean_type %}
162 { 160 {
163 impl.setBoolean(v8Value->ToBoolean()->Value()); 161 impl.setBoolean(v8Value->BooleanValue());
164 return; 162 return;
165 } 163 }
166 164
167 {% else %} 165 {% else %}
168 {# 19. TypeError #} 166 {# 19. TypeError #}
169 exceptionState.throwTypeError("The provided value is not of type '{{containe r.type_string}}'"); 167 exceptionState.throwTypeError("The provided value is not of type '{{containe r.type_string}}'");
170 {% endif %} 168 {% endif %}
171 } 169 }
172 170
173 v8::Local<v8::Value> toV8(const {{container.cpp_class}}& impl, v8::Local<v8::Obj ect> creationContext, v8::Isolate* isolate) 171 v8::Local<v8::Value> toV8(const {{container.cpp_class}}& impl, v8::Local<v8::Obj ect> creationContext, v8::Isolate* isolate)
(...skipping 14 matching lines...) Expand all
188 186
189 {{container.cpp_class}} NativeValueTraits<{{container.cpp_class}}>::nativeValue( const v8::Local<v8::Value>& value, v8::Isolate* isolate, ExceptionState& excepti onState) 187 {{container.cpp_class}} NativeValueTraits<{{container.cpp_class}}>::nativeValue( const v8::Local<v8::Value>& value, v8::Isolate* isolate, ExceptionState& excepti onState)
190 { 188 {
191 {{container.cpp_class}} impl; 189 {{container.cpp_class}} impl;
192 V8{{container.cpp_class}}::toImpl(isolate, value, impl, exceptionState); 190 V8{{container.cpp_class}}::toImpl(isolate, value, impl, exceptionState);
193 return impl; 191 return impl;
194 } 192 }
195 193
196 {% endfor %} 194 {% endfor %}
197 } // namespace blink 195 } // namespace blink
OLDNEW
« no previous file with comments | « Source/bindings/templates/templates.gypi ('k') | Source/bindings/tests/results/core/UnionTypesCore.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698