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

Side by Side Diff: Source/bindings/templates/methods.cpp

Issue 810563007: IDL: Add missing type-check for callback function arguments (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 11 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
« no previous file with comments | « Source/bindings/scripts/v8_methods.py ('k') | Source/bindings/tests/idls/core/TestObject.idl » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 {% else %}{# argument.is_optional #} 135 {% else %}{# argument.is_optional #}
136 if (info.Length() <= {{argument.index}} || !{% if argument.is_nullable %}(info[{ {argument.index}}]->IsFunction() || info[{{argument.index}}]->IsNull()){% else % }info[{{argument.index}}]->IsFunction(){% endif %}) { 136 if (info.Length() <= {{argument.index}} || !{% if argument.is_nullable %}(info[{ {argument.index}}]->IsFunction() || info[{{argument.index}}]->IsNull()){% else % }info[{{argument.index}}]->IsFunction(){% endif %}) {
137 {{throw_type_error(method, 137 {{throw_type_error(method,
138 '"The callback provided as parameter %s is not a function."' % 138 '"The callback provided as parameter %s is not a function."' %
139 (argument.index + 1)) | indent }} 139 (argument.index + 1)) | indent }}
140 return; 140 return;
141 } 141 }
142 {{argument.name}} = {% if argument.is_nullable %}info[{{argument.index}}]->IsNul l() ? nullptr : {% endif %}V8{{argument.idl_type}}::create(v8::Local<v8::Functio n>::Cast(info[{{argument.index}}]), ScriptState::current(info.GetIsolate())); 142 {{argument.name}} = {% if argument.is_nullable %}info[{{argument.index}}]->IsNul l() ? nullptr : {% endif %}V8{{argument.idl_type}}::create(v8::Local<v8::Functio n>::Cast(info[{{argument.index}}]), ScriptState::current(info.GetIsolate()));
143 {% endif %}{# argument.is_optional #} 143 {% endif %}{# argument.is_optional #}
144 {% endif %}{# argument.idl_type == 'EventListener' #} 144 {% endif %}{# argument.idl_type == 'EventListener' #}
145 {% elif argument.is_callback_function %}
146 if (!info[{{argument.index}}]->IsFunction(){% if argument.is_nullable %} && !inf o[{{argument.index}}]->IsNull(){% endif %}) {
147 {{throw_type_error(method,
148 '"The callback provided as parameter %s is not a function."' %
149 (argument.index + 1)) | indent(8)}}
150 return;
151 }
152 {{argument.v8_value_to_local_cpp_value}};
145 {% elif argument.is_variadic_wrapper_type %} 153 {% elif argument.is_variadic_wrapper_type %}
146 for (int i = {{argument.index}}; i < info.Length(); ++i) { 154 for (int i = {{argument.index}}; i < info.Length(); ++i) {
147 if (!V8{{argument.idl_type}}::hasInstance(info[i], info.GetIsolate())) { 155 if (!V8{{argument.idl_type}}::hasInstance(info[i], info.GetIsolate())) {
148 {{throw_type_error(method, '"parameter %s is not of type \'%s\'."' % 156 {{throw_type_error(method, '"parameter %s is not of type \'%s\'."' %
149 (argument.index + 1, argument.idl_type)) | in dent(8)}} 157 (argument.index + 1, argument.idl_type)) | in dent(8)}}
150 return; 158 return;
151 } 159 }
152 {{argument.name}}.append(V8{{argument.idl_type}}::toImpl(v8::Local<v8::Objec t>::Cast(info[i]))); 160 {{argument.name}}.append(V8{{argument.idl_type}}::toImpl(v8::Local<v8::Objec t>::Cast(info[i])));
153 } 161 }
154 {% elif argument.is_dictionary %} 162 {% elif argument.is_dictionary %}
(...skipping 497 matching lines...) Expand 10 before | Expand all | Expand 10 after
652 if method.overloads else 660 if method.overloads else
653 method.runtime_enabled_function) %} 661 method.runtime_enabled_function) %}
654 prototypeObject->Set(v8AtomicString(isolate, "{{method.name}}"), v8::Functio nTemplate::New(isolate, {{cpp_class_or_partial}}V8Internal::{{method.name}}Metho dCallback, v8Undefined(), defaultSignature, {{method.number_of_required_argument s}})->GetFunction()); 662 prototypeObject->Set(v8AtomicString(isolate, "{{method.name}}"), v8::Functio nTemplate::New(isolate, {{cpp_class_or_partial}}V8Internal::{{method.name}}Metho dCallback, v8Undefined(), defaultSignature, {{method.number_of_required_argument s}})->GetFunction());
655 {% endfilter %}{# runtime_enabled() #} 663 {% endfilter %}{# runtime_enabled() #}
656 {% endfilter %}{# exposed() #} 664 {% endfilter %}{# exposed() #}
657 {% endfilter %}{# per_context_enabled() #} 665 {% endfilter %}{# per_context_enabled() #}
658 {% endfor %} 666 {% endfor %}
659 {% endif %} 667 {% endif %}
660 } 668 }
661 {%- endmacro %} 669 {%- endmacro %}
OLDNEW
« no previous file with comments | « Source/bindings/scripts/v8_methods.py ('k') | Source/bindings/tests/idls/core/TestObject.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698