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

Unified Diff: Source/bindings/tests/results/core/V8TestInterface.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/V8TestInterface.cpp
diff --git a/Source/bindings/tests/results/core/V8TestInterface.cpp b/Source/bindings/tests/results/core/V8TestInterface.cpp
index d67f1284b627985b322d248fab9dfb21ade96031..d8a82acac74c2a0f036a15fd870f82b6fac4ea8e 100644
--- a/Source/bindings/tests/results/core/V8TestInterface.cpp
+++ b/Source/bindings/tests/results/core/V8TestInterface.cpp
@@ -277,13 +277,19 @@ static void testEnumAttributeAttributeGetterCallback(v8::Local<v8::Name>, const
static void testEnumAttributeAttributeSetter(v8::Local<v8::Value> v8Value, const v8::PropertyCallbackInfo<void>& info)
{
v8::Local<v8::Object> holder = info.Holder();
+ ExceptionState exceptionState(ExceptionState::SetterContext, "testEnumAttribute", "TestInterface", holder, info.GetIsolate());
bashi 2015/04/01 08:25:34 Changed to use actual ExceptionState.
TestInterfaceImplementation* impl = V8TestInterface::toImpl(holder);
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), exceptionState)) {
+ currentExecutionContext(info.GetIsolate())->addConsoleMessage(ConsoleMessage::create(JSMessageSource, WarningMessageLevel, exceptionState.message()));
return;
}
impl->setTestEnumAttribute(cppValue);
@@ -959,13 +965,17 @@ static void partialPartialEnumTypeAttributeAttributeGetterCallback(v8::Local<v8:
static void partialPartialEnumTypeAttributeAttributeSetter(v8::Local<v8::Value> v8Value, const v8::PropertyCallbackInfo<void>& info)
{
v8::Local<v8::Object> holder = info.Holder();
+ ExceptionState exceptionState(ExceptionState::SetterContext, "partialPartialEnumTypeAttribute", "TestInterface", holder, info.GetIsolate());
TestInterfaceImplementation* impl = V8TestInterface::toImpl(holder);
V8StringResource<> cppValue = v8Value;
if (!cppValue.prepare())
return;
- String string = cppValue;
- if (!(string == "foo" || string == "bar")) {
- currentExecutionContext(info.GetIsolate())->addConsoleMessage(ConsoleMessage::create(JSMessageSource, WarningMessageLevel, "The provided value '" + string + "' is not a valid value of type 'PartialEnumType'."));
+ static const char* validValues[] = {
+ "foo",
+ "bar",
+ };
+ if (!isValidEnum(cppValue, validValues, WTF_ARRAY_LENGTH(validValues), exceptionState)) {
+ currentExecutionContext(info.GetIsolate())->addConsoleMessage(ConsoleMessage::create(JSMessageSource, WarningMessageLevel, exceptionState.message()));
return;
}
TestPartialInterface::setPartialPartialEnumTypeAttribute(*impl, cppValue);
@@ -1169,8 +1179,10 @@ static void voidMethodUnrestrictedDoubleArgUnrestrictedFloatArgMethodCallback(co
static void voidMethodTestEnumArgMethod(const v8::FunctionCallbackInfo<v8::Value>& info)
{
+ ExceptionState exceptionState(ExceptionState::ExecutionContext, "voidMethodTestEnumArg", "TestInterface", info.Holder(), info.GetIsolate());
if (UNLIKELY(info.Length() < 1)) {
- V8ThrowException::throwException(createMinimumArityTypeErrorForMethod(info.GetIsolate(), "voidMethodTestEnumArg", "TestInterface", 1, info.Length()), info.GetIsolate());
+ setMinimumArityTypeError(exceptionState, 1, info.Length());
+ exceptionState.throwIfNeeded();
return;
}
TestInterfaceImplementation* impl = V8TestInterface::toImpl(info.Holder());
@@ -1179,9 +1191,14 @@ static void voidMethodTestEnumArgMethod(const v8::FunctionCallbackInfo<v8::Value
testEnumArg = info[0];
if (!testEnumArg.prepare())
return;
- String string = testEnumArg;
- if (!(string == "" || string == "EnumValue1" || string == "EnumValue2" || string == "EnumValue3")) {
- V8ThrowException::throwTypeError(info.GetIsolate(), ExceptionMessages::failedToExecute("voidMethodTestEnumArg", "TestInterface", "parameter 1 ('" + string + "') is not a valid enum value."));
+ static const char* validValues[] = {
+ "",
+ "EnumValue1",
+ "EnumValue2",
+ "EnumValue3",
+ };
+ if (!isValidEnum(testEnumArg, validValues, WTF_ARRAY_LENGTH(validValues), exceptionState)) {
+ exceptionState.throwIfNeeded();
return;
}
}
« no previous file with comments | « Source/bindings/tests/results/core/V8TestDictionary.cpp ('k') | Source/bindings/tests/results/core/V8TestObject.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698