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

Side by Side Diff: Source/bindings/templates/methods.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: 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 {##############################################################################} 1 {##############################################################################}
2 {% macro generate_method(method, world_suffix) %} 2 {% macro generate_method(method, world_suffix) %}
3 {% filter conditional(method.conditional_string) %} 3 {% filter conditional(method.conditional_string) %}
4 {% if method.returns_promise and method.has_exception_state %}
5 static void {{method.name}}{{method.overload_index}}Method{{world_suffix}}Promis e(const v8::FunctionCallbackInfo<v8::Value>& info, ExceptionState& exceptionStat e)
6 {% else %}
4 static void {{method.name}}{{method.overload_index}}Method{{world_suffix}}(const v8::FunctionCallbackInfo<v8::Value>& info) 7 static void {{method.name}}{{method.overload_index}}Method{{world_suffix}}(const v8::FunctionCallbackInfo<v8::Value>& info)
8 {% endif %}
5 { 9 {
6 {# Local variables #} 10 {# Local variables #}
7 {% if method.has_exception_state %} 11 {% if method.has_exception_state and not method.returns_promise %}
8 ExceptionState exceptionState(ExceptionState::ExecutionContext, "{{method.na me}}", "{{interface_name}}", info.Holder(), info.GetIsolate()); 12 ExceptionState exceptionState(ExceptionState::ExecutionContext, "{{method.na me}}", "{{interface_name}}", info.Holder(), info.GetIsolate());
9 {% endif %} 13 {% endif %}
10 {# Overloaded methods have length checked during overload resolution #} 14 {# Overloaded methods have length checked during overload resolution #}
11 {% if method.number_of_required_arguments and not method.overload_index %} 15 {% if method.number_of_required_arguments and not method.overload_index %}
12 if (UNLIKELY(info.Length() < {{method.number_of_required_arguments}})) { 16 if (UNLIKELY(info.Length() < {{method.number_of_required_arguments}})) {
13 {{throw_minimum_arity_type_error(method, method.number_of_required_argum ents) | indent(8)}} 17 {{throw_minimum_arity_type_error(method, method.number_of_required_argum ents) | indent(8)}}
14 return;
15 } 18 }
16 {% endif %} 19 {% endif %}
17 {% if not method.is_static %} 20 {% if not method.is_static %}
18 {{cpp_class}}* impl = {{v8_class}}::toImpl(info.Holder()); 21 {{cpp_class}}* impl = {{v8_class}}::toImpl(info.Holder());
19 {% endif %} 22 {% endif %}
20 {% if method.is_custom_element_callbacks %} 23 {% if method.is_custom_element_callbacks %}
21 CustomElementProcessingStack::CallbackDeliveryScope deliveryScope; 24 CustomElementProcessingStack::CallbackDeliveryScope deliveryScope;
22 {% endif %} 25 {% endif %}
23 {# Security checks #} 26 {# Security checks #}
24 {% if method.is_check_security_for_window %} 27 {% if method.is_check_security_for_window %}
25 if (LocalDOMWindow* window = impl->toDOMWindow()) { 28 if (LocalDOMWindow* window = impl->toDOMWindow()) {
26 if (!BindingSecurity::shouldAllowAccessToFrame(info.GetIsolate(), window ->frame(), exceptionState)) { 29 if (!BindingSecurity::shouldAllowAccessToFrame(info.GetIsolate(), window ->frame(), exceptionState)) {
27 {{throw_from_exception_state(method)}}; 30 {{throw_from_exception_state(method) | indent(12)}}
28 return;
29 } 31 }
30 if (!window->document()) 32 if (!window->document())
31 return; 33 return;
32 } 34 }
33 {% elif method.is_check_security_for_frame %} 35 {% elif method.is_check_security_for_frame %}
34 if (!BindingSecurity::shouldAllowAccessToFrame(info.GetIsolate(), impl->fram e(), exceptionState)) { 36 if (!BindingSecurity::shouldAllowAccessToFrame(info.GetIsolate(), impl->fram e(), exceptionState)) {
35 {{throw_from_exception_state(method)}}; 37 {{throw_from_exception_state(method) | indent(8)}}
36 return;
37 } 38 }
38 {% endif %} 39 {% endif %}
39 {% if method.is_check_security_for_node %} 40 {% if method.is_check_security_for_node %}
40 if (!BindingSecurity::shouldAllowAccessToNode(info.GetIsolate(), impl->{{met hod.name}}(exceptionState), exceptionState)) { 41 if (!BindingSecurity::shouldAllowAccessToNode(info.GetIsolate(), impl->{{met hod.name}}(exceptionState), exceptionState)) {
41 v8SetReturnValueNull(info); 42 v8SetReturnValueNull(info);
42 {{throw_from_exception_state(method)}}; 43 {{throw_from_exception_state(method) | indent(8)}}
43 return;
44 } 44 }
45 {% endif %} 45 {% endif %}
46 {# Call method #} 46 {# Call method #}
47 {% if method.arguments %} 47 {% if method.arguments %}
48 {{generate_arguments(method, world_suffix) | indent}} 48 {{generate_arguments(method, world_suffix) | indent}}
49 {% endif %} 49 {% endif %}
50 {% if world_suffix %} 50 {% if world_suffix %}
51 {{cpp_method_call(method, method.v8_set_return_value_for_main_world, method. cpp_value) | indent}} 51 {{cpp_method_call(method, method.v8_set_return_value_for_main_world, method. cpp_value) | indent}}
52 {% else %} 52 {% else %}
53 {{cpp_method_call(method, method.v8_set_return_value, method.cpp_value) | in dent}} 53 {{cpp_method_call(method, method.v8_set_return_value, method.cpp_value) | in dent}}
54 {% endif %} 54 {% endif %}
55 } 55 }
56 {% if method.returns_promise and method.has_exception_state %}
57
58 static void {{method.name}}{{method.overload_index}}Method{{world_suffix}}(const v8::FunctionCallbackInfo<v8::Value>& info)
59 {
60 ExceptionState exceptionState(ExceptionState::ExecutionContext, "{{method.na me}}", "{{interface_name}}", info.Holder(), info.GetIsolate());
61 {{method.name}}{{method.overload_index}}Method{{world_suffix}}Promise(info, exceptionState);
62 if (exceptionState.hadException())
63 v8SetReturnValue(info, exceptionState.reject(ScriptState::current(info.G etIsolate())).v8Value());
64 }
65 {% endif %}
56 {% endfilter %} 66 {% endfilter %}
57 {% endmacro %} 67 {% endmacro %}
58 68
59 69
60 {######################################} 70 {######################################}
61 {% macro generate_arguments(method, world_suffix) %} 71 {% macro generate_arguments(method, world_suffix) %}
62 {% for argument in method.arguments %} 72 {% for argument in method.arguments %}
63 {{generate_argument_var_declaration(argument)}}; 73 {{generate_argument_var_declaration(argument)}};
64 {% endfor %} 74 {% endfor %}
65 { 75 {
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 {% endif %}{# method.name #} 129 {% endif %}{# method.name #}
120 {% else %}{# argument.idl_type == 'EventListener' #} 130 {% else %}{# argument.idl_type == 'EventListener' #}
121 {# Callback functions must be functions: 131 {# Callback functions must be functions:
122 http://www.w3.org/TR/WebIDL/#es-callback-function #} 132 http://www.w3.org/TR/WebIDL/#es-callback-function #}
123 {% if argument.is_optional %} 133 {% if argument.is_optional %}
124 if (!isUndefinedOrNull(info[{{argument.index}}])) { 134 if (!isUndefinedOrNull(info[{{argument.index}}])) {
125 if (!info[{{argument.index}}]->IsFunction()) { 135 if (!info[{{argument.index}}]->IsFunction()) {
126 {{throw_type_error(method, 136 {{throw_type_error(method,
127 '"The callback provided as parameter %s is not a function."' % 137 '"The callback provided as parameter %s is not a function."' %
128 (argument.index + 1)) | indent(8)}} 138 (argument.index + 1)) | indent(8)}}
129 return;
130 } 139 }
131 {{argument.name}} = V8{{argument.idl_type}}::create(v8::Local<v8::Function>: :Cast(info[{{argument.index}}]), ScriptState::current(info.GetIsolate())); 140 {{argument.name}} = V8{{argument.idl_type}}::create(v8::Local<v8::Function>: :Cast(info[{{argument.index}}]), ScriptState::current(info.GetIsolate()));
132 } else { 141 } else {
133 {{argument.name}} = nullptr; 142 {{argument.name}} = nullptr;
134 } 143 }
135 {% else %}{# argument.is_optional #} 144 {% else %}{# argument.is_optional #}
136 if (info.Length() <= {{argument.index}} || !{% if argument.is_nullable %}(info[{ {argument.index}}]->IsFunction() || info[{{argument.index}}]->IsNull()){% else % }info[{{argument.index}}]->IsFunction(){% endif %}) { 145 if (info.Length() <= {{argument.index}} || !{% if argument.is_nullable %}(info[{ {argument.index}}]->IsFunction() || info[{{argument.index}}]->IsNull()){% else % }info[{{argument.index}}]->IsFunction(){% endif %}) {
137 {{throw_type_error(method, 146 {{throw_type_error(method,
138 '"The callback provided as parameter %s is not a function."' % 147 '"The callback provided as parameter %s is not a function."' %
139 (argument.index + 1)) | indent }} 148 (argument.index + 1)) | indent}}
140 return;
141 } 149 }
142 {{argument.name}} = {% if argument.is_nullable %}info[{{argument.index}}]->IsNul l() ? nullptr : {% endif %}V8{{argument.idl_type}}::create(v8::Local<v8::Functio n>::Cast(info[{{argument.index}}]), ScriptState::current(info.GetIsolate())); 150 {{argument.name}} = {% if argument.is_nullable %}info[{{argument.index}}]->IsNul l() ? nullptr : {% endif %}V8{{argument.idl_type}}::create(v8::Local<v8::Functio n>::Cast(info[{{argument.index}}]), ScriptState::current(info.GetIsolate()));
143 {% endif %}{# argument.is_optional #} 151 {% endif %}{# argument.is_optional #}
144 {% endif %}{# argument.idl_type == 'EventListener' #} 152 {% endif %}{# argument.idl_type == 'EventListener' #}
145 {% elif argument.is_callback_function %} 153 {% elif argument.is_callback_function %}
146 if (!info[{{argument.index}}]->IsFunction(){% if argument.is_nullable %} && !inf o[{{argument.index}}]->IsNull(){% endif %}) { 154 if (!info[{{argument.index}}]->IsFunction(){% if argument.is_nullable %} && !inf o[{{argument.index}}]->IsNull(){% endif %}) {
147 {{throw_type_error(method, 155 {{throw_type_error(method,
148 '"The callback provided as parameter %s is not a function."' % 156 '"The callback provided as parameter %s is not a function."' %
149 (argument.index + 1)) | indent(8)}} 157 (argument.index + 1)) | indent}}
150 return;
151 } 158 }
152 {{argument.v8_value_to_local_cpp_value}}; 159 {{argument.v8_value_to_local_cpp_value}};
153 {% elif argument.is_variadic_wrapper_type %} 160 {% elif argument.is_variadic_wrapper_type %}
154 for (int i = {{argument.index}}; i < info.Length(); ++i) { 161 for (int i = {{argument.index}}; i < info.Length(); ++i) {
155 if (!V8{{argument.idl_type}}::hasInstance(info[i], info.GetIsolate())) { 162 if (!V8{{argument.idl_type}}::hasInstance(info[i], info.GetIsolate())) {
156 {{throw_type_error(method, '"parameter %s is not of type \'%s\'."' % 163 {{throw_type_error(method, '"parameter %s is not of type \'%s\'."' %
157 (argument.index + 1, argument.idl_type)) | in dent(8)}} 164 (argument.index + 1, argument.idl_type)) | in dent(8)}}
158 return;
159 } 165 }
160 {{argument.name}}.append(V8{{argument.idl_type}}::toImpl(v8::Local<v8::Objec t>::Cast(info[i]))); 166 {{argument.name}}.append(V8{{argument.idl_type}}::toImpl(v8::Local<v8::Objec t>::Cast(info[i])));
161 } 167 }
162 {% elif argument.is_dictionary %} 168 {% elif argument.is_dictionary %}
163 {% if not argument.use_permissive_dictionary_conversion %} 169 {% if not argument.use_permissive_dictionary_conversion %}
164 {# Dictionaries must have type Undefined, Null or Object: 170 {# Dictionaries must have type Undefined, Null or Object:
165 http://heycam.github.io/webidl/#es-dictionary #} 171 http://heycam.github.io/webidl/#es-dictionary #}
166 if (!isUndefinedOrNull(info[{{argument.index}}]) && !info[{{argument.index}}]->I sObject()) { 172 if (!isUndefinedOrNull(info[{{argument.index}}]) && !info[{{argument.index}}]->I sObject()) {
167 {{throw_type_error(method, '"parameter %s (\'%s\') is not an object."' % 173 {{throw_type_error(method, '"parameter %s (\'%s\') is not an object."' %
168 (argument.index + 1, argument.name)) | indent}} 174 (argument.index + 1, argument.name)) | indent}}
169 return;
170 } 175 }
171 {% endif %}{# not argument.use_permissive_dictionary_conversion #} 176 {% endif %}{# not argument.use_permissive_dictionary_conversion #}
172 {{argument.v8_value_to_local_cpp_value}}; 177 {{argument.v8_value_to_local_cpp_value}};
173 {% else %}{# argument.is_nullable #} 178 {% else %}{# argument.is_nullable #}
174 {{argument.v8_value_to_local_cpp_value}}; 179 {{argument.v8_value_to_local_cpp_value}};
175 {% endif %}{# argument.is_nullable #} 180 {% endif %}{# argument.is_nullable #}
176 {# Type checking, possibly throw a TypeError, per: 181 {# Type checking, possibly throw a TypeError, per:
177 http://www.w3.org/TR/WebIDL/#es-type-mapping #} 182 http://www.w3.org/TR/WebIDL/#es-type-mapping #}
178 {% if argument.has_type_checking_interface and not argument.is_variadic_wrapper_ type %} 183 {% if argument.has_type_checking_interface and not argument.is_variadic_wrapper_ type %}
179 {# Type checking for wrapper interface types (if interface not implemented, 184 {# Type checking for wrapper interface types (if interface not implemented,
180 throw a TypeError), per http://www.w3.org/TR/WebIDL/#es-interface 185 throw a TypeError), per http://www.w3.org/TR/WebIDL/#es-interface
181 Note: for variadic arguments, the type checking is done for each matched 186 Note: for variadic arguments, the type checking is done for each matched
182 argument instead; see argument.is_variadic_wrapper_type code-path above. #} 187 argument instead; see argument.is_variadic_wrapper_type code-path above. #}
183 if (!{{argument.name}}{% if argument.is_nullable %} && !isUndefinedOrNull(info[{ {argument.index}}]){% endif %}) { 188 if (!{{argument.name}}{% if argument.is_nullable %} && !isUndefinedOrNull(info[{ {argument.index}}]){% endif %}) {
184 {{throw_type_error(method, '"parameter %s is not of type \'%s\'."' % 189 {{throw_type_error(method, '"parameter %s is not of type \'%s\'."' %
185 (argument.index + 1, argument.idl_type)) | indent }} 190 (argument.index + 1, argument.idl_type)) | indent }}
186 return;
187 } 191 }
188 {% elif argument.enum_validation_expression %} 192 {% elif argument.enum_validation_expression %}
189 {# Invalid enum values: http://www.w3.org/TR/WebIDL/#idl-enums #} 193 {# Invalid enum values: http://www.w3.org/TR/WebIDL/#idl-enums #}
190 String string = {{argument.name}}; 194 String string = {{argument.name}};
191 if (!({{argument.enum_validation_expression}})) { 195 if (!({{argument.enum_validation_expression}})) {
192 {{throw_type_error(method, 196 {{throw_type_error(method,
193 '"parameter %s (\'" + string + "\') is not a valid enum value."' % 197 '"parameter %s (\'" + string + "\') is not a valid enum value."' %
194 (argument.index + 1)) | indent}} 198 (argument.index + 1)) | indent}}
195 return;
196 } 199 }
197 {% elif argument.idl_type == 'Promise' %} 200 {% elif argument.idl_type == 'Promise' %}
198 {# We require this for our implementation of promises, though not in spec: 201 {# We require this for our implementation of promises, though not in spec:
199 http://heycam.github.io/webidl/#es-promise #} 202 http://heycam.github.io/webidl/#es-promise #}
200 if (!{{argument.name}}.isUndefinedOrNull() && !{{argument.name}}.isObject()) { 203 if (!{{argument.name}}.isUndefinedOrNull() && !{{argument.name}}.isObject()) {
201 {{throw_type_error(method, '"parameter %s (\'%s\') is not an object."' % 204 {{throw_type_error(method, '"parameter %s (\'%s\') is not an object."' %
202 (argument.index + 1, argument.name)) | indent}} 205 (argument.index + 1, argument.name)) | indent}}
203 return;
204 } 206 }
205 {% endif %} 207 {% endif %}
206 {% endmacro %} 208 {% endmacro %}
207 209
208 210
209 {######################################} 211 {######################################}
210 {% macro cpp_method_call(method, v8_set_return_value, cpp_value) %} 212 {% macro cpp_method_call(method, v8_set_return_value, cpp_value) %}
211 {# Local variables #} 213 {# Local variables #}
212 {% if method.is_call_with_script_state %} 214 {% if method.is_call_with_script_state %}
213 {# [ConstructorCallWith=ScriptState] #} 215 {# [ConstructorCallWith=ScriptState] #}
(...skipping 24 matching lines...) Expand all
238 {{method.cpp_type}} result; 240 {{method.cpp_type}} result;
239 {{cpp_value}}; 241 {{cpp_value}};
240 {% elif method.is_constructor %} 242 {% elif method.is_constructor %}
241 {{method.cpp_type}} impl = {{cpp_value}}; 243 {{method.cpp_type}} impl = {{cpp_value}};
242 {% elif method.use_local_result %} 244 {% elif method.use_local_result %}
243 {{method.cpp_type}} result = {{cpp_value}}; 245 {{method.cpp_type}} result = {{cpp_value}};
244 {% endif %} 246 {% endif %}
245 {# Post-call #} 247 {# Post-call #}
246 {% if method.is_raises_exception %} 248 {% if method.is_raises_exception %}
247 if (exceptionState.hadException()) { 249 if (exceptionState.hadException()) {
248 {{throw_from_exception_state(method)}}; 250 {{throw_from_exception_state(method) | indent}}
249 return;
250 } 251 }
251 {% endif %} 252 {% endif %}
252 {# Set return value #} 253 {# Set return value #}
253 {% if method.is_constructor %} 254 {% if method.is_constructor %}
254 {{generate_constructor_wrapper(method)}} 255 {{generate_constructor_wrapper(method)}}
255 {%- elif v8_set_return_value %} 256 {%- elif v8_set_return_value %}
256 {% if method.is_explicit_nullable %} 257 {% if method.is_explicit_nullable %}
257 if (result.isNull()) 258 if (result.isNull())
258 v8SetReturnValueNull(info); 259 v8SetReturnValueNull(info);
259 else 260 else
(...skipping 13 matching lines...) Expand all
273 if (info.Length() >= {{argument_index}} + 1 && listener && !impl->toNode()) 274 if (info.Length() >= {{argument_index}} + 1 && listener && !impl->toNode())
274 {{hidden_dependency_action}}(info.GetIsolate(), info.Holder(), info[{{argume nt_index}}], {{v8_class}}::eventListenerCacheIndex); 275 {{hidden_dependency_action}}(info.GetIsolate(), info.Holder(), info[{{argume nt_index}}], {{v8_class}}::eventListenerCacheIndex);
275 {% endif %} 276 {% endif %}
276 {% endmacro %} 277 {% endmacro %}
277 278
278 279
279 {######################################} 280 {######################################}
280 {% macro throw_type_error(method, error_message) %} 281 {% macro throw_type_error(method, error_message) %}
281 {% if method.has_exception_state %} 282 {% if method.has_exception_state %}
282 exceptionState.throwTypeError({{error_message}}); 283 exceptionState.throwTypeError({{error_message}});
283 {{throw_from_exception_state(method)}}; 284 {{throw_from_exception_state(method)}}
284 {% elif method.idl_type == 'Promise' %} 285 {% elif method.idl_type == 'Promise' %}
285 v8SetReturnValue(info, ScriptPromise::rejectRaw(info.GetIsolate(), V8ThrowExcept ion::createTypeError(info.GetIsolate(), {{type_error_message(method, error_messa ge)}}))); 286 v8SetReturnValue(info, ScriptPromise::rejectRaw(info.GetIsolate(), V8ThrowExcept ion::createTypeError(info.GetIsolate(), {{type_error_message(method, error_messa ge)}})));
287 return;
286 {% else %} 288 {% else %}
287 V8ThrowException::throwTypeError(info.GetIsolate(), {{type_error_message(method, error_message)}}); 289 V8ThrowException::throwTypeError(info.GetIsolate(), {{type_error_message(method, error_message)}});
290 return;
288 {% endif %}{# method.has_exception_state #} 291 {% endif %}{# method.has_exception_state #}
289 {% endmacro %} 292 {% endmacro %}
290 293
291 294
292 {######################################} 295 {######################################}
293 {% macro type_error_message(method, error_message) %} 296 {% macro type_error_message(method, error_message) %}
294 {% if method.is_constructor %} 297 {% if method.is_constructor %}
295 ExceptionMessages::failedToConstruct("{{interface_name}}", {{error_message}}) 298 ExceptionMessages::failedToConstruct("{{interface_name}}", {{error_message}})
296 {%- else %} 299 {%- else %}
297 ExceptionMessages::failedToExecute("{{method.name}}", "{{interface_name}}", {{er ror_message}}) 300 ExceptionMessages::failedToExecute("{{method.name}}", "{{interface_name}}", {{er ror_message}})
298 {%- endif %} 301 {%- endif %}
299 {%- endmacro %} 302 {%- endmacro %}
300 303
301 304
302 {######################################} 305 {######################################}
303 {% macro throw_from_exception_state(method_or_overloads) %} 306 {% macro throw_from_exception_state(method_or_overloads) %}
304 {% if method_or_overloads.idl_type == 'Promise' or method_or_overloads.returns_p romise_all %} 307 {% if method_or_overloads.returns_promise_all %}
305 v8SetReturnValue(info, exceptionState.reject(ScriptState::current(info.GetIsolat e())).v8Value()) 308 v8SetReturnValue(info, exceptionState.reject(ScriptState::current(info.GetIsolat e())).v8Value());
306 {%- else %} 309 {% elif not method_or_overloads.returns_promise %}
307 exceptionState.throwIfNeeded() 310 exceptionState.throwIfNeeded();
308 {%- endif %} 311 {% endif %}
312 return;
309 {%- endmacro %} 313 {%- endmacro %}
310 314
311 315
312 {######################################} 316 {######################################}
313 {% macro throw_minimum_arity_type_error(method, number_of_required_arguments) %} 317 {% macro throw_minimum_arity_type_error(method, number_of_required_arguments) %}
314 {% if method.has_exception_state %} 318 {% if method.has_exception_state %}
315 setMinimumArityTypeError(exceptionState, {{number_of_required_arguments}}, info. Length()); 319 setMinimumArityTypeError(exceptionState, {{number_of_required_arguments}}, info. Length());
316 {{throw_from_exception_state(method)}}; 320 {{throw_from_exception_state(method)}}
317 {%- elif method.idl_type == 'Promise' %} 321 {%- elif method.idl_type == 'Promise' %}
318 v8SetReturnValue(info, ScriptPromise::rejectRaw(info.GetIsolate(), {{create_mini mum_arity_type_error_without_exception_state(method, number_of_required_argument s)}})); 322 v8SetReturnValue(info, ScriptPromise::rejectRaw(info.GetIsolate(), {{create_mini mum_arity_type_error_without_exception_state(method, number_of_required_argument s)}}));
323 return;
319 {%- else %} 324 {%- else %}
320 V8ThrowException::throwException({{create_minimum_arity_type_error_without_excep tion_state(method, number_of_required_arguments)}}, info.GetIsolate()); 325 V8ThrowException::throwException({{create_minimum_arity_type_error_without_excep tion_state(method, number_of_required_arguments)}}, info.GetIsolate());
326 return;
321 {%- endif %} 327 {%- endif %}
322 {%- endmacro %} 328 {%- endmacro %}
323 329
324 330
325 {######################################} 331 {######################################}
326 {% macro create_minimum_arity_type_error_without_exception_state(method, number_ of_required_arguments) %} 332 {% macro create_minimum_arity_type_error_without_exception_state(method, number_ of_required_arguments) %}
327 {% if method.is_constructor %} 333 {% if method.is_constructor %}
328 createMinimumArityTypeErrorForConstructor(info.GetIsolate(), "{{interface_name}} ", {{number_of_required_arguments}}, info.Length()) 334 createMinimumArityTypeErrorForConstructor(info.GetIsolate(), "{{interface_name}} ", {{number_of_required_arguments}}, info.Length())
329 {%- else %} 335 {%- else %}
330 createMinimumArityTypeErrorForMethod(info.GetIsolate(), "{{method.name}}", "{{in terface_name}}", {{number_of_required_arguments}}, info.Length()) 336 createMinimumArityTypeErrorForMethod(info.GetIsolate(), "{{method.name}}", "{{in terface_name}}", {{number_of_required_arguments}}, info.Length())
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
392 default: 398 default:
393 {# If methods are overloaded between interface and partial interface #} 399 {# If methods are overloaded between interface and partial interface #}
394 {# definitions, need to invoke methods defined in the partial #} 400 {# definitions, need to invoke methods defined in the partial #}
395 {# interface. #} 401 {# interface. #}
396 {# FIXME: we do not need to always generate this code. #} 402 {# FIXME: we do not need to always generate this code. #}
397 {# Invalid arity, throw error #} 403 {# Invalid arity, throw error #}
398 {# Report full list of valid arities if gaps and above minimum #} 404 {# Report full list of valid arities if gaps and above minimum #}
399 {% if overloads.valid_arities %} 405 {% if overloads.valid_arities %}
400 if (info.Length() >= {{overloads.minarg}}) { 406 if (info.Length() >= {{overloads.minarg}}) {
401 setArityTypeError(exceptionState, "{{overloads.valid_arities}}", inf o.Length()); 407 setArityTypeError(exceptionState, "{{overloads.valid_arities}}", inf o.Length());
402 {{throw_from_exception_state(overloads)}}; 408 {{throw_from_exception_state(overloads) | indent(12)}}
403 return;
404 } 409 }
405 {% endif %} 410 {% endif %}
406 break; 411 break;
407 {% endif %} 412 {% endif %}
408 } 413 }
409 {% if not is_partial and overloads.has_partial_overloads %} 414 {% if not is_partial and overloads.has_partial_overloads %}
410 ASSERT({{overloads.name}}MethodForPartialInterface); 415 ASSERT({{overloads.name}}MethodForPartialInterface);
411 ({{overloads.name}}MethodForPartialInterface)(info); 416 ({{overloads.name}}MethodForPartialInterface)(info);
412 {% else %} 417 {% else %}
413 {% if overloads.length != 0 %} 418 {% if overloads.length != 0 %}
414 if (info.Length() < {{overloads.length}}) { 419 if (info.Length() < {{overloads.length}}) {
415 {# Otherwise just report "not enough arguments" #} 420 {# Otherwise just report "not enough arguments" #}
416 exceptionState.throwTypeError(ExceptionMessages::notEnoughArguments({{ov erloads.length}}, info.Length())); 421 exceptionState.throwTypeError(ExceptionMessages::notEnoughArguments({{ov erloads.length}}, info.Length()));
417 {{throw_from_exception_state(overloads)}}; 422 {{throw_from_exception_state(overloads) | indent(8)}}
418 return;
419 } 423 }
420 {% endif %} 424 {% endif %}
421 {# No match, throw error #} 425 {# No match, throw error #}
422 exceptionState.throwTypeError("No function was found that matched the signat ure provided."); 426 exceptionState.throwTypeError("No function was found that matched the signat ure provided.");
423 {{throw_from_exception_state(overloads)}}; 427 {{throw_from_exception_state(overloads) | indent}}
424 {% endif %} 428 {% endif %}
425 } 429 }
426 {% endmacro %} 430 {% endmacro %}
427 431
428 432
429 {##############################################################################} 433 {##############################################################################}
430 {% macro method_callback(method, world_suffix) %} 434 {% macro method_callback(method, world_suffix) %}
431 {% filter conditional(method.conditional_string) %} 435 {% filter conditional(method.conditional_string) %}
432 static void {{method.name}}MethodCallback{{world_suffix}}(const v8::FunctionCall backInfo<v8::Value>& info) 436 static void {{method.name}}MethodCallback{{world_suffix}}(const v8::FunctionCall backInfo<v8::Value>& info)
433 { 437 {
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
570 return; 574 return;
571 } 575 }
572 {% endif %} 576 {% endif %}
573 {% if constructor.has_exception_state %} 577 {% if constructor.has_exception_state %}
574 ExceptionState exceptionState(ExceptionState::ConstructionContext, "{{interf ace_name}}", info.Holder(), info.GetIsolate()); 578 ExceptionState exceptionState(ExceptionState::ConstructionContext, "{{interf ace_name}}", info.Holder(), info.GetIsolate());
575 {% endif %} 579 {% endif %}
576 {# Overloaded constructors have length checked during overload resolution #} 580 {# Overloaded constructors have length checked during overload resolution #}
577 {% if constructor.number_of_required_arguments and not constructor.overload_ index %} 581 {% if constructor.number_of_required_arguments and not constructor.overload_ index %}
578 if (UNLIKELY(info.Length() < {{constructor.number_of_required_arguments}})) { 582 if (UNLIKELY(info.Length() < {{constructor.number_of_required_arguments}})) {
579 {{throw_minimum_arity_type_error(constructor, constructor.number_of_requ ired_arguments) | indent(8)}} 583 {{throw_minimum_arity_type_error(constructor, constructor.number_of_requ ired_arguments) | indent(8)}}
580 return;
581 } 584 }
582 {% endif %} 585 {% endif %}
583 {% if constructor.arguments %} 586 {% if constructor.arguments %}
584 {{generate_arguments(constructor) | indent}} 587 {{generate_arguments(constructor) | indent}}
585 {% endif %} 588 {% endif %}
586 {{cpp_method_call(constructor, constructor.v8_set_return_value, constructor. cpp_value) | indent}} 589 {{cpp_method_call(constructor, constructor.v8_set_return_value, constructor. cpp_value) | indent}}
587 } 590 }
588 {% endmacro %} 591 {% endmacro %}
589 592
590 593
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
651 if method.overloads else 654 if method.overloads else
652 method.runtime_enabled_function) %} 655 method.runtime_enabled_function) %}
653 prototypeObject->Set(v8AtomicString(isolate, "{{method.name}}"), v8::Functio nTemplate::New(isolate, {{cpp_class_or_partial}}V8Internal::{{method.name}}Metho dCallback, v8Undefined(), defaultSignature, {{method.number_of_required_argument s}})->GetFunction()); 656 prototypeObject->Set(v8AtomicString(isolate, "{{method.name}}"), v8::Functio nTemplate::New(isolate, {{cpp_class_or_partial}}V8Internal::{{method.name}}Metho dCallback, v8Undefined(), defaultSignature, {{method.number_of_required_argument s}})->GetFunction());
654 {% endfilter %}{# runtime_enabled() #} 657 {% endfilter %}{# runtime_enabled() #}
655 {% endfilter %}{# exposed() #} 658 {% endfilter %}{# exposed() #}
656 {% endfilter %}{# per_context_enabled() #} 659 {% endfilter %}{# per_context_enabled() #}
657 {% endfor %} 660 {% endfor %}
658 {% endif %} 661 {% endif %}
659 } 662 }
660 {%- endmacro %} 663 {%- endmacro %}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698