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

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 b976162b2deed3e14599ec7c47c0b12be24bbfbd..5e362eaccf74c657e9a6c21972598291570eb32e 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'."));
+ const char* validValues[] = {
+ "",
+ "EnumValue1",
+ "EnumValue2",
+ "EnumValue3",
+ };
+ if (!isValidEnum(cppValue, validValues, 4)) {
+ currentExecutionContext(info.GetIsolate())->addConsoleMessage(ConsoleMessage::create(JSMessageSource, WarningMessageLevel, "The provided value is not a valid value of type 'TestEnum'."));
haraken 2015/03/31 06:11:17 It's a shame that we lose the |string| information
bashi 2015/04/01 00:17:31 I dropped this because it requires a Vector<String
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'."));
+ const char* validValues[] = {
+ "",
+ "EnumValue1",
+ "EnumValue2",
+ "EnumValue3",
+ };
+ if (!isValidEnum(cppValue, validValues, 4)) {
+ currentExecutionContext(info.GetIsolate())->addConsoleMessage(ConsoleMessage::create(JSMessageSource, WarningMessageLevel, "The provided value 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'."));
+ const char* validValues[] = {
+ "",
+ "EnumValue1",
+ "EnumValue2",
+ "EnumValue3",
+ };
+ if (!isValidEnum(cppValue, validValues, 4)) {
+ currentExecutionContext(info.GetIsolate())->addConsoleMessage(ConsoleMessage::create(JSMessageSource, WarningMessageLevel, "The provided value 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."));
+ const char* validValues[] = {
+ "",
+ "EnumValue1",
+ "EnumValue2",
+ "EnumValue3",
+ };
+ if (!isValidEnum(testEnumTypeArg, validValues, 4)) {
+ V8ThrowException::throwTypeError(info.GetIsolate(), ExceptionMessages::failedToExecute("voidMethodTestEnumArg", "TestObject", "parameter 1 is not a valid enum value."));
return;
}
}

Powered by Google App Engine
This is Rietveld 408576698