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 {% if method.number_of_required_arguments %} | 10 {% if method.number_of_required_arguments %} |
11 if (UNLIKELY(info.Length() < {{method.number_of_required_arguments}})) { | 11 if (UNLIKELY(info.Length() < {{method.number_of_required_arguments}})) { |
12 {{throw_type_error(method, | 12 {{throw_arity_type_error(method, method.number_of_required_arguments)}}; |
13 'ExceptionMessages::notEnoughArguments(%s, info.Length())' % | |
14 method.number_of_required_arguments) | indent(8)}} | |
15 return; | 13 return; |
16 } | 14 } |
17 {% endif %} | 15 {% endif %} |
18 {% if not method.is_static %} | 16 {% if not method.is_static %} |
19 {{cpp_class}}* impl = {{v8_class}}::toNative(info.Holder()); | 17 {{cpp_class}}* impl = {{v8_class}}::toNative(info.Holder()); |
20 {% endif %} | 18 {% endif %} |
21 {% if method.is_custom_element_callbacks %} | 19 {% if method.is_custom_element_callbacks %} |
22 CustomElementCallbackDispatcher::CallbackDeliveryScope deliveryScope; | 20 CustomElementCallbackDispatcher::CallbackDeliveryScope deliveryScope; |
23 {% endif %} | 21 {% endif %} |
24 {# Security checks #} | 22 {# Security checks #} |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 exceptionState.throwTypeError({{error_message}}); | 249 exceptionState.throwTypeError({{error_message}}); |
252 exceptionState.throwIfNeeded(); | 250 exceptionState.throwIfNeeded(); |
253 {%- elif method.is_constructor %} | 251 {%- elif method.is_constructor %} |
254 throwTypeError(ExceptionMessages::failedToConstruct("{{interface_name}}", {{erro
r_message}}), info.GetIsolate()); | 252 throwTypeError(ExceptionMessages::failedToConstruct("{{interface_name}}", {{erro
r_message}}), info.GetIsolate()); |
255 {%- else %} | 253 {%- else %} |
256 throwTypeError(ExceptionMessages::failedToExecute("{{method.name}}", "{{interfac
e_name}}", {{error_message}}), info.GetIsolate()); | 254 throwTypeError(ExceptionMessages::failedToExecute("{{method.name}}", "{{interfac
e_name}}", {{error_message}}), info.GetIsolate()); |
257 {%- endif %} | 255 {%- endif %} |
258 {% endmacro %} | 256 {% endmacro %} |
259 | 257 |
260 | 258 |
| 259 {######################################} |
| 260 {% macro throw_arity_type_error(method, number_of_required_arguments) %} |
| 261 {% if method.has_exception_state %} |
| 262 throwArityTypeError(exceptionState, {{number_of_required_arguments}}, info.Lengt
h()) |
| 263 {%- elif method.is_constructor %} |
| 264 throwArityTypeErrorForConstructor("{{interface_name}}", {{number_of_required_arg
uments}}, info.Length(), info.GetIsolate()) |
| 265 {%- else %} |
| 266 throwArityTypeErrorForMethod("{{method.name}}", "{{interface_name}}", {{number_o
f_required_arguments}}, info.Length(), info.GetIsolate()) |
| 267 {%- endif %} |
| 268 {% endmacro %} |
| 269 |
| 270 |
261 {##############################################################################} | 271 {##############################################################################} |
262 {% macro overload_resolution_method(overloads, world_suffix) %} | 272 {% macro overload_resolution_method(overloads, world_suffix) %} |
263 static void {{overloads.name}}Method{{world_suffix}}(const v8::FunctionCallbackI
nfo<v8::Value>& info) | 273 static void {{overloads.name}}Method{{world_suffix}}(const v8::FunctionCallbackI
nfo<v8::Value>& info) |
264 { | 274 { |
265 {% for method in overloads.methods %} | 275 {% for method in overloads.methods %} |
266 if ({{method.overload_resolution_expression}}) { | 276 if ({{method.overload_resolution_expression}}) { |
267 {{method.name}}{{method.overload_index}}Method{{world_suffix}}(info); | 277 {{method.name}}{{method.overload_index}}Method{{world_suffix}}(info); |
268 return; | 278 return; |
269 } | 279 } |
270 {% endfor %} | 280 {% endfor %} |
271 {% if overloads.minimum_number_of_required_arguments %} | 281 {% if overloads.minimum_number_of_required_arguments %} |
272 ExceptionState exceptionState(ExceptionState::ExecutionContext, "{{overloads
.name}}", "{{interface_name}}", info.Holder(), info.GetIsolate()); | 282 ExceptionState exceptionState(ExceptionState::ExecutionContext, "{{overloads
.name}}", "{{interface_name}}", info.Holder(), info.GetIsolate()); |
273 if (UNLIKELY(info.Length() < {{overloads.minimum_number_of_required_argument
s}})) { | 283 if (UNLIKELY(info.Length() < {{overloads.minimum_number_of_required_argument
s}})) { |
274 {{throw_type_error(overloads, | 284 {{throw_arity_type_error(overloads, overloads.minimum_number_of_required
_arguments)}}; |
275 'ExceptionMessages::notEnoughArguments(%s, info.Length())' % | |
276 overloads.minimum_number_of_required_arguments) | indent(8)}} | |
277 return; | 285 return; |
278 } | 286 } |
279 {% endif %} | 287 {% endif %} |
280 {{throw_type_error(overloads, '"No function was found that matched the signa
ture provided."') | indent}} | 288 {{throw_type_error(overloads, '"No function was found that matched the signa
ture provided."') | indent}} |
281 } | 289 } |
282 {% endmacro %} | 290 {% endmacro %} |
283 | 291 |
284 | 292 |
285 {##############################################################################} | 293 {##############################################################################} |
286 {% macro method_callback(method, world_suffix) %} | 294 {% macro method_callback(method, world_suffix) %} |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
364 {% macro generate_constructor(constructor) %} | 372 {% macro generate_constructor(constructor) %} |
365 static void constructor{{constructor.overload_index}}(const v8::FunctionCallback
Info<v8::Value>& info) | 373 static void constructor{{constructor.overload_index}}(const v8::FunctionCallback
Info<v8::Value>& info) |
366 { | 374 { |
367 v8::Isolate* isolate = info.GetIsolate(); | 375 v8::Isolate* isolate = info.GetIsolate(); |
368 {% if constructor.has_exception_state %} | 376 {% if constructor.has_exception_state %} |
369 ExceptionState exceptionState(ExceptionState::ConstructionContext, "{{interf
ace_name}}", info.Holder(), isolate); | 377 ExceptionState exceptionState(ExceptionState::ConstructionContext, "{{interf
ace_name}}", info.Holder(), isolate); |
370 {% endif %} | 378 {% endif %} |
371 {% if interface_length and not constructor.overload_index %} | 379 {% if interface_length and not constructor.overload_index %} |
372 {# FIXME: remove UNLIKELY: constructors are expensive, so no difference. #} | 380 {# FIXME: remove UNLIKELY: constructors are expensive, so no difference. #} |
373 if (UNLIKELY(info.Length() < {{interface_length}})) { | 381 if (UNLIKELY(info.Length() < {{interface_length}})) { |
374 {{throw_type_error(constructor, | 382 {{throw_arity_type_error(constructor, interface_length)}}; |
375 'ExceptionMessages::notEnoughArguments(%s, info.Length())' % | |
376 interface_length) | indent(8)}} | |
377 return; | 383 return; |
378 } | 384 } |
379 {% endif %} | 385 {% endif %} |
380 {% for argument in constructor.arguments %} | 386 {% for argument in constructor.arguments %} |
381 {{generate_argument(constructor, argument) | indent}} | 387 {{generate_argument(constructor, argument) | indent}} |
382 {% endfor %} | 388 {% endfor %} |
383 {% if is_constructor_call_with_execution_context %} | 389 {% if is_constructor_call_with_execution_context %} |
384 ExecutionContext* context = currentExecutionContext(isolate); | 390 ExecutionContext* context = currentExecutionContext(isolate); |
385 {% endif %} | 391 {% endif %} |
386 {% if is_constructor_call_with_document %} | 392 {% if is_constructor_call_with_document %} |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
422 | 428 |
423 // Make sure the document is added to the DOM Node map. Otherwise, the {{cpp
_class}} instance | 429 // Make sure the document is added to the DOM Node map. Otherwise, the {{cpp
_class}} instance |
424 // may end up being the only node in the map and get garbage-collected prema
turely. | 430 // may end up being the only node in the map and get garbage-collected prema
turely. |
425 toV8(document, info.Holder(), info.GetIsolate()); | 431 toV8(document, info.Holder(), info.GetIsolate()); |
426 | 432 |
427 {% if constructor.has_exception_state %} | 433 {% if constructor.has_exception_state %} |
428 ExceptionState exceptionState(ExceptionState::ConstructionContext, "{{interf
ace_name}}", info.Holder(), info.GetIsolate()); | 434 ExceptionState exceptionState(ExceptionState::ConstructionContext, "{{interf
ace_name}}", info.Holder(), info.GetIsolate()); |
429 {% endif %} | 435 {% endif %} |
430 {% if constructor.number_of_required_arguments %} | 436 {% if constructor.number_of_required_arguments %} |
431 if (UNLIKELY(info.Length() < {{constructor.number_of_required_arguments}}))
{ | 437 if (UNLIKELY(info.Length() < {{constructor.number_of_required_arguments}}))
{ |
432 {{throw_type_error(constructor, | 438 {{throw_arity_type_error(constructor, constructor.number_of_required_arg
uments)}}; |
433 'ExceptionMessages::notEnoughArguments(%s, info.Length())' % | |
434 constructor.number_of_required_arguments) | indent(8)}} | |
435 return; | 439 return; |
436 } | 440 } |
437 {% endif %} | 441 {% endif %} |
438 {% for argument in constructor.arguments %} | 442 {% for argument in constructor.arguments %} |
439 {{generate_argument(constructor, argument) | indent}} | 443 {{generate_argument(constructor, argument) | indent}} |
440 {% endfor %} | 444 {% endfor %} |
441 RefPtr<{{cpp_class}}> impl = {{cpp_class}}::createForJSConstructor({{constru
ctor.argument_list | join(', ')}}); | 445 RefPtr<{{cpp_class}}> impl = {{cpp_class}}::createForJSConstructor({{constru
ctor.argument_list | join(', ')}}); |
442 {% if is_constructor_raises_exception %} | 446 {% if is_constructor_raises_exception %} |
443 if (exceptionState.throwIfNeeded()) | 447 if (exceptionState.throwIfNeeded()) |
444 return; | 448 return; |
445 {% endif %} | 449 {% endif %} |
446 | 450 |
447 {% if has_custom_wrap %} | 451 {% if has_custom_wrap %} |
448 v8::Handle<v8::Object> wrapper = wrap(impl.get(), info.Holder(), info.GetIso
late()); | 452 v8::Handle<v8::Object> wrapper = wrap(impl.get(), info.Holder(), info.GetIso
late()); |
449 {% else %} | 453 {% else %} |
450 v8::Handle<v8::Object> wrapper = info.Holder(); | 454 v8::Handle<v8::Object> wrapper = info.Holder(); |
451 V8DOMWrapper::associateObjectWithWrapper<{{v8_class}}>(impl.release(), &{{v8
_class}}Constructor::wrapperTypeInfo, wrapper, info.GetIsolate(), {{wrapper_conf
iguration}}); | 455 V8DOMWrapper::associateObjectWithWrapper<{{v8_class}}>(impl.release(), &{{v8
_class}}Constructor::wrapperTypeInfo, wrapper, info.GetIsolate(), {{wrapper_conf
iguration}}); |
452 {% endif %} | 456 {% endif %} |
453 v8SetReturnValue(info, wrapper); | 457 v8SetReturnValue(info, wrapper); |
454 } | 458 } |
455 {% endmacro %} | 459 {% endmacro %} |
OLD | NEW |