OLD | NEW |
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 static void {{method.name}}{{method.overload_index}}Method{{world_suffix}}(const
v8::FunctionCallbackInfo<v8::Value>& info) | 4 static void {{method.name}}{{method.overload_index}}Method{{world_suffix}}(const
v8::FunctionCallbackInfo<v8::Value>& info) |
5 { | 5 { |
6 {# Local variables #} | 6 {# Local variables #} |
7 {% if method.has_exception_state %} | 7 {% if method.has_exception_state %} |
8 ExceptionState exceptionState(ExceptionState::ExecutionContext, "{{method.na
me}}", "{{interface_name}}", info.Holder(), info.GetIsolate()); | 8 ExceptionState exceptionState(ExceptionState::ExecutionContext, "{{method.na
me}}", "{{interface_name}}", info.Holder(), info.GetIsolate()); |
9 {% endif %} | 9 {% endif %} |
10 {# Overloaded methods have length checked during overload resolution #} | 10 {# Overloaded methods have length checked during overload resolution #} |
11 {% if method.number_of_required_arguments and not method.overload_index %} | 11 {% if method.number_of_required_arguments and not method.overload_index %} |
12 if (UNLIKELY(info.Length() < {{method.number_of_required_arguments}})) { | 12 if (UNLIKELY(info.Length() < {{method.number_of_required_arguments}})) { |
13 {{throw_arity_type_error(method, method.number_of_required_arguments)}}; | 13 {{throw_minimum_arity_type_error(method, method.number_of_required_argum
ents)}}; |
14 return; | 14 return; |
15 } | 15 } |
16 {% endif %} | 16 {% endif %} |
17 {% if not method.is_static %} | 17 {% if not method.is_static %} |
18 {{cpp_class}}* impl = {{v8_class}}::toNative(info.Holder()); | 18 {{cpp_class}}* impl = {{v8_class}}::toNative(info.Holder()); |
19 {% endif %} | 19 {% endif %} |
20 {% if method.is_custom_element_callbacks %} | 20 {% if method.is_custom_element_callbacks %} |
21 CustomElementCallbackDispatcher::CallbackDeliveryScope deliveryScope; | 21 CustomElementCallbackDispatcher::CallbackDeliveryScope deliveryScope; |
22 {% endif %} | 22 {% endif %} |
23 {# Security checks #} | 23 {# Security checks #} |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 exceptionState.throwIfNeeded(); | 260 exceptionState.throwIfNeeded(); |
261 {%- elif method.is_constructor %} | 261 {%- elif method.is_constructor %} |
262 throwTypeError(ExceptionMessages::failedToConstruct("{{interface_name}}", {{erro
r_message}}), info.GetIsolate()); | 262 throwTypeError(ExceptionMessages::failedToConstruct("{{interface_name}}", {{erro
r_message}}), info.GetIsolate()); |
263 {%- else %} | 263 {%- else %} |
264 throwTypeError(ExceptionMessages::failedToExecute("{{method.name}}", "{{interfac
e_name}}", {{error_message}}), info.GetIsolate()); | 264 throwTypeError(ExceptionMessages::failedToExecute("{{method.name}}", "{{interfac
e_name}}", {{error_message}}), info.GetIsolate()); |
265 {%- endif %} | 265 {%- endif %} |
266 {% endmacro %} | 266 {% endmacro %} |
267 | 267 |
268 | 268 |
269 {######################################} | 269 {######################################} |
270 {% macro throw_arity_type_error(method, number_of_required_arguments) %} | 270 {% macro throw_arity_type_error(method, valid_arities) %} |
271 {% if method.has_exception_state %} | 271 {% if method.has_exception_state %} |
272 throwArityTypeError(exceptionState, {{number_of_required_arguments}}, info.Lengt
h()) | 272 throwArityTypeError(exceptionState, {{valid_arities}}, info.Length()) |
273 {%- elif method.is_constructor %} | 273 {%- elif method.is_constructor %} |
274 throwArityTypeErrorForConstructor("{{interface_name}}", {{number_of_required_arg
uments}}, info.Length(), info.GetIsolate()) | 274 throwArityTypeErrorForConstructor("{{interface_name}}", {{valid_arities}}, info.
Length(), info.GetIsolate()) |
275 {%- else %} | 275 {%- else %} |
276 throwArityTypeErrorForMethod("{{method.name}}", "{{interface_name}}", {{number_o
f_required_arguments}}, info.Length(), info.GetIsolate()) | 276 throwArityTypeErrorForMethod("{{method.name}}", "{{interface_name}}", {{valid_ar
ities}}, info.Length(), info.GetIsolate()) |
277 {%- endif %} | 277 {%- endif %} |
278 {% endmacro %} | 278 {% endmacro %} |
279 | 279 |
| 280 |
| 281 {######################################} |
| 282 {% macro throw_minimum_arity_type_error(method, number_of_required_arguments) %} |
| 283 {% if method.has_exception_state %} |
| 284 throwMinimumArityTypeError(exceptionState, {{number_of_required_arguments}}, inf
o.Length()) |
| 285 {%- elif method.is_constructor %} |
| 286 throwMinimumArityTypeErrorForConstructor("{{interface_name}}", {{number_of_requi
red_arguments}}, info.Length(), info.GetIsolate()) |
| 287 {%- else %} |
| 288 throwMinimumArityTypeErrorForMethod("{{method.name}}", "{{interface_name}}", {{n
umber_of_required_arguments}}, info.Length(), info.GetIsolate()) |
| 289 {%- endif %} |
| 290 {% endmacro %} |
| 291 |
280 | 292 |
281 {##############################################################################} | 293 {##############################################################################} |
282 {% macro overload_resolution_method(overloads, world_suffix) %} | 294 {% macro overload_resolution_method(overloads, world_suffix) %} |
283 static void {{overloads.name}}Method{{world_suffix}}(const v8::FunctionCallbackI
nfo<v8::Value>& info) | 295 static void {{overloads.name}}Method{{world_suffix}}(const v8::FunctionCallbackI
nfo<v8::Value>& info) |
284 { | 296 { |
285 v8::Isolate* isolate = info.GetIsolate(); | 297 v8::Isolate* isolate = info.GetIsolate(); |
286 ExceptionState exceptionState(ExceptionState::ExecutionContext, "{{overloads
.name}}", "{{interface_name}}", info.Holder(), isolate); | 298 ExceptionState exceptionState(ExceptionState::ExecutionContext, "{{overloads
.name}}", "{{interface_name}}", info.Holder(), isolate); |
287 {% if overloads.measure_all_as %} | 299 {% if overloads.measure_all_as %} |
288 UseCounter::count(callingExecutionContext(isolate), UseCounter::{{overloads.
measure_all_as}}); | 300 UseCounter::count(callingExecutionContext(isolate), UseCounter::{{overloads.
measure_all_as}}); |
289 {% endif %} | 301 {% endif %} |
(...skipping 16 matching lines...) Expand all Loading... |
306 {% endif %} | 318 {% endif %} |
307 {% if method.deprecate_as and not overloads.deprecate_all_as %} | 319 {% if method.deprecate_as and not overloads.deprecate_all_as %} |
308 UseCounter::countDeprecation(callingExecutionContext(isolate), UseCo
unter::{{method.deprecate_as}}); | 320 UseCounter::countDeprecation(callingExecutionContext(isolate), UseCo
unter::{{method.deprecate_as}}); |
309 {% endif %} | 321 {% endif %} |
310 {{method.name}}{{method.overload_index}}Method{{world_suffix}}(info)
; | 322 {{method.name}}{{method.overload_index}}Method{{world_suffix}}(info)
; |
311 return; | 323 return; |
312 } | 324 } |
313 {% endfor %} | 325 {% endfor %} |
314 break; | 326 break; |
315 {% endfor %} | 327 {% endfor %} |
| 328 default: |
| 329 {# Invalid arity, throw error #} |
| 330 {# Report full list of valid arities if gaps and above minimum #} |
| 331 {% if overloads.valid_arities %} |
| 332 if (info.Length() >= {{overloads.minarg}}) { |
| 333 throwArityTypeError(exceptionState, "{{overloads.valid_arities}}", i
nfo.Length()); |
| 334 return; |
| 335 } |
| 336 {% endif %} |
| 337 {# Otherwise just report "not enough arguments" #} |
| 338 exceptionState.throwTypeError(ExceptionMessages::notEnoughArguments({{ov
erloads.minarg}}, info.Length())); |
| 339 exceptionState.throwIfNeeded(); |
| 340 return; |
316 } | 341 } |
317 {# No match, throw error #} | 342 {# No match, throw error #} |
318 {% if overloads.minimum_number_of_required_arguments %} | |
319 if (UNLIKELY(info.Length() < {{overloads.minimum_number_of_required_argument
s}})) { | |
320 throwArityTypeError(exceptionState, {{overloads.minimum_number_of_requir
ed_arguments}}, info.Length()); | |
321 return; | |
322 } | |
323 {% endif %} | |
324 exceptionState.throwTypeError("No function was found that matched the signat
ure provided."); | 343 exceptionState.throwTypeError("No function was found that matched the signat
ure provided."); |
325 exceptionState.throwIfNeeded(); | 344 exceptionState.throwIfNeeded(); |
326 } | 345 } |
327 {% endmacro %} | 346 {% endmacro %} |
328 | 347 |
329 | 348 |
330 {##############################################################################} | 349 {##############################################################################} |
331 {% macro method_callback(method, world_suffix) %} | 350 {% macro method_callback(method, world_suffix) %} |
332 {% filter conditional(method.conditional_string) %} | 351 {% filter conditional(method.conditional_string) %} |
333 static void {{method.name}}MethodCallback{{world_suffix}}(const v8::FunctionCall
backInfo<v8::Value>& info) | 352 static void {{method.name}}MethodCallback{{world_suffix}}(const v8::FunctionCall
backInfo<v8::Value>& info) |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
413 static void constructor{{constructor.overload_index}}(const v8::FunctionCallback
Info<v8::Value>& info) | 432 static void constructor{{constructor.overload_index}}(const v8::FunctionCallback
Info<v8::Value>& info) |
414 { | 433 { |
415 v8::Isolate* isolate = info.GetIsolate(); | 434 v8::Isolate* isolate = info.GetIsolate(); |
416 {% if constructor.has_exception_state %} | 435 {% if constructor.has_exception_state %} |
417 ExceptionState exceptionState(ExceptionState::ConstructionContext, "{{interf
ace_name}}", info.Holder(), isolate); | 436 ExceptionState exceptionState(ExceptionState::ConstructionContext, "{{interf
ace_name}}", info.Holder(), isolate); |
418 {% endif %} | 437 {% endif %} |
419 {# Overloaded constructors have length checked during overload resolution #} | 438 {# Overloaded constructors have length checked during overload resolution #} |
420 {% if interface_length and not constructor.overload_index %} | 439 {% if interface_length and not constructor.overload_index %} |
421 {# FIXME: remove UNLIKELY: constructors are expensive, so no difference. #} | 440 {# FIXME: remove UNLIKELY: constructors are expensive, so no difference. #} |
422 if (UNLIKELY(info.Length() < {{interface_length}})) { | 441 if (UNLIKELY(info.Length() < {{interface_length}})) { |
423 {{throw_arity_type_error(constructor, interface_length)}}; | 442 {{throw_minimum_arity_type_error(constructor, interface_length)}}; |
424 return; | 443 return; |
425 } | 444 } |
426 {% endif %} | 445 {% endif %} |
427 {% for argument in constructor.arguments %} | 446 {% for argument in constructor.arguments %} |
428 {{generate_argument(constructor, argument) | indent}} | 447 {{generate_argument(constructor, argument) | indent}} |
429 {% endfor %} | 448 {% endfor %} |
430 {% if is_constructor_call_with_execution_context %} | 449 {% if is_constructor_call_with_execution_context %} |
431 ExecutionContext* context = currentExecutionContext(isolate); | 450 ExecutionContext* context = currentExecutionContext(isolate); |
432 {% endif %} | 451 {% endif %} |
433 {% if is_constructor_call_with_document %} | 452 {% if is_constructor_call_with_document %} |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
479 | 498 |
480 // Make sure the document is added to the DOM Node map. Otherwise, the {{cpp
_class}} instance | 499 // Make sure the document is added to the DOM Node map. Otherwise, the {{cpp
_class}} instance |
481 // may end up being the only node in the map and get garbage-collected prema
turely. | 500 // may end up being the only node in the map and get garbage-collected prema
turely. |
482 toV8(document, info.Holder(), isolate); | 501 toV8(document, info.Holder(), isolate); |
483 | 502 |
484 {% if constructor.has_exception_state %} | 503 {% if constructor.has_exception_state %} |
485 ExceptionState exceptionState(ExceptionState::ConstructionContext, "{{interf
ace_name}}", info.Holder(), isolate); | 504 ExceptionState exceptionState(ExceptionState::ConstructionContext, "{{interf
ace_name}}", info.Holder(), isolate); |
486 {% endif %} | 505 {% endif %} |
487 {% if constructor.number_of_required_arguments %} | 506 {% if constructor.number_of_required_arguments %} |
488 if (UNLIKELY(info.Length() < {{constructor.number_of_required_arguments}}))
{ | 507 if (UNLIKELY(info.Length() < {{constructor.number_of_required_arguments}}))
{ |
489 {{throw_arity_type_error(constructor, constructor.number_of_required_arg
uments)}}; | 508 {{throw_minimum_arity_type_error(constructor, constructor.number_of_requ
ired_arguments)}}; |
490 return; | 509 return; |
491 } | 510 } |
492 {% endif %} | 511 {% endif %} |
493 {% for argument in constructor.arguments %} | 512 {% for argument in constructor.arguments %} |
494 {{generate_argument(constructor, argument) | indent}} | 513 {{generate_argument(constructor, argument) | indent}} |
495 {% endfor %} | 514 {% endfor %} |
496 {{constructor.cpp_type}} impl = {{cpp_class}}::createForJSConstructor({{cons
tructor.argument_list | join(', ')}}); | 515 {{constructor.cpp_type}} impl = {{cpp_class}}::createForJSConstructor({{cons
tructor.argument_list | join(', ')}}); |
497 {% if is_constructor_raises_exception %} | 516 {% if is_constructor_raises_exception %} |
498 if (exceptionState.throwIfNeeded()) | 517 if (exceptionState.throwIfNeeded()) |
499 return; | 518 return; |
500 {% endif %} | 519 {% endif %} |
501 | 520 |
502 {{generate_constructor_wrapper(constructor) | indent}} | 521 {{generate_constructor_wrapper(constructor) | indent}} |
503 } | 522 } |
504 {% endmacro %} | 523 {% endmacro %} |
OLD | NEW |