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

Unified Diff: Source/bindings/core/v8/V8Binding.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/core/v8/V8Binding.cpp
diff --git a/Source/bindings/core/v8/V8Binding.cpp b/Source/bindings/core/v8/V8Binding.cpp
index b288a2950186d5b88766aa9ae4837cccb0b2bdc9..b9c554fbe7499b42b57e6d7ec6e07144fe618997 100644
--- a/Source/bindings/core/v8/V8Binding.cpp
+++ b/Source/bindings/core/v8/V8Binding.cpp
@@ -778,6 +778,25 @@ void crashIfV8IsDead()
}
}
+bool isValidEnum(const String value, const char** validValues, size_t length, ExceptionState& exceptionState)
+{
+ for (size_t i = 0; i < length; ++i) {
+ if (value == validValues[i])
+ return true;
+ }
+ exceptionState.throwTypeError("The provided value '" + value + "' is not a valid enum value.");
+ return false;
+}
+
+bool isValidEnum(const Vector<String>& values, const char** validValues, size_t length, ExceptionState& exceptionState)
+{
+ for (auto value : values) {
+ if (!isValidEnum(value, validValues, length, exceptionState))
+ return false;
+ }
+ return true;
+}
+
v8::Handle<v8::Function> getBoundFunction(v8::Handle<v8::Function> function)
{
v8::Handle<v8::Value> boundFunction = function->GetBoundFunction();

Powered by Google App Engine
This is Rietveld 408576698