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

Unified Diff: Source/bindings/templates/methods.cpp

Issue 265293004: Create fewer local v8::TryCatch objects in generated bindings code (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: Source/bindings/templates/methods.cpp
diff --git a/Source/bindings/templates/methods.cpp b/Source/bindings/templates/methods.cpp
index dc4c6c056086660b95067762469ad7af99ba2458..1ffbb528b9dfbf15cef96de661d38461dda9c7ef 100644
--- a/Source/bindings/templates/methods.cpp
+++ b/Source/bindings/templates/methods.cpp
@@ -44,9 +44,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 %}
@@ -73,6 +73,26 @@ if (listener && !impl->toNode())
{######################################}
Nils Barth (inactive) 2014/05/07 03:02:19 Could you rename this as generate_argument_var_dec
+{% macro generate_argument_var(argument) %}
Nils Barth (inactive) 2014/05/07 03:02:19 This is a one-line macro, so please put the ; at t
Jens Widell 2014/05/07 10:34:46 Thanks for the pointers! The white-space handling
Nils Barth (inactive) 2014/05/08 00:55:13 Jinja whitespace handling was the bane of my life
+{% 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;
+{% elif argument.is_variadic_wrapper_type %}
+{{argument.vector_type}}<{{argument.cpp_type}} > {{argument.name}};
+{% 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
@@ -100,20 +120,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(info[1], false, ListenerFindOnly);
+{{argument.name}} = V8EventListenerList::getEventListener(info[1], false, ListenerFindOnly);
{% else %}{# method.name == 'addEventListener' #}
-RefPtr<{{argument.idl_type}}> {{argument.name}} = V8EventListenerList::getEventListener(info[1], false, ListenerFindOrCreate);
+{{argument.name}} = V8EventListenerList::getEventListener(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,
@@ -123,30 +142,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}}]), currentExecutionContext(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}}]), currentExecutionContext(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}}]), currentExecutionContext(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_NO_DECL({{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\'."' %
@@ -193,6 +211,22 @@ if (!{{argument.name}}.isUndefinedOrNull() && !{{argument.name}}.isObject()) {
{######################################}
+{% macro generate_arguments(method, world_suffix) %}
Nils Barth (inactive) 2014/05/07 03:02:19 Could you move this *up* above the generate_argume
+{% for argument in method.arguments %}
+{{generate_argument_var(argument) | indent}}
Nils Barth (inactive) 2014/05/07 03:02:19 No |indent|, trailing ; here.
+{% 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 cpp_method_call(method, v8_set_return_value, cpp_value) %}
{# Local variables #}
{% if method.is_partial_interface_member and not method.is_static %}
@@ -407,9 +441,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 %}
Nils Barth (inactive) 2014/05/07 03:02:19 Could you move this {% if %} test into the generat
Jens Widell 2014/05/07 10:34:46 Would love to. One problem: I can't seem to figure
Nils Barth (inactive) 2014/05/08 00:55:13 Oh, good point (>.<) That's exactly the trickiest
+ {{generate_arguments(constructor) | indent}}
+ {% endif %}
{% if is_constructor_call_with_execution_context %}
ExecutionContext* context = currentExecutionContext(isolate);
{% endif %}
@@ -473,9 +507,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())

Powered by Google App Engine
This is Rietveld 408576698