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

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..d1da5496131ffdde2f88749d28c86c16b272f00e 100644
--- a/Source/bindings/core/v8/V8Binding.cpp
+++ b/Source/bindings/core/v8/V8Binding.cpp
@@ -74,6 +74,18 @@
namespace blink {
+String toCoreString(v8::Isolate* isolate, v8::Local<v8::Value> value)
+{
+ if (value.IsEmpty())
+ return String();
+ if (value->IsString())
+ return toCoreString(value.As<v8::String>());
+ v8::Local<v8::String> stringValue;
+ if (!value->ToString(isolate->GetCurrentContext()).ToLocal(&stringValue))
+ return String();
+ return toCoreString(stringValue);
+}
+
void setArityTypeError(ExceptionState& exceptionState, const char* valid, unsigned provided)
{
exceptionState.throwTypeError(ExceptionMessages::invalidArity(valid, provided));
@@ -778,6 +790,24 @@ void crashIfV8IsDead()
}
}
+bool isValidEnum(const String value, const char** validValues, size_t length)
+{
+ for (size_t i = 0; i < length; ++i) {
+ if (value == validValues[i])
+ return true;
+ }
+ return false;
+}
+
+bool isValidEnum(const Vector<String>& values, const char** validValues, size_t length)
+{
+ for (auto value : values) {
+ if (!isValidEnum(value, validValues, length))
+ 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