| Index: Source/bindings/templates/methods.cpp
|
| diff --git a/Source/bindings/templates/methods.cpp b/Source/bindings/templates/methods.cpp
|
| index d567735d17e8287218d919600527b141c48b1dec..ac1df4c9eb1e37b8f2eb3ffc396178bea2225440 100644
|
| --- a/Source/bindings/templates/methods.cpp
|
| +++ b/Source/bindings/templates/methods.cpp
|
| @@ -45,9 +45,9 @@ static void {{method.name}}{{method.overload_index}}Method{{world_suffix}}(const
|
| }
|
| {% endif %}
|
| {# Call method #}
|
| - {% for argument in method.arguments %}
|
| - {{generate_argument(method, argument, world_suffix) | indent}}
|
| - {% endfor %}
|
| + {% if method.arguments %}
|
| + {{generate_arguments(method, world_suffix) | indent}}
|
| + {% endif %}
|
| {% if world_suffix %}
|
| {{cpp_method_call(method, method.v8_set_return_value_for_main_world, method.cpp_value) | indent}}
|
| {% else %}
|
| @@ -74,6 +74,40 @@ if (listener && !impl->toNode())
|
|
|
|
|
| {######################################}
|
| +{% macro generate_arguments(method, world_suffix) %}
|
| +{% for argument in method.arguments %}
|
| +{{generate_argument_var_declaration(argument)}};
|
| +{% endfor %}
|
| +{
|
| + {% if method.arguments_need_try_catch %}
|
| + v8::TryCatch block;
|
| + {% endif %}
|
| + {% for argument in method.arguments %}
|
| + {{generate_argument(method, argument, world_suffix) | indent}}
|
| + {% endfor %}
|
| +}
|
| +{% endmacro %}
|
| +
|
| +
|
| +{######################################}
|
| +{% macro generate_argument_var_declaration(argument) %}
|
| +{% if argument.is_callback_interface %}
|
| +{# FIXME: remove EventListener special case #}
|
| +{% if argument.idl_type == 'EventListener' %}
|
| +RefPtr<{{argument.idl_type}}> {{argument.name}}
|
| +{%- else %}
|
| +OwnPtr<{{argument.idl_type}}> {{argument.name}}
|
| +{%- endif %}{# argument.idl_type == 'EventListener' #}
|
| +{%- 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
|
| +{%- else %}
|
| +{{argument.cpp_type}} {{argument.name}}
|
| +{%- endif %}
|
| +{% endmacro %}
|
| +
|
| +
|
| +{######################################}
|
| {% macro generate_argument(method, argument, world_suffix) %}
|
| {% if argument.is_optional and not argument.has_default and
|
| argument.idl_type != 'Dictionary' and
|
| @@ -101,20 +135,19 @@ if (info.Length() > {{argument.index}} && {% if argument.is_nullable %}!isUndefi
|
| (argument.index + 1, argument.idl_type)) | indent}}
|
| return;
|
| }
|
| -{% endif %}
|
| +{% endif %}{# argument.has_type_checking_interface #}
|
| {% if argument.is_callback_interface %}
|
| {# FIXME: remove EventListener special case #}
|
| {% if argument.idl_type == 'EventListener' %}
|
| {% if method.name == 'removeEventListener' %}
|
| -RefPtr<{{argument.idl_type}}> {{argument.name}} = V8EventListenerList::getEventListener(ScriptState::current(info.GetIsolate()), info[1], false, ListenerFindOnly);
|
| +{{argument.name}} = V8EventListenerList::getEventListener(ScriptState::current(info.GetIsolate()), info[1], false, ListenerFindOnly);
|
| {% else %}{# method.name == 'addEventListener' #}
|
| -RefPtr<{{argument.idl_type}}> {{argument.name}} = V8EventListenerList::getEventListener(ScriptState::current(info.GetIsolate()), info[1], false, ListenerFindOrCreate);
|
| +{{argument.name}} = V8EventListenerList::getEventListener(ScriptState::current(info.GetIsolate()), info[1], false, ListenerFindOrCreate);
|
| {% endif %}{# method.name #}
|
| -{% else %}
|
| +{% else %}{# argument.idl_type == 'EventListener' #}
|
| {# Callback functions must be functions:
|
| http://www.w3.org/TR/WebIDL/#es-callback-function #}
|
| {% if argument.is_optional %}
|
| -OwnPtr<{{argument.idl_type}}> {{argument.name}};
|
| if (info.Length() > {{argument.index}} && !isUndefinedOrNull(info[{{argument.index}}])) {
|
| if (!info[{{argument.index}}]->IsFunction()) {
|
| {{throw_type_error(method,
|
| @@ -124,30 +157,29 @@ if (info.Length() > {{argument.index}} && !isUndefinedOrNull(info[{{argument.ind
|
| }
|
| {{argument.name}} = V8{{argument.idl_type}}::create(v8::Handle<v8::Function>::Cast(info[{{argument.index}}]), ScriptState::current(info.GetIsolate()));
|
| }
|
| -{% else %}
|
| +{% else %}{# argument.is_optional #}
|
| if (info.Length() <= {{argument.index}} || !{% if argument.is_nullable %}(info[{{argument.index}}]->IsFunction() || info[{{argument.index}}]->IsNull()){% else %}info[{{argument.index}}]->IsFunction(){% endif %}) {
|
| {{throw_type_error(method,
|
| '"The callback provided as parameter %s is not a function."' %
|
| (argument.index + 1)) | indent }}
|
| return;
|
| }
|
| -OwnPtr<{{argument.idl_type}}> {{argument.name}} = {% if argument.is_nullable %}info[{{argument.index}}]->IsNull() ? nullptr : {% endif %}V8{{argument.idl_type}}::create(v8::Handle<v8::Function>::Cast(info[{{argument.index}}]), ScriptState::current(info.GetIsolate()));
|
| +{{argument.name}} = {% if argument.is_nullable %}info[{{argument.index}}]->IsNull() ? nullptr : {% endif %}V8{{argument.idl_type}}::create(v8::Handle<v8::Function>::Cast(info[{{argument.index}}]), ScriptState::current(info.GetIsolate()));
|
| {% endif %}{# argument.is_optional #}
|
| {% endif %}{# argument.idl_type == 'EventListener' #}
|
| {% 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;
|
| -TONATIVE_VOID(double, {{argument.name}}NativeValue, info[{{argument.index}}]->NumberValue());
|
| +double {{argument.name}}NativeValue;
|
| +TONATIVE_VOID_INTERNAL({{argument.name}}NativeValue, info[{{argument.index}}]->NumberValue());
|
| 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());
|
| +{{argument.name}} = SerializedScriptValue::create(info[{{argument.index}}], 0, 0, exceptionState, info.GetIsolate());
|
| if (exceptionState.throwIfNeeded())
|
| return;
|
| {% elif argument.is_variadic_wrapper_type %}
|
| -{{argument.vector_type}}<{{argument.cpp_type}} > {{argument.name}};
|
| for (int i = {{argument.index}}; i < info.Length(); ++i) {
|
| if (!V8{{argument.idl_type}}::hasInstance(info[i], info.GetIsolate())) {
|
| {{throw_type_error(method, '"parameter %s is not of type \'%s\'."' %
|
| @@ -254,10 +286,13 @@ v8SetReturnValueNull(info);
|
| {% if method.has_exception_state %}
|
| exceptionState.throwTypeError({{error_message}});
|
| exceptionState.throwIfNeeded();
|
| -{%- elif method.is_constructor %}
|
| +{% elif method.is_constructor %}
|
| throwTypeError(ExceptionMessages::failedToConstruct("{{interface_name}}", {{error_message}}), info.GetIsolate());
|
| -{%- else %}
|
| +{% else %}
|
| throwTypeError(ExceptionMessages::failedToExecute("{{method.name}}", "{{interface_name}}", {{error_message}}), info.GetIsolate());
|
| +{% endif %}
|
| +{% if method.arguments_need_try_catch %}
|
| +block.ReThrow();
|
| {%- endif %}
|
| {% endmacro %}
|
|
|
| @@ -438,9 +473,9 @@ static void constructor{{constructor.overload_index}}(const v8::FunctionCallback
|
| return;
|
| }
|
| {% endif %}
|
| - {% for argument in constructor.arguments %}
|
| - {{generate_argument(constructor, argument) | indent}}
|
| - {% endfor %}
|
| + {% if constructor.arguments %}
|
| + {{generate_arguments(constructor) | indent}}
|
| + {% endif %}
|
| {% if is_constructor_call_with_execution_context %}
|
| ExecutionContext* context = currentExecutionContext(isolate);
|
| {% endif %}
|
| @@ -504,9 +539,9 @@ static void {{v8_class}}ConstructorCallback(const v8::FunctionCallbackInfo<v8::V
|
| return;
|
| }
|
| {% endif %}
|
| - {% for argument in constructor.arguments %}
|
| - {{generate_argument(constructor, argument) | indent}}
|
| - {% endfor %}
|
| + {% if constructor.arguments %}
|
| + {{generate_arguments(constructor) | indent}}
|
| + {% endif %}
|
| {{constructor.cpp_type}} impl = {{cpp_class}}::createForJSConstructor({{constructor.argument_list | join(', ')}});
|
| {% if is_constructor_raises_exception %}
|
| if (exceptionState.throwIfNeeded())
|
|
|