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

Unified Diff: Source/bindings/tests/results/core/V8TestDictionary.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/V8TestDictionary.cpp
diff --git a/Source/bindings/tests/results/core/V8TestDictionary.cpp b/Source/bindings/tests/results/core/V8TestDictionary.cpp
index 62cd43d3da1ece5601f0e2149585d5b383255f6e..a73a53751a20bcafc2f47b1d962656257f6e6f73 100644
--- a/Source/bindings/tests/results/core/V8TestDictionary.cpp
+++ b/Source/bindings/tests/results/core/V8TestDictionary.cpp
@@ -130,14 +130,43 @@ void V8TestDictionary::toImpl(v8::Isolate* isolate, v8::Local<v8::Value> v8Value
V8StringResource<> enumMember = enumMemberValue;
if (!enumMember.prepare(exceptionState))
return;
- String string = enumMember;
- if (!(string == "" || string == "EnumValue1" || string == "EnumValue2" || string == "EnumValue3")) {
- exceptionState.throwTypeError("member enumMember ('" + string + "') is not a valid enum value.");
+ static const char* validValues[] = {
+ "",
+ "EnumValue1",
+ "EnumValue2",
+ "EnumValue3",
+ };
+ if (!isValidEnum(enumMember, validValues, WTF_ARRAY_LENGTH(validValues))) {
+ exceptionState.throwTypeError("member enumMember ('" + toCoreString(isolate, enumMemberValue) + "') is not a valid enum value.");
return;
}
impl.setEnumMember(enumMember);
}
+ v8::Local<v8::Value> enumSequenceMemberValue = v8Object->Get(v8String(isolate, "enumSequenceMember"));
+ if (block.HasCaught()) {
+ exceptionState.rethrowV8Exception(block.Exception());
+ return;
+ }
+ if (enumSequenceMemberValue.IsEmpty() || enumSequenceMemberValue->IsUndefined()) {
+ // Do nothing.
+ } else {
+ Vector<String> enumSequenceMember = toImplArray<String>(enumSequenceMemberValue, 0, isolate, exceptionState);
+ if (exceptionState.hadException())
+ return;
+ static const char* validValues[] = {
+ "",
+ "EnumValue1",
+ "EnumValue2",
+ "EnumValue3",
+ };
+ if (!isValidEnum(enumSequenceMember, validValues, WTF_ARRAY_LENGTH(validValues))) {
+ exceptionState.throwTypeError("member enumSequenceMember ('" + toCoreString(isolate, enumSequenceMemberValue) + "') is not a valid enum value.");
haraken 2015/04/01 01:27:25 Shall we move the for loop from isValidEnum to the
+ return;
+ }
+ impl.setEnumSequenceMember(enumSequenceMember);
+ }
+
v8::Local<v8::Value> eventTargetMemberValue = v8Object->Get(v8String(isolate, "eventTargetMember"));
if (block.HasCaught()) {
exceptionState.rethrowV8Exception(block.Exception());
@@ -495,6 +524,10 @@ void toV8TestDictionary(const TestDictionary& impl, v8::Local<v8::Object> dictio
dictionary->Set(v8String(isolate, "enumMember"), v8String(isolate, String("foo")));
}
+ if (impl.hasEnumSequenceMember()) {
+ dictionary->Set(v8String(isolate, "enumSequenceMember"), toV8(impl.enumSequenceMember(), creationContext, isolate));
+ }
+
if (impl.hasEventTargetMember()) {
dictionary->Set(v8String(isolate, "eventTargetMember"), toV8(impl.eventTargetMember(), creationContext, isolate));
}
« no previous file with comments | « Source/bindings/tests/results/core/UnionTypesCore.cpp ('k') | Source/bindings/tests/results/core/V8TestInterface.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698