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

Unified Diff: Source/bindings/templates/union.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/union.cpp
diff --git a/Source/bindings/templates/union.cpp b/Source/bindings/templates/union.cpp
index 3191d5e92e576220b17a627f764fb53ce34a2ba9..98031198d4fdf640335a426c7ac534ec93d7c2a8 100644
--- a/Source/bindings/templates/union.cpp
+++ b/Source/bindings/templates/union.cpp
@@ -1,3 +1,4 @@
+{% from 'conversions.cpp' import declare_enum_validation_variable %}
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -37,9 +38,10 @@ namespace blink {
void {{container.cpp_class}}::set{{member.type_name}}({{member.rvalue_cpp_type}} value)
{
ASSERT(isNull());
- {% if member.enum_validation_expression %}
- String string = value;
- if (!({{member.enum_validation_expression}})) {
+ {% if member.enum_values %}
+ NonThrowableExceptionState exceptionState;
+ {{declare_enum_validation_variable(member.enum_values) | indent}}
+ if (!isValidEnum(value, validValues, WTF_ARRAY_LENGTH(validValues), exceptionState)) {
ASSERT_NOT_REACHED();
return;
}
@@ -136,12 +138,10 @@ void V8{{container.cpp_class}}::toImpl(v8::Isolate* isolate, v8::Local<v8::Value
{# 16. String #}
{
{{v8_value_to_local_cpp_value(container.string_type) | indent(8)}}
- {% if container.string_type.enum_validation_expression %}
- String string = cppValue;
- if (!({{container.string_type.enum_validation_expression}})) {
- exceptionState.throwTypeError("'" + string + "' is not a valid enum value.");
+ {% if container.string_type.enum_values %}
+ {{declare_enum_validation_variable(container.string_type.enum_values) | indent(8)}}
+ if (!isValidEnum(cppValue, validValues, WTF_ARRAY_LENGTH(validValues), exceptionState))
return;
- }
{% endif %}
impl.set{{container.string_type.type_name}}(cppValue);
return;

Powered by Google App Engine
This is Rietveld 408576698