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

Unified Diff: Source/bindings/tests/results/core/V8TestObject.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/V8TestObject.cpp
diff --git a/Source/bindings/tests/results/core/V8TestObject.cpp b/Source/bindings/tests/results/core/V8TestObject.cpp
index 9f7655cc5dd574f7062cfafc1d9325e1ae78a056..903f0945386ec854a0c43f353a5073c33867eaf0 100644
--- a/Source/bindings/tests/results/core/V8TestObject.cpp
+++ b/Source/bindings/tests/results/core/V8TestObject.cpp
@@ -1723,9 +1723,14 @@ static void testEnumAttributeAttributeSetter(v8::Local<v8::Value> v8Value, const
V8StringResource<> cppValue = v8Value;
if (!cppValue.prepare())
return;
- String string = cppValue;
- if (!(string == "" || string == "EnumValue1" || string == "EnumValue2" || string == "EnumValue3")) {
- currentExecutionContext(info.GetIsolate())->addConsoleMessage(ConsoleMessage::create(JSMessageSource, WarningMessageLevel, "The provided value '" + string + "' is not a valid value of type 'TestEnum'."));
+ static const char* validValues[] = {
+ "",
+ "EnumValue1",
+ "EnumValue2",
+ "EnumValue3",
+ };
+ if (!isValidEnum(cppValue, validValues, WTF_ARRAY_LENGTH(validValues))) {
+ currentExecutionContext(info.GetIsolate())->addConsoleMessage(ConsoleMessage::create(JSMessageSource, WarningMessageLevel, "The provided value '" + toCoreString(info.GetIsolate(), v8Value) + "' is not a valid value of type 'TestEnum'."));
return;
}
impl->setTestEnumAttribute(cppValue);
@@ -1759,9 +1764,14 @@ static void testEnumOrNullAttributeAttributeSetter(v8::Local<v8::Value> v8Value,
V8StringResource<TreatNullAsNullString> cppValue = v8Value;
if (!cppValue.prepare())
return;
- String string = cppValue;
- if (!(string == "" || string == "EnumValue1" || string == "EnumValue2" || string == "EnumValue3")) {
- currentExecutionContext(info.GetIsolate())->addConsoleMessage(ConsoleMessage::create(JSMessageSource, WarningMessageLevel, "The provided value '" + string + "' is not a valid value of type 'TestEnum'."));
+ static const char* validValues[] = {
+ "",
+ "EnumValue1",
+ "EnumValue2",
+ "EnumValue3",
+ };
+ if (!isValidEnum(cppValue, validValues, WTF_ARRAY_LENGTH(validValues))) {
+ currentExecutionContext(info.GetIsolate())->addConsoleMessage(ConsoleMessage::create(JSMessageSource, WarningMessageLevel, "The provided value '" + toCoreString(info.GetIsolate(), v8Value) + "' is not a valid value of type 'TestEnum'."));
return;
}
impl->setTestEnumOrNullAttribute(cppValue);
@@ -5534,9 +5544,14 @@ static void enumForPrivateScriptAttributeSetter(v8::Local<v8::Value> v8Value, co
V8StringResource<> cppValue = v8Value;
if (!cppValue.prepare())
return;
- String string = cppValue;
- if (!(string == "" || string == "EnumValue1" || string == "EnumValue2" || string == "EnumValue3")) {
- currentExecutionContext(info.GetIsolate())->addConsoleMessage(ConsoleMessage::create(JSMessageSource, WarningMessageLevel, "The provided value '" + string + "' is not a valid value of type 'TestEnum'."));
+ static const char* validValues[] = {
+ "",
+ "EnumValue1",
+ "EnumValue2",
+ "EnumValue3",
+ };
+ if (!isValidEnum(cppValue, validValues, WTF_ARRAY_LENGTH(validValues))) {
+ currentExecutionContext(info.GetIsolate())->addConsoleMessage(ConsoleMessage::create(JSMessageSource, WarningMessageLevel, "The provided value '" + toCoreString(info.GetIsolate(), v8Value) + "' is not a valid value of type 'TestEnum'."));
return;
}
V8TestObject::PrivateScript::enumForPrivateScriptAttributeSetter(toLocalFrame(toFrameIfNotDetached(info.GetIsolate()->GetCurrentContext())), impl, cppValue);
@@ -7399,9 +7414,14 @@ static void voidMethodTestEnumArgMethod(const v8::FunctionCallbackInfo<v8::Value
testEnumTypeArg = info[0];
if (!testEnumTypeArg.prepare())
return;
- String string = testEnumTypeArg;
- if (!(string == "" || string == "EnumValue1" || string == "EnumValue2" || string == "EnumValue3")) {
- V8ThrowException::throwTypeError(info.GetIsolate(), ExceptionMessages::failedToExecute("voidMethodTestEnumArg", "TestObject", "parameter 1 ('" + string + "') is not a valid enum value."));
+ static const char* validValues[] = {
+ "",
+ "EnumValue1",
+ "EnumValue2",
+ "EnumValue3",
+ };
+ if (!isValidEnum(testEnumTypeArg, validValues, WTF_ARRAY_LENGTH(validValues))) {
+ V8ThrowException::throwTypeError(info.GetIsolate(), ExceptionMessages::failedToExecute("voidMethodTestEnumArg", "TestObject", "parameter 1 ('" + toCoreString(info.GetIsolate(), info[0]) + "') is not a valid enum value."));
return;
}
}

Powered by Google App Engine
This is Rietveld 408576698