Chromium Code Reviews| 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_minimum_arity_type_error(method, method.number_of_required_argum ents)}}; | 13 {{throw_minimum_arity_type_error(method, method.number_of_required_argum ents) | indent(8)}} |
| 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 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 310 {{v8_set_return_value}}; | 310 {{v8_set_return_value}}; |
| 311 return; | 311 return; |
| 312 } | 312 } |
| 313 {% endfor %} | 313 {% endfor %} |
| 314 {# Fall back to null if none of the union members results are returned #} | 314 {# Fall back to null if none of the union members results are returned #} |
| 315 v8SetReturnValueNull(info); | 315 v8SetReturnValueNull(info); |
| 316 {% endmacro %} | 316 {% endmacro %} |
| 317 | 317 |
| 318 | 318 |
| 319 {######################################} | 319 {######################################} |
| 320 {% macro type_error_message(method, error_message) %} | |
|
Jens Widell
2014/08/12 08:42:26
Nit: nbarth@ once told me "Order here is top-down"
yhirano
2014/08/12 09:36:09
Done.
| |
| 321 {% if method.is_constructor %} | |
| 322 ExceptionMessages::failedToConstruct("{{interface_name}}", {{error_message}}) | |
| 323 {%- else %} | |
| 324 ExceptionMessages::failedToExecute("{{method.name}}", "{{interface_name}}", {{er ror_message}}) | |
| 325 {%- endif %} | |
| 326 {%- endmacro %} | |
| 327 | |
| 328 | |
| 329 {######################################} | |
| 320 {% macro throw_type_error(method, error_message) %} | 330 {% macro throw_type_error(method, error_message) %} |
| 321 {% if method.has_exception_state %} | 331 {% if method.has_exception_state %} |
| 322 exceptionState.throwTypeError({{error_message}}); | 332 exceptionState.throwTypeError({{error_message}}); |
| 323 {{throw_from_exception_state(method)}}; | 333 {{throw_from_exception_state(method)}}; |
| 324 {% elif method.is_constructor %} | 334 {% elif method.idl_type == 'Promise' %} |
| 325 {% if method.idl_type == 'Promise' %} | 335 v8SetReturnValue(info, ScriptPromise::rejectRaw(info.GetIsolate(), V8ThrowExcept ion::createTypeError({{type_error_message(method, error_message)}}, info.GetIsol ate()))); |
| 326 {# FIXME: reduce code duplication between sync / async exception handling. #} | |
| 327 v8SetReturnValue(info, ScriptPromise::rejectWithTypeError(ScriptState::current(i nfo.GetIsolate()), ExceptionMessages::failedToConstruct("{{interface_name}}", {{ error_message}})).v8Value()); | |
| 328 {% else %} | 336 {% else %} |
| 329 V8ThrowException::throwTypeError(ExceptionMessages::failedToConstruct("{{interfa ce_name}}", {{error_message}}), info.GetIsolate()); | 337 V8ThrowException::throwTypeError({{type_error_message(method, error_message)}}, info.GetIsolate()); |
| 330 {% endif %} | |
| 331 {% else %}{# method.has_exception_state #} | |
| 332 {% if method.idl_type == 'Promise' %} | |
| 333 v8SetReturnValue(info, ScriptPromise::rejectWithTypeError(ScriptState::current(i nfo.GetIsolate()), ExceptionMessages::failedToExecute("{{method.name}}", "{{inte rface_name}}", {{error_message}})).v8Value()); | |
| 334 {% else %} | |
| 335 V8ThrowException::throwTypeError(ExceptionMessages::failedToExecute("{{method.na me}}", "{{interface_name}}", {{error_message}}), info.GetIsolate()); | |
| 336 {% endif %} | |
| 337 {% endif %}{# method.has_exception_state #} | 338 {% endif %}{# method.has_exception_state #} |
| 338 {% endmacro %} | 339 {% endmacro %} |
| 339 | 340 |
| 340 | 341 |
| 341 {######################################} | 342 {######################################} |
| 342 {% macro throw_from_exception_state(method) %} | 343 {% macro throw_from_exception_state(method) %} |
| 343 {% if method.idl_type == 'Promise' %} | 344 {% if method.idl_type == 'Promise' %} |
| 344 v8SetReturnValue(info, exceptionState.reject(ScriptState::current(info.GetIsolat e())).v8Value()) | 345 v8SetReturnValue(info, exceptionState.reject(ScriptState::current(info.GetIsolat e())).v8Value()) |
| 345 {%- else %} | 346 {%- else %} |
| 346 exceptionState.throwIfNeeded() | 347 exceptionState.throwIfNeeded() |
| 347 {%- endif %} | 348 {%- endif %} |
| 348 {%- endmacro %} | 349 {%- endmacro %} |
| 349 | 350 |
| 350 | 351 |
| 351 {######################################} | 352 {######################################} |
| 352 {% macro throw_arity_type_error(method, valid_arities) %} | 353 {% macro create_minimum_arity_type_error_without_exception_state(method, number_ of_required_arguments) %} |
| 353 {% if method.idl_type == 'Promise' %} | 354 {% if method.is_constructor %} |
| 354 {% if method.has_exception_state %} | 355 createMinimumArityTypeErrorForConstructor("{{interface_name}}", {{number_of_requ ired_arguments}}, info.Length(), info.GetIsolate()) |
| 355 v8SetReturnValue(info, ScriptPromise::rejectWithArityTypeError(ScriptState::curr ent(info.GetIsolate()), exceptionState, {{valid_arities}}, info.Length()).v8Valu e()) | |
| 356 {%- elif method.is_constructor %} | |
| 357 v8SetReturnValue(info, ScriptPromise::rejectWithArityTypeErrorForConstructor(Scr iptState::current(info.GetIsolate()), "{{interface_name}}", {{valid_arities}}, i nfo.Length()).v8Value()) | |
| 358 {%- else %} | 356 {%- else %} |
| 359 v8SetReturnValue(info, ScriptPromise::rejectWithArityTypeErrorForMethod(ScriptSt ate::current(info.GetIsolate()), "{{method.name}}", "{{interface_name}}", {{vali d_arities}}, info.Length()).v8Value()) | 357 createMinimumArityTypeErrorForMethod("{{method.name}}", "{{interface_name}}", {{ number_of_required_arguments}}, info.Length(), info.GetIsolate()) |
| 360 {%- endif %} | 358 {%- endif %} |
| 361 {%- else %}{# methods.idl_type == 'Promise' #} | 359 {%- endmacro %} |
| 362 {% if method.has_exception_state %} | |
| 363 throwArityTypeError(exceptionState, {{valid_arities}}, info.Length()) | |
| 364 {%- elif method.is_constructor %} | |
| 365 throwArityTypeErrorForConstructor("{{interface_name}}", {{valid_arities}}, info. Length(), info.GetIsolate()) | |
| 366 {%- else %} | |
| 367 throwArityTypeErrorForMethod("{{method.name}}", "{{interface_name}}", {{valid_ar ities}}, info.Length(), info.GetIsolate()) | |
| 368 {%- endif %} | |
| 369 {%- endif %}{# methods.idl_type == 'Promise' #} | |
| 370 {% endmacro %} | |
| 371 | 360 |
| 372 | 361 |
| 373 {######################################} | 362 {######################################} |
| 374 {% macro throw_minimum_arity_type_error(method, number_of_required_arguments) %} | 363 {% macro throw_minimum_arity_type_error(method, number_of_required_arguments) %} |
| 364 {% if method.has_exception_state %} | |
| 365 setMinimumArityTypeError(exceptionState, {{number_of_required_arguments}}, info. Length()); | |
| 366 {{throw_from_exception_state(method)}}; | |
| 367 {%- else %} | |
|
Jens Widell
2014/08/12 08:42:26
Nit: Could use elif here, I suppose.
yhirano
2014/08/12 09:36:09
Done.
| |
| 375 {% if method.idl_type == 'Promise' %} | 368 {% if method.idl_type == 'Promise' %} |
| 376 {% if method.has_exception_state %} | 369 v8SetReturnValue(info, ScriptPromise::rejectRaw(info.GetIsolate(), {{create_mini mum_arity_type_error_without_exception_state(method, number_of_required_argument s)}})); |
| 377 v8SetReturnValue(info, ScriptPromise::rejectWithMinimumArityTypeError(ScriptStat e::current(info.GetIsolate()), exceptionState, {{number_of_required_arguments}}, info.Length()).v8Value()) | |
| 378 {%- elif method.is_constructor %} | |
| 379 v8SetReturnValue(info, ScriptPromise::rejectWithMinimumArityTypeErrorForConstruc tor(ScriptState::current(info.GetIsolate()), "{{interface_name}}", {{number_of_r equired_arguments}}, info.Length()).v8Value()) | |
| 380 {%- else %} | 370 {%- else %} |
| 381 v8SetReturnValue(info, ScriptPromise::rejectWithMinimumArityTypeErrorForMethod(S criptState::current(info.GetIsolate()), "{{method.name}}", "{{interface_name}}", {{number_of_required_arguments}}, info.Length()).v8Value()) | 371 V8ThrowException::throwException({{create_minimum_arity_type_error_without_excep tion_state(method, number_of_required_arguments)}}, info.GetIsolate()); |
| 382 {%- endif %} | 372 {%- endif %}{# method.idl_type == 'Promise' #} |
| 383 {%- else %}{# methods.idl_type == 'Promise' #} | 373 {%- endif %}{# method.has_exception_state #} |
| 384 {% if method.has_exception_state %} | 374 {%- endmacro %} |
| 385 throwMinimumArityTypeError(exceptionState, {{number_of_required_arguments}}, inf o.Length()) | |
| 386 {%- elif method.is_constructor %} | |
| 387 throwMinimumArityTypeErrorForConstructor("{{interface_name}}", {{number_of_requi red_arguments}}, info.Length(), info.GetIsolate()) | |
| 388 {%- else %} | |
| 389 throwMinimumArityTypeErrorForMethod("{{method.name}}", "{{interface_name}}", {{n umber_of_required_arguments}}, info.Length(), info.GetIsolate()) | |
| 390 {%- endif %} | |
| 391 {%- endif %}{# methods.idl_type == 'Promise' #} | |
| 392 {% endmacro %} | |
| 393 | 375 |
| 394 | 376 |
| 395 {##############################################################################} | 377 {##############################################################################} |
| 378 {# FIXME: We should return a rejected Promise if an error occurs in this | |
| 379 function when ALL methods in this overload return Promise. In order to do so, | |
| 380 we must ensure either ALL or NO methods in this overload return Promise #} | |
| 396 {% macro overload_resolution_method(overloads, world_suffix) %} | 381 {% macro overload_resolution_method(overloads, world_suffix) %} |
| 397 static void {{overloads.name}}Method{{world_suffix}}(const v8::FunctionCallbackI nfo<v8::Value>& info) | 382 static void {{overloads.name}}Method{{world_suffix}}(const v8::FunctionCallbackI nfo<v8::Value>& info) |
| 398 { | 383 { |
| 399 ExceptionState exceptionState(ExceptionState::ExecutionContext, "{{overloads .name}}", "{{interface_name}}", info.Holder(), info.GetIsolate()); | 384 ExceptionState exceptionState(ExceptionState::ExecutionContext, "{{overloads .name}}", "{{interface_name}}", info.Holder(), info.GetIsolate()); |
| 400 {% if overloads.measure_all_as %} | 385 {% if overloads.measure_all_as %} |
| 401 UseCounter::count(callingExecutionContext(info.GetIsolate()), UseCounter::{{ overloads.measure_all_as}}); | 386 UseCounter::count(callingExecutionContext(info.GetIsolate()), UseCounter::{{ overloads.measure_all_as}}); |
| 402 {% endif %} | 387 {% endif %} |
| 403 {% if overloads.deprecate_all_as %} | 388 {% if overloads.deprecate_all_as %} |
| 404 UseCounter::countDeprecation(callingExecutionContext(info.GetIsolate()), Use Counter::{{overloads.deprecate_all_as}}); | 389 UseCounter::countDeprecation(callingExecutionContext(info.GetIsolate()), Use Counter::{{overloads.deprecate_all_as}}); |
| 405 {% endif %} | 390 {% endif %} |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 426 } | 411 } |
| 427 {% endfilter %} | 412 {% endfilter %} |
| 428 {% endfor %} | 413 {% endfor %} |
| 429 break; | 414 break; |
| 430 {% endfor %} | 415 {% endfor %} |
| 431 default: | 416 default: |
| 432 {# Invalid arity, throw error #} | 417 {# Invalid arity, throw error #} |
| 433 {# Report full list of valid arities if gaps and above minimum #} | 418 {# Report full list of valid arities if gaps and above minimum #} |
| 434 {% if overloads.valid_arities %} | 419 {% if overloads.valid_arities %} |
| 435 if (info.Length() >= {{overloads.minarg}}) { | 420 if (info.Length() >= {{overloads.minarg}}) { |
| 436 throwArityTypeError(exceptionState, "{{overloads.valid_arities}}", i nfo.Length()); | 421 setArityTypeError(exceptionState, "{{overloads.valid_arities}}", inf o.Length()); |
| 422 exceptionState.throwIfNeeded(); | |
| 437 return; | 423 return; |
| 438 } | 424 } |
| 439 {% endif %} | 425 {% endif %} |
| 440 {# Otherwise just report "not enough arguments" #} | 426 {# Otherwise just report "not enough arguments" #} |
| 441 exceptionState.throwTypeError(ExceptionMessages::notEnoughArguments({{ov erloads.minarg}}, info.Length())); | 427 exceptionState.throwTypeError(ExceptionMessages::notEnoughArguments({{ov erloads.minarg}}, info.Length())); |
| 442 exceptionState.throwIfNeeded(); | 428 exceptionState.throwIfNeeded(); |
| 443 return; | 429 return; |
| 444 } | 430 } |
| 445 {# No match, throw error #} | 431 {# No match, throw error #} |
| 446 exceptionState.throwTypeError("No function was found that matched the signat ure provided."); | 432 exceptionState.throwTypeError("No function was found that matched the signat ure provided."); |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 607 v8SetReturnValue(info, info.Holder()); | 593 v8SetReturnValue(info, info.Holder()); |
| 608 return; | 594 return; |
| 609 } | 595 } |
| 610 {% endif %} | 596 {% endif %} |
| 611 {% if constructor.has_exception_state %} | 597 {% if constructor.has_exception_state %} |
| 612 ExceptionState exceptionState(ExceptionState::ConstructionContext, "{{interf ace_name}}", info.Holder(), info.GetIsolate()); | 598 ExceptionState exceptionState(ExceptionState::ConstructionContext, "{{interf ace_name}}", info.Holder(), info.GetIsolate()); |
| 613 {% endif %} | 599 {% endif %} |
| 614 {# Overloaded constructors have length checked during overload resolution #} | 600 {# Overloaded constructors have length checked during overload resolution #} |
| 615 {% if constructor.number_of_required_arguments and not constructor.overload_ index %} | 601 {% if constructor.number_of_required_arguments and not constructor.overload_ index %} |
| 616 if (UNLIKELY(info.Length() < {{constructor.number_of_required_arguments}})) { | 602 if (UNLIKELY(info.Length() < {{constructor.number_of_required_arguments}})) { |
| 617 {{throw_minimum_arity_type_error(constructor, constructor.number_of_requ ired_arguments)}}; | 603 {{throw_minimum_arity_type_error(constructor, constructor.number_of_requ ired_arguments) | indent(8)}} |
| 618 return; | 604 return; |
| 619 } | 605 } |
| 620 {% endif %} | 606 {% endif %} |
| 621 {% if constructor.arguments %} | 607 {% if constructor.arguments %} |
| 622 {{generate_arguments(constructor) | indent}} | 608 {{generate_arguments(constructor) | indent}} |
| 623 {% endif %} | 609 {% endif %} |
| 624 {{cpp_method_call(constructor, constructor.v8_set_return_value, constructor. cpp_value) | indent}} | 610 {{cpp_method_call(constructor, constructor.v8_set_return_value, constructor. cpp_value) | indent}} |
| 625 } | 611 } |
| 626 {% endmacro %} | 612 {% endmacro %} |
| 627 | 613 |
| 628 | 614 |
| 629 {##############################################################################} | 615 {##############################################################################} |
| 630 {% macro generate_constructor_wrapper(constructor) %} | 616 {% macro generate_constructor_wrapper(constructor) %} |
| 631 {% if has_custom_wrap %} | 617 {% if has_custom_wrap %} |
| 632 v8::Handle<v8::Object> wrapper = wrap(impl.get(), info.Holder(), info.GetIsolate ()); | 618 v8::Handle<v8::Object> wrapper = wrap(impl.get(), info.Holder(), info.GetIsolate ()); |
| 633 {% else %} | 619 {% else %} |
| 634 {% set constructor_class = v8_class + ('Constructor' | 620 {% set constructor_class = v8_class + ('Constructor' |
| 635 if constructor.is_named_constructor else | 621 if constructor.is_named_constructor else |
| 636 '') %} | 622 '') %} |
| 637 v8::Handle<v8::Object> wrapper = info.Holder(); | 623 v8::Handle<v8::Object> wrapper = info.Holder(); |
| 638 V8DOMWrapper::associateObjectWithWrapper<{{v8_class}}>(impl.release(), &{{constr uctor_class}}::wrapperTypeInfo, wrapper, info.GetIsolate(), {{wrapper_configurat ion}}); | 624 V8DOMWrapper::associateObjectWithWrapper<{{v8_class}}>(impl.release(), &{{constr uctor_class}}::wrapperTypeInfo, wrapper, info.GetIsolate(), {{wrapper_configurat ion}}); |
| 639 {% endif %} | 625 {% endif %} |
| 640 v8SetReturnValue(info, wrapper); | 626 v8SetReturnValue(info, wrapper); |
| 641 {% endmacro %} | 627 {% endmacro %} |
| OLD | NEW |