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

Side by Side 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 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 #}
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 {{cpp_method_call(method, method.v8_set_return_value, method.cpp_value) | in dent}} 54 {{cpp_method_call(method, method.v8_set_return_value, method.cpp_value) | in dent}}
55 {% endif %} 55 {% endif %}
56 } 56 }
57 {% endfilter %} 57 {% endfilter %}
58 {% endmacro %} 58 {% endmacro %}
59 59
60 60
61 {######################################} 61 {######################################}
62 {% macro generate_arguments(method, world_suffix) %} 62 {% macro generate_arguments(method, world_suffix) %}
63 {% for argument in method.arguments %} 63 {% for argument in method.arguments %}
64 {{generate_argument_var_declaration(argument)}}; 64 {{generate_argument_var_declaration(argument)}}
65 {% endfor %} 65 {%- endfor %}
66 { 66 {
67 {% if method.arguments_need_try_catch %} 67 {% if method.arguments_need_try_catch %}
68 v8::TryCatch block; 68 v8::TryCatch block;
69 V8RethrowTryCatchScope rethrow(block); 69 V8RethrowTryCatchScope rethrow(block);
70 {% endif %} 70 {% endif %}
71 {% for argument in method.arguments %} 71 {% for argument in method.arguments %}
72 {% if argument.default_value %} 72 {% if argument.is_optional %}
73 if (!info[{{argument.index}}]->IsUndefined()) { 73 if (!info[{{argument.index}}]->IsUndefined()) {
74 {{generate_argument(method, argument, world_suffix) | indent(8)}} 74 {{generate_argument(method, argument, world_suffix) | indent(8)}}
75 } else { 75 } else {
76 {% if argument.default_value %}
76 {{argument.name}} = {{argument.default_value}}; 77 {{argument.name}} = {{argument.default_value}};
78 {% else %}
79 {{argument.name}}Missing = true;
80 {% endif %}
77 } 81 }
78 {% else %} 82 {% else %}
79 {{generate_argument(method, argument, world_suffix) | indent}} 83 {{generate_argument(method, argument, world_suffix) | indent}}
80 {% endif %} 84 {% endif %}
81 {% endfor %} 85 {% endfor %}
82 } 86 }
83 {% endmacro %} 87 {% endmacro %}
84 88
85 89
86 {######################################} 90 {######################################}
87 {% macro generate_argument_var_declaration(argument) %} 91 {% macro generate_argument_var_declaration(argument) %}
88 {% if argument.is_callback_interface %} 92 {% if argument.is_callback_interface %}
89 {# FIXME: remove EventListener special case #} 93 {# FIXME: remove EventListener special case #}
90 {% if argument.idl_type == 'EventListener' %} 94 {% if argument.idl_type == 'EventListener' %}
91 RefPtr<{{argument.idl_type}}> {{argument.name}} 95 RefPtr<{{argument.idl_type}}> {{argument.name}};
92 {%- else %} 96 {% else %}
93 OwnPtr<{{argument.idl_type}}> {{argument.name}} 97 OwnPtr<{{argument.idl_type}}> {{argument.name}};
94 {%- endif %}{# argument.idl_type == 'EventListener' #} 98 {% endif %}{# argument.idl_type == 'EventListener' #}
95 {%- elif argument.is_clamp %}{# argument.is_callback_interface #} 99 {%- elif argument.is_clamp %}{# argument.is_callback_interface #}
96 {# NaN is treated as 0: http://www.w3.org/TR/WebIDL/#es-type-mapping #} 100 {# NaN is treated as 0: http://www.w3.org/TR/WebIDL/#es-type-mapping #}
97 {{argument.cpp_type}} {{argument.name}} = 0 101 {{argument.cpp_type}} {{argument.name}} = 0;
98 {%- else %} 102 {% else %}
99 {{argument.cpp_type}} {{argument.name}} 103 {{argument.cpp_type}} {{argument.name}}{% if argument.is_explicit_optional %}{{a rgument.cpp_type_initializer}}{% endif %};
100 {%- endif %} 104 {% endif %}
101 {% endmacro %} 105 {% if argument.is_explicit_optional %}
106 bool {{argument.name}}Missing = false;
107 {% endif %}
108 {%- endmacro %}
102 109
103 110
104 {######################################} 111 {######################################}
105 {% macro generate_argument(method, argument, world_suffix) %} 112 {% macro generate_argument(method, argument, world_suffix) %}
106 {% if argument.is_optional and not argument.has_default and
107 argument.idl_type != 'Dictionary' and
108 not argument.is_callback_interface %}
109 {# Optional arguments without a default value generate an early call with
110 fewer arguments if they are omitted.
111 Optional Dictionary arguments default to empty dictionary. #}
112 if (UNLIKELY(info.Length() <= {{argument.index}})) {
113 {% if world_suffix %}
114 {{cpp_method_call(method, argument.v8_set_return_value_for_main_world, argum ent.cpp_value) | indent}}
115 {% else %}
116 {{cpp_method_call(method, argument.v8_set_return_value, argument.cpp_value) | indent}}
117 {% endif %}
118 {% if argument.has_event_listener_argument %}
119 {{hidden_dependency_action(method.name) | indent}}
120 {% endif %}
121 return;
122 }
123 {% endif %}
124 {% if argument.has_type_checking_interface and not argument.is_variadic_wrapper_ type %} 113 {% if argument.has_type_checking_interface and not argument.is_variadic_wrapper_ type %}
125 {# Type checking for wrapper interface types (if interface not implemented, 114 {# Type checking for wrapper interface types (if interface not implemented,
126 throw a TypeError), per http://www.w3.org/TR/WebIDL/#es-interface 115 throw a TypeError), per http://www.w3.org/TR/WebIDL/#es-interface
127 Note: for variadic arguments, the type checking is done for each matched 116 Note: for variadic arguments, the type checking is done for each matched
128 argument instead; see argument.is_variadic_wrapper_type code-path below. #} 117 argument instead; see argument.is_variadic_wrapper_type code-path below. #}
129 if (info.Length() > {{argument.index}} && {% if argument.is_nullable %}!isUndefi nedOrNull(info[{{argument.index}}]) && {% endif %}!V8{{argument.idl_type}}::hasI nstance(info[{{argument.index}}], info.GetIsolate())) { 118 if (info.Length() > {{argument.index}} && {% if argument.is_nullable %}!isUndefi nedOrNull(info[{{argument.index}}]) && {% endif %}!V8{{argument.idl_type}}::hasI nstance(info[{{argument.index}}], info.GetIsolate())) {
130 {{throw_type_error(method, '"parameter %s is not of type \'%s\'."' % 119 {{throw_type_error(method, '"parameter %s is not of type \'%s\'."' %
131 (argument.index + 1, argument.idl_type)) | indent }} 120 (argument.index + 1, argument.idl_type)) | indent }}
132 return; 121 return;
133 } 122 }
(...skipping 485 matching lines...) Expand 10 before | Expand all | Expand 10 after
619 v8::Handle<v8::Object> wrapper = wrap(impl.get(), info.Holder(), info.GetIsolate ()); 608 v8::Handle<v8::Object> wrapper = wrap(impl.get(), info.Holder(), info.GetIsolate ());
620 {% else %} 609 {% else %}
621 {% set constructor_class = v8_class + ('Constructor' 610 {% set constructor_class = v8_class + ('Constructor'
622 if constructor.is_named_constructor else 611 if constructor.is_named_constructor else
623 '') %} 612 '') %}
624 v8::Handle<v8::Object> wrapper = info.Holder(); 613 v8::Handle<v8::Object> wrapper = info.Holder();
625 V8DOMWrapper::associateObjectWithWrapper<{{v8_class}}>(impl.release(), &{{constr uctor_class}}::wrapperTypeInfo, wrapper, info.GetIsolate(), {{wrapper_configurat ion}}); 614 V8DOMWrapper::associateObjectWithWrapper<{{v8_class}}>(impl.release(), &{{constr uctor_class}}::wrapperTypeInfo, wrapper, info.GetIsolate(), {{wrapper_configurat ion}});
626 {% endif %} 615 {% endif %}
627 v8SetReturnValue(info, wrapper); 616 v8SetReturnValue(info, wrapper);
628 {% endmacro %} 617 {% endmacro %}
OLDNEW
« 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