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

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

Issue 460923002: Decouple arity errors creation from throwing. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 4 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 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 291 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 v8SetReturnValueNull(info); 315 v8SetReturnValueNull(info);
316 {% endmacro %} 316 {% endmacro %}
317 317
318 318
319 {######################################} 319 {######################################}
320 {% macro throw_type_error(method, error_message) %} 320 {% macro throw_type_error(method, error_message) %}
321 {% if method.has_exception_state %} 321 {% if method.has_exception_state %}
322 exceptionState.throwTypeError({{error_message}}); 322 exceptionState.throwTypeError({{error_message}});
323 {{throw_from_exception_state(method)}}; 323 {{throw_from_exception_state(method)}};
324 {% elif method.is_constructor %} 324 {% elif method.is_constructor %}
325 {% if method.idl_type == 'Promise' %} 325 {% if method.idl_type == 'Promise' %}
Jens Widell 2014/08/12 07:18:03 This if/else block is repeated twice in this macro
yhirano 2014/08/12 07:43:19 Done.
Jens Widell 2014/08/12 08:42:26 I meant the "if promise, set return value, else th
326 {# FIXME: reduce code duplication between sync / async exception handling. #} 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()); 327 v8SetReturnValue(info, ScriptPromise::rejecRaw(info.GetIsolate(), V8ThrowExcepti on::createTypeError(ExceptionMessages::failedToConstruct("{{interface_name}}", { {error_message}}), info.GetIsolate())));
328 {% else %} 328 {% else %}
329 V8ThrowException::throwTypeError(ExceptionMessages::failedToConstruct("{{interfa ce_name}}", {{error_message}}), info.GetIsolate()); 329 V8ThrowException::throwTypeError(ExceptionMessages::failedToConstruct("{{interfa ce_name}}", {{error_message}}), info.GetIsolate());
330 {% endif %} 330 {% endif %}
331 {% else %}{# method.has_exception_state #} 331 {% else %}{# method.has_exception_state #}
332 {% if method.idl_type == 'Promise' %} 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()); 333 v8SetReturnValue(info, ScriptPromise::rejectRaw(info.GetIsolate(), V8ThrowExcept ion::createTypeError(ExceptionMessages::failedToExecute("{{method.name}}", "{{in terface_name}}", {{error_message}}), info.GetIsolate())));
334 {% else %} 334 {% else %}
335 V8ThrowException::throwTypeError(ExceptionMessages::failedToExecute("{{method.na me}}", "{{interface_name}}", {{error_message}}), info.GetIsolate()); 335 V8ThrowException::throwTypeError(ExceptionMessages::failedToExecute("{{method.na me}}", "{{interface_name}}", {{error_message}}), info.GetIsolate());
336 {% endif %} 336 {% endif %}
337 {% endif %}{# method.has_exception_state #} 337 {% endif %}{# method.has_exception_state #}
338 {% endmacro %} 338 {% endmacro %}
339 339
340 340
341 {######################################} 341 {######################################}
342 {% macro throw_from_exception_state(method) %} 342 {% macro throw_from_exception_state(method) %}
343 {% if method.idl_type == 'Promise' %} 343 {% if method.idl_type == 'Promise' %}
344 v8SetReturnValue(info, exceptionState.reject(ScriptState::current(info.GetIsolat e())).v8Value()) 344 v8SetReturnValue(info, exceptionState.reject(ScriptState::current(info.GetIsolat e())).v8Value())
345 {%- else %} 345 {%- else %}
346 exceptionState.throwIfNeeded() 346 exceptionState.throwIfNeeded()
347 {%- endif %} 347 {%- endif %}
348 {%- endmacro %} 348 {%- endmacro %}
349 349
350 350
351 {######################################} 351 {######################################}
352 {% macro throw_arity_type_error(method, valid_arities) %} 352 {% macro create_minimum_arity_type_error_without_exception_state(method, number_ of_required_arguments) %}
353 {% if method.idl_type == 'Promise' %} 353 {% if method.is_constructor %}
354 {% if method.has_exception_state %} 354 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 %} 355 {%- else %}
359 v8SetReturnValue(info, ScriptPromise::rejectWithArityTypeErrorForMethod(ScriptSt ate::current(info.GetIsolate()), "{{method.name}}", "{{interface_name}}", {{vali d_arities}}, info.Length()).v8Value()) 356 createMinimumArityTypeErrorForMethod("{{method.name}}", "{{interface_name}}", {{ number_of_required_arguments}}, info.Length(), info.GetIsolate())
360 {%- endif %} 357 {%- endif %}
361 {%- else %}{# methods.idl_type == 'Promise' #} 358 {%- 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 359
372 360
373 {######################################} 361 {######################################}
374 {% macro throw_minimum_arity_type_error(method, number_of_required_arguments) %} 362 {% macro throw_minimum_arity_type_error(method, number_of_required_arguments) %}
363 {% if method.has_exception_state %}
364 setMinimumArityTypeError(exceptionState, {{number_of_required_arguments}}, info. Length());
365 {{throw_from_exception_state(method)}};
366 {%- else %}
375 {% if method.idl_type == 'Promise' %} 367 {% if method.idl_type == 'Promise' %}
376 {% if method.has_exception_state %} 368 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 %} 369 {%- else %}
381 v8SetReturnValue(info, ScriptPromise::rejectWithMinimumArityTypeErrorForMethod(S criptState::current(info.GetIsolate()), "{{method.name}}", "{{interface_name}}", {{number_of_required_arguments}}, info.Length()).v8Value()) 370 V8ThrowException::throwException({{create_minimum_arity_type_error_without_excep tion_state(method, number_of_required_arguments)}}, info.GetIsolate());
382 {%- endif %} 371 {%- endif %}{# method.idl_type == 'Promise' #}
383 {%- else %}{# methods.idl_type == 'Promise' #} 372 {%- endif %}{# method.has_exception_state #}
384 {% if method.has_exception_state %} 373 {%- 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 374
394 375
395 {##############################################################################} 376 {##############################################################################}
396 {% macro overload_resolution_method(overloads, world_suffix) %} 377 {% macro overload_resolution_method(overloads, world_suffix) %}
397 static void {{overloads.name}}Method{{world_suffix}}(const v8::FunctionCallbackI nfo<v8::Value>& info) 378 static void {{overloads.name}}Method{{world_suffix}}(const v8::FunctionCallbackI nfo<v8::Value>& info)
398 { 379 {
399 ExceptionState exceptionState(ExceptionState::ExecutionContext, "{{overloads .name}}", "{{interface_name}}", info.Holder(), info.GetIsolate()); 380 ExceptionState exceptionState(ExceptionState::ExecutionContext, "{{overloads .name}}", "{{interface_name}}", info.Holder(), info.GetIsolate());
400 {% if overloads.measure_all_as %} 381 {% if overloads.measure_all_as %}
401 UseCounter::count(callingExecutionContext(info.GetIsolate()), UseCounter::{{ overloads.measure_all_as}}); 382 UseCounter::count(callingExecutionContext(info.GetIsolate()), UseCounter::{{ overloads.measure_all_as}});
402 {% endif %} 383 {% endif %}
(...skipping 23 matching lines...) Expand all
426 } 407 }
427 {% endfilter %} 408 {% endfilter %}
428 {% endfor %} 409 {% endfor %}
429 break; 410 break;
430 {% endfor %} 411 {% endfor %}
431 default: 412 default:
432 {# Invalid arity, throw error #} 413 {# Invalid arity, throw error #}
433 {# Report full list of valid arities if gaps and above minimum #} 414 {# Report full list of valid arities if gaps and above minimum #}
434 {% if overloads.valid_arities %} 415 {% if overloads.valid_arities %}
435 if (info.Length() >= {{overloads.minarg}}) { 416 if (info.Length() >= {{overloads.minarg}}) {
436 throwArityTypeError(exceptionState, "{{overloads.valid_arities}}", i nfo.Length()); 417 {# FIXME: We should return a rejected Promise here and the
Jens Widell 2014/08/12 07:18:03 This FIXME applies to the code immediately followi
yhirano 2014/08/12 07:43:19 This function has three blocks and all should be a
418 the following throwIfNeeded when ALL methods return Promise. In
419 order to do so, we must ensure either ALL or NO methods in this
420 overload return Promise #}
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
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 %}
OLDNEW
« no previous file with comments | « Source/bindings/modules/v8/custom/V8SubtleCryptoCustom.cpp ('k') | Source/bindings/tests/results/V8TestInterface.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698