Chromium Code Reviews| Index: Source/bindings/templates/methods.cpp |
| diff --git a/Source/bindings/templates/methods.cpp b/Source/bindings/templates/methods.cpp |
| index 4118aff639f575fc258dd2b13e78bbed9e10cf7f..97be8e0e7a279cabba23f75b9ed056f059c739e7 100644 |
| --- a/Source/bindings/templates/methods.cpp |
| +++ b/Source/bindings/templates/methods.cpp |
| @@ -24,7 +24,7 @@ static void {{method.name}}{{method.overload_index}}Method{{world_suffix}}(const |
| {% if interface_name == 'EventTarget' %} |
| if (DOMWindow* window = impl->toDOMWindow()) { |
| if (!BindingSecurity::shouldAllowAccessToFrame(info.GetIsolate(), window->frame(), exceptionState)) { |
| - exceptionState.throwIfNeeded(); |
| + {{throw_from_exception_state(method) | indent}} |
|
Nils Barth (inactive)
2014/04/10 07:48:03
No indent here (it's a 1-line macro, right), and '
yhirano
2014/04/11 10:19:04
Done.
|
| return; |
| } |
| if (!window->document()) |
| @@ -32,14 +32,14 @@ static void {{method.name}}{{method.overload_index}}Method{{world_suffix}}(const |
| } |
| {% elif method.is_check_security_for_frame %} |
| if (!BindingSecurity::shouldAllowAccessToFrame(info.GetIsolate(), impl->frame(), exceptionState)) { |
| - exceptionState.throwIfNeeded(); |
| + {{throw_from_exception_state(method) | indent}} |
|
Nils Barth (inactive)
2014/04/10 07:48:03
no indent, ; at call
yhirano
2014/04/11 10:19:04
Done.
|
| return; |
| } |
| {% endif %} |
| {% if method.is_check_security_for_node %} |
| if (!BindingSecurity::shouldAllowAccessToNode(info.GetIsolate(), impl->{{method.name}}(exceptionState), exceptionState)) { |
| v8SetReturnValueNull(info); |
| - exceptionState.throwIfNeeded(); |
| + {{throw_from_exception_state(method) | indent}} |
|
Nils Barth (inactive)
2014/04/10 07:48:03
no indent, ; at call
yhirano
2014/04/11 10:19:04
Done.
|
| return; |
| } |
| {% endif %} |
| @@ -134,15 +134,21 @@ OwnPtr<{{argument.idl_type}}> {{argument.name}} = {% if argument.is_nullable %}i |
| {% elif argument.is_clamp %}{# argument.is_callback_interface #} |
| {# NaN is treated as 0: http://www.w3.org/TR/WebIDL/#es-type-mapping #} |
| {{argument.cpp_type}} {{argument.name}} = 0; |
| +{% if method.idl_type == 'Promise' %} |
| +V8TRYCATCH_VOID_PROMISE(double, {{argument.name}}NativeValue, info[{{argument.index}}]->NumberValue(), info); |
| +{% else %} |
| V8TRYCATCH_VOID(double, {{argument.name}}NativeValue, info[{{argument.index}}]->NumberValue()); |
| +{% endif %} |
| if (!std::isnan({{argument.name}}NativeValue)) |
| {# IDL type is used for clamping, for the right bounds, since different |
| IDL integer types have same internal C++ type (int or unsigned) #} |
| {{argument.name}} = clampTo<{{argument.idl_type}}>({{argument.name}}NativeValue); |
| {% elif argument.idl_type == 'SerializedScriptValue' %} |
| {{argument.cpp_type}} {{argument.name}} = SerializedScriptValue::create(info[{{argument.index}}], 0, 0, exceptionState, info.GetIsolate()); |
| -if (exceptionState.throwIfNeeded()) |
| +if (exceptionState.hadException()) { |
| + {{throw_from_exception_state(method) | indent}} |
| return; |
| +} |
| {% elif argument.is_variadic_wrapper_type %} |
| {{argument.vector_type}}<{{argument.cpp_type}} > {{argument.name}}; |
| for (int i = {{argument.index}}; i < info.Length(); ++i) { |
| @@ -154,8 +160,12 @@ for (int i = {{argument.index}}; i < info.Length(); ++i) { |
| {{argument.name}}.append(V8{{argument.idl_type}}::toNative(v8::Handle<v8::Object>::Cast(info[i]))); |
| } |
| {% else %} |
| +{% if method.idl_type == 'Promise' %} |
| +{{argument.v8_value_to_local_cpp_value_async}}; |
| +{% else %} |
| {{argument.v8_value_to_local_cpp_value}}; |
| {% endif %} |
| +{% endif %} |
| {% if argument.enum_validation_expression %} |
| {# Methods throw on invalid enum values: http://www.w3.org/TR/WebIDL/#idl-enums #} |
| String string = {{argument.name}}; |
| @@ -206,8 +216,10 @@ RefPtr<ScriptArguments> scriptArguments(createScriptArguments(info, {{method.num |
| {% endif %} |
| {# Post-call #} |
| {% if method.is_raises_exception %} |
| -if (exceptionState.throwIfNeeded()) |
| +if (exceptionState.hadException()) { |
| + {{throw_from_exception_state(method) | indent}} |
| return; |
| +} |
| {% endif %} |
| {# Set return value #} |
| {% if method.union_arguments %} |
| @@ -242,17 +254,42 @@ v8SetReturnValueNull(info); |
| {% macro throw_type_error(method, error_message) %} |
| {% if method.has_exception_state %} |
| exceptionState.throwTypeError({{error_message}}); |
| -exceptionState.throwIfNeeded(); |
| +{{throw_from_exception_state(method)}} |
| {%- elif method.is_constructor %} |
| +{% if method.idl_type == 'Promise' %} |
| +v8SetReturnValue(info, ScriptPromise::rejectWithTypeError(ExceptionMessages::failedToConstruct("{{interface_name}}", {{error_message}}), info.GetIsolate()).v8Value()); |
| +{%- else %} |
| throwTypeError(ExceptionMessages::failedToConstruct("{{interface_name}}", {{error_message}}), info.GetIsolate()); |
| +{%- endif %}{# if method.idl_type == 'Promise' #} |
| +{%- else %} |
| +{% if method.idl_type == 'Promise' %} |
| +v8SetReturnValue(info, ScriptPromise::rejectWithTypeError(ExceptionMessages::failedToExecute("{{method.name}}", "{{interface_name}}", {{error_message}}), info.GetIsolate()).v8Value()); |
| {%- else %} |
| throwTypeError(ExceptionMessages::failedToExecute("{{method.name}}", "{{interface_name}}", {{error_message}}), info.GetIsolate()); |
| +{%- endif %}{# if method.idl_type == 'Promise' #} |
| {%- endif %} |
| {% endmacro %} |
|
Nils Barth (inactive)
2014/04/10 07:48:03
2 lines between macros
yhirano
2014/04/11 10:19:04
Done.
|
| +{######################################} |
| +{% macro throw_from_exception_state(method) %} |
| +{% if method.idl_type == 'Promise' %} |
| +v8SetReturnValue(info, exceptionState.rejectedPromise().v8Value()); |
| +{%- else %} |
| +exceptionState.throwIfNeeded(); |
| +{%- endif %} |
| +{% endmacro %} |
|
Nils Barth (inactive)
2014/04/10 07:48:03
2 lines between macros
yhirano
2014/04/11 10:19:04
Done.
|
| {######################################} |
| {% macro throw_arity_type_error(method, number_of_required_arguments) %} |
| +{% if method.idl_type == 'Promise' %} |
| +{% if method.has_exception_state %} |
| +v8SetReturnValue(info, ScriptPromise::rejectWithArityTypeError(exceptionState, {{number_of_required_arguments}}, info.Length()).v8Value()) |
| +{%- elif method.is_constructor %} |
| +v8SetReturnValue(info, ScriptPromise::rejectWithArityTypeErrorForConstructor("{{interface_name}}", {{number_of_required_arguments}}, info.Length(), info.GetIsolate().v8Value()) |
| +{%- else %} |
| +v8SetReturnValue(info, ScriptPromise::rejectWithArityTypeErrorForMethod("{{method.name}}", "{{interface_name}}", {{number_of_required_arguments}}, info.Length(), info.GetIsolate()).v8Value()) |
| +{%- endif %} |
| +{%- else %} |
| {% if method.has_exception_state %} |
| throwArityTypeError(exceptionState, {{number_of_required_arguments}}, info.Length()) |
| {%- elif method.is_constructor %} |
| @@ -260,6 +297,7 @@ throwArityTypeErrorForConstructor("{{interface_name}}", {{number_of_required_arg |
| {%- else %} |
| throwArityTypeErrorForMethod("{{method.name}}", "{{interface_name}}", {{number_of_required_arguments}}, info.Length(), info.GetIsolate()) |
| {%- endif %} |
| +{%- endif %} |
| {% endmacro %} |