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

Unified Diff: Source/bindings/tests/results/core/UnionTypesCore.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/tests/results/core/UnionTypesCore.cpp
diff --git a/Source/bindings/tests/results/core/UnionTypesCore.cpp b/Source/bindings/tests/results/core/UnionTypesCore.cpp
index 8e9f21d50bb45cd6fbb3e55540f599e07939b441..80dd50bb2a6efaef7361e0629df230f532fa7a34 100644
--- a/Source/bindings/tests/results/core/UnionTypesCore.cpp
+++ b/Source/bindings/tests/results/core/UnionTypesCore.cpp
@@ -758,8 +758,14 @@ String TestEnumOrDouble::getAsTestEnum() const
void TestEnumOrDouble::setTestEnum(String value)
{
ASSERT(isNull());
- String string = value;
- if (!(string == "" || string == "EnumValue1" || string == "EnumValue2" || string == "EnumValue3")) {
+ NonThrowableExceptionState exceptionState;
+ static const char* validValues[] = {
+ "",
+ "EnumValue1",
+ "EnumValue2",
+ "EnumValue3",
+ };
+ if (!isValidEnum(value, validValues, WTF_ARRAY_LENGTH(validValues), exceptionState)) {
ASSERT_NOT_REACHED();
return;
}
@@ -811,11 +817,14 @@ void V8TestEnumOrDouble::toImpl(v8::Isolate* isolate, v8::Local<v8::Value> v8Val
V8StringResource<> cppValue = v8Value;
if (!cppValue.prepare(exceptionState))
return;
- String string = cppValue;
- if (!(string == "" || string == "EnumValue1" || string == "EnumValue2" || string == "EnumValue3")) {
- exceptionState.throwTypeError("'" + string + "' is not a valid enum value.");
+ static const char* validValues[] = {
+ "",
+ "EnumValue1",
+ "EnumValue2",
+ "EnumValue3",
+ };
+ if (!isValidEnum(cppValue, validValues, WTF_ARRAY_LENGTH(validValues), exceptionState))
return;
- }
impl.setTestEnum(cppValue);
return;
}

Powered by Google App Engine
This is Rietveld 408576698