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

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

Issue 1047993002: bindings: Add validation for enum Sequence or Array (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 8 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 | Annotate | Revision Log
OLDNEW
1 {% from 'conversions.cpp' import v8_value_to_local_cpp_value %} 1 {% from 'conversions.cpp' import declare_enum_validation_variable, v8_value_to_l ocal_cpp_value %}
2 2
3 3
4 {##############################################################################} 4 {##############################################################################}
5 {% macro generate_method(method, world_suffix) %} 5 {% macro generate_method(method, world_suffix) %}
6 {% filter conditional(method.conditional_string) %} 6 {% filter conditional(method.conditional_string) %}
7 {% if method.returns_promise and method.has_exception_state %} 7 {% if method.returns_promise and method.has_exception_state %}
8 static void {{method.name}}{{method.overload_index}}Method{{world_suffix}}Promis e(const v8::FunctionCallbackInfo<v8::Value>& info, ExceptionState& exceptionStat e) 8 static void {{method.name}}{{method.overload_index}}Method{{world_suffix}}Promis e(const v8::FunctionCallbackInfo<v8::Value>& info, ExceptionState& exceptionStat e)
9 {% else %} 9 {% else %}
10 static void {{method.name}}{{method.overload_index}}Method{{world_suffix}}(const v8::FunctionCallbackInfo<v8::Value>& info) 10 static void {{method.name}}{{method.overload_index}}Method{{world_suffix}}(const v8::FunctionCallbackInfo<v8::Value>& info)
11 {% endif %} 11 {% endif %}
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 http://www.w3.org/TR/WebIDL/#es-type-mapping #} 189 http://www.w3.org/TR/WebIDL/#es-type-mapping #}
190 {% if argument.has_type_checking_interface and not argument.is_variadic_wrapper_ type %} 190 {% if argument.has_type_checking_interface and not argument.is_variadic_wrapper_ type %}
191 {# Type checking for wrapper interface types (if interface not implemented, 191 {# Type checking for wrapper interface types (if interface not implemented,
192 throw a TypeError), per http://www.w3.org/TR/WebIDL/#es-interface 192 throw a TypeError), per http://www.w3.org/TR/WebIDL/#es-interface
193 Note: for variadic arguments, the type checking is done for each matched 193 Note: for variadic arguments, the type checking is done for each matched
194 argument instead; see argument.is_variadic_wrapper_type code-path above. #} 194 argument instead; see argument.is_variadic_wrapper_type code-path above. #}
195 if (!{{argument.name}}{% if argument.is_nullable %} && !isUndefinedOrNull(info[{ {argument.index}}]){% endif %}) { 195 if (!{{argument.name}}{% if argument.is_nullable %} && !isUndefinedOrNull(info[{ {argument.index}}]){% endif %}) {
196 {{throw_type_error(method, '"parameter %s is not of type \'%s\'."' % 196 {{throw_type_error(method, '"parameter %s is not of type \'%s\'."' %
197 (argument.index + 1, argument.idl_type)) | indent }} 197 (argument.index + 1, argument.idl_type)) | indent }}
198 } 198 }
199 {% elif argument.enum_validation_expression %} 199 {% elif argument.enum_values %}
200 {# Invalid enum values: http://www.w3.org/TR/WebIDL/#idl-enums #} 200 {# Invalid enum values: http://www.w3.org/TR/WebIDL/#idl-enums #}
201 String string = {{argument.name}}; 201 {{declare_enum_validation_variable(argument.enum_values)}}
202 if (!({{argument.enum_validation_expression}})) { 202 if (!isValidEnum({{argument.name}}, validValues, WTF_ARRAY_LENGTH(validValues), exceptionState)) {
203 {{throw_type_error(method, 203 exceptionState.throwIfNeeded();
204 '"parameter %s (\'" + string + "\') is not a valid enum value."' % 204 return;
205 (argument.index + 1)) | indent}}
206 } 205 }
207 {% elif argument.idl_type == 'Promise' %} 206 {% elif argument.idl_type == 'Promise' %}
208 {# We require this for our implementation of promises, though not in spec: 207 {# We require this for our implementation of promises, though not in spec:
209 http://heycam.github.io/webidl/#es-promise #} 208 http://heycam.github.io/webidl/#es-promise #}
210 if (!{{argument.name}}.isUndefinedOrNull() && !{{argument.name}}.isObject()) { 209 if (!{{argument.name}}.isUndefinedOrNull() && !{{argument.name}}.isObject()) {
211 {{throw_type_error(method, '"parameter %s (\'%s\') is not an object."' % 210 {{throw_type_error(method, '"parameter %s (\'%s\') is not an object."' %
212 (argument.index + 1, argument.name)) | indent}} 211 (argument.index + 1, argument.name)) | indent}}
213 } 212 }
214 {% endif %} 213 {% endif %}
215 {% endmacro %} 214 {% endmacro %}
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after
653 if method.overloads else 652 if method.overloads else
654 method.runtime_enabled_function) %} 653 method.runtime_enabled_function) %}
655 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()); 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());
656 {% endfilter %}{# runtime_enabled() #} 655 {% endfilter %}{# runtime_enabled() #}
657 {% endfilter %}{# exposed() #} 656 {% endfilter %}{# exposed() #}
658 {% endfilter %}{# per_context_enabled() #} 657 {% endfilter %}{# per_context_enabled() #}
659 {% endfor %} 658 {% endfor %}
660 {% endif %} 659 {% endif %}
661 } 660 }
662 {%- endmacro %} 661 {%- endmacro %}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698