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

Unified 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, 9 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 865271c40531c6c912a1829f34c4513f3021fdff..ba5af8fcd70959e3a196bd2c9de3603918704f7e 100644
--- a/Source/bindings/templates/methods.cpp
+++ b/Source/bindings/templates/methods.cpp
@@ -1,4 +1,4 @@
-{% from 'conversions.cpp' import v8_value_to_local_cpp_value %}
+{% from 'conversions.cpp' import declare_enum_validation_variable, v8_value_to_local_cpp_value %}
{##############################################################################}
@@ -196,13 +196,12 @@ if (!{{argument.name}}{% if argument.is_nullable %} && !isUndefinedOrNull(info[{
{{throw_type_error(method, '"parameter %s is not of type \'%s\'."' %
(argument.index + 1, argument.idl_type)) | indent}}
}
-{% elif argument.enum_validation_expression %}
+{% elif argument.enum_values %}
{# Invalid enum values: http://www.w3.org/TR/WebIDL/#idl-enums #}
-String string = {{argument.name}};
-if (!({{argument.enum_validation_expression}})) {
- {{throw_type_error(method,
- '"parameter %s (\'" + string + "\') is not a valid enum value."' %
- (argument.index + 1)) | indent}}
+{{declare_enum_validation_variable(argument.enum_values)}}
+if (!isValidEnum({{argument.name}}, validValues, WTF_ARRAY_LENGTH(validValues), exceptionState)) {
+ exceptionState.throwIfNeeded();
+ return;
}
{% elif argument.idl_type == 'Promise' %}
{# We require this for our implementation of promises, though not in spec:

Powered by Google App Engine
This is Rietveld 408576698