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

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

Issue 337343002: IDL: make optional arguments (without default) explicit sometimes Base URL: https://chromium.googlesource.com/chromium/blink.git@idl-default-arguments-next
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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/bindings/scripts/v8_types.py ('k') | Source/bindings/tests/idls/TestInterfaceConstructor.idl » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/bindings/templates/methods.cpp
diff --git a/Source/bindings/templates/methods.cpp b/Source/bindings/templates/methods.cpp
index e33041bb0a4df4aa0bb441c9ceda7aa41767648e..85bb19408844248a99a4a1b59a5838013e6c0ebd 100644
--- a/Source/bindings/templates/methods.cpp
+++ b/Source/bindings/templates/methods.cpp
@@ -61,19 +61,23 @@ static void {{method.name}}{{method.overload_index}}Method{{world_suffix}}(const
{######################################}
{% macro generate_arguments(method, world_suffix) %}
{% for argument in method.arguments %}
-{{generate_argument_var_declaration(argument)}};
-{% endfor %}
+{{generate_argument_var_declaration(argument)}}
+{%- endfor %}
{
{% if method.arguments_need_try_catch %}
v8::TryCatch block;
V8RethrowTryCatchScope rethrow(block);
{% endif %}
{% for argument in method.arguments %}
- {% if argument.default_value %}
+ {% if argument.is_optional %}
if (!info[{{argument.index}}]->IsUndefined()) {
{{generate_argument(method, argument, world_suffix) | indent(8)}}
} else {
+ {% if argument.default_value %}
{{argument.name}} = {{argument.default_value}};
+ {% else %}
+ {{argument.name}}Missing = true;
+ {% endif %}
}
{% else %}
{{generate_argument(method, argument, world_suffix) | indent}}
@@ -88,39 +92,24 @@ static void {{method.name}}{{method.overload_index}}Method{{world_suffix}}(const
{% 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' #}
+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 %}
+{{argument.cpp_type}} {{argument.name}} = 0;
+{% else %}
+{{argument.cpp_type}} {{argument.name}}{% if argument.is_explicit_optional %}{{argument.cpp_type_initializer}}{% endif %};
+{% endif %}
+{% if argument.is_explicit_optional %}
+bool {{argument.name}}Missing = false;
+{% endif %}
+{%- endmacro %}
{######################################}
{% macro generate_argument(method, argument, world_suffix) %}
-{% if argument.is_optional and not argument.has_default and
- argument.idl_type != 'Dictionary' and
- not argument.is_callback_interface %}
-{# Optional arguments without a default value generate an early call with
- fewer arguments if they are omitted.
- Optional Dictionary arguments default to empty dictionary. #}
-if (UNLIKELY(info.Length() <= {{argument.index}})) {
- {% if world_suffix %}
- {{cpp_method_call(method, argument.v8_set_return_value_for_main_world, argument.cpp_value) | indent}}
- {% else %}
- {{cpp_method_call(method, argument.v8_set_return_value, argument.cpp_value) | indent}}
- {% endif %}
- {% if argument.has_event_listener_argument %}
- {{hidden_dependency_action(method.name) | indent}}
- {% endif %}
- return;
-}
-{% endif %}
{% if argument.has_type_checking_interface and not argument.is_variadic_wrapper_type %}
{# Type checking for wrapper interface types (if interface not implemented,
throw a TypeError), per http://www.w3.org/TR/WebIDL/#es-interface
« no previous file with comments | « Source/bindings/scripts/v8_types.py ('k') | Source/bindings/tests/idls/TestInterfaceConstructor.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698