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

Unified Diff: Source/bindings/templates/attributes.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/attributes.cpp
diff --git a/Source/bindings/templates/attributes.cpp b/Source/bindings/templates/attributes.cpp
index bc3da71fedf5c3bfda2365053f4691e8627bb47d..7b50e518c47c4a6c8a64610aac486f6067dc98ab 100644
--- a/Source/bindings/templates/attributes.cpp
+++ b/Source/bindings/templates/attributes.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 %}
{##############################################################################}
@@ -330,12 +330,15 @@ v8::Local<v8::Value> v8Value, const v8::PropertyCallbackInfo<void>& info
exceptionState.throwIfNeeded();
return;
}
- {% elif attribute.enum_validation_expression %}
+ {% elif attribute.enum_values %}
{# Setter ignores invalid enum values:
http://www.w3.org/TR/WebIDL/#idl-enums #}
- String string = cppValue;
- if (!({{attribute.enum_validation_expression}})) {
- currentExecutionContext(info.GetIsolate())->addConsoleMessage(ConsoleMessage::create(JSMessageSource, WarningMessageLevel, "The provided value '" + string + "' is not a valid value of type '{{attribute.idl_type}}'."));
+ {% if not attribute.has_setter_exception_state %}
+ NonThrowableExceptionState exceptionState;
+ {% endif %}
+ {{declare_enum_validation_variable(attribute.enum_values) | indent}}
+ if (!isValidEnum(cppValue, validValues, WTF_ARRAY_LENGTH(validValues), exceptionState)) {
+ currentExecutionContext(info.GetIsolate())->addConsoleMessage(ConsoleMessage::create(JSMessageSource, WarningMessageLevel, exceptionState.message()));
return;
}
{% endif %}

Powered by Google App Engine
This is Rietveld 408576698