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

Side by Side 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, 8 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2006, 2007, 2008, 2009 Google Inc. All rights reserved. 2 * Copyright (C) 2006, 2007, 2008, 2009 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 #include "wtf/text/AtomicString.h" 67 #include "wtf/text/AtomicString.h"
68 #include "wtf/text/CString.h" 68 #include "wtf/text/CString.h"
69 #include "wtf/text/StringBuffer.h" 69 #include "wtf/text/StringBuffer.h"
70 #include "wtf/text/StringHash.h" 70 #include "wtf/text/StringHash.h"
71 #include "wtf/text/WTFString.h" 71 #include "wtf/text/WTFString.h"
72 #include "wtf/unicode/CharacterNames.h" 72 #include "wtf/unicode/CharacterNames.h"
73 #include "wtf/unicode/Unicode.h" 73 #include "wtf/unicode/Unicode.h"
74 74
75 namespace blink { 75 namespace blink {
76 76
77 String toCoreString(v8::Isolate* isolate, v8::Local<v8::Value> value)
78 {
79 if (value.IsEmpty())
80 return String();
81 if (value->IsString())
82 return toCoreString(value.As<v8::String>());
83 v8::Local<v8::String> stringValue;
84 if (!value->ToString(isolate->GetCurrentContext()).ToLocal(&stringValue))
85 return String();
86 return toCoreString(stringValue);
87 }
88
77 void setArityTypeError(ExceptionState& exceptionState, const char* valid, unsign ed provided) 89 void setArityTypeError(ExceptionState& exceptionState, const char* valid, unsign ed provided)
78 { 90 {
79 exceptionState.throwTypeError(ExceptionMessages::invalidArity(valid, provide d)); 91 exceptionState.throwTypeError(ExceptionMessages::invalidArity(valid, provide d));
80 } 92 }
81 93
82 v8::Local<v8::Value> createMinimumArityTypeErrorForMethod(v8::Isolate* isolate, const char* method, const char* type, unsigned expected, unsigned provided) 94 v8::Local<v8::Value> createMinimumArityTypeErrorForMethod(v8::Isolate* isolate, const char* method, const char* type, unsigned expected, unsigned provided)
83 { 95 {
84 return V8ThrowException::createTypeError(isolate, ExceptionMessages::failedT oExecute(method, type, ExceptionMessages::notEnoughArguments(expected, provided) )); 96 return V8ThrowException::createTypeError(isolate, ExceptionMessages::failedT oExecute(method, type, ExceptionMessages::notEnoughArguments(expected, provided) ));
85 } 97 }
86 98
(...skipping 684 matching lines...) Expand 10 before | Expand all | Expand 10 after
771 783
772 void crashIfV8IsDead() 784 void crashIfV8IsDead()
773 { 785 {
774 if (v8::V8::IsDead()) { 786 if (v8::V8::IsDead()) {
775 // FIXME: We temporarily deal with V8 internal error situations 787 // FIXME: We temporarily deal with V8 internal error situations
776 // such as out-of-memory by crashing the renderer. 788 // such as out-of-memory by crashing the renderer.
777 CRASH(); 789 CRASH();
778 } 790 }
779 } 791 }
780 792
793 bool isValidEnum(const String value, const char** validValues, size_t length)
794 {
795 for (size_t i = 0; i < length; ++i) {
796 if (value == validValues[i])
797 return true;
798 }
799 return false;
800 }
801
802 bool isValidEnum(const Vector<String>& values, const char** validValues, size_t length)
803 {
804 for (auto value : values) {
805 if (!isValidEnum(value, validValues, length))
806 return false;
807 }
808 return true;
809 }
810
781 v8::Handle<v8::Function> getBoundFunction(v8::Handle<v8::Function> function) 811 v8::Handle<v8::Function> getBoundFunction(v8::Handle<v8::Function> function)
782 { 812 {
783 v8::Handle<v8::Value> boundFunction = function->GetBoundFunction(); 813 v8::Handle<v8::Value> boundFunction = function->GetBoundFunction();
784 return boundFunction->IsFunction() ? v8::Handle<v8::Function>::Cast(boundFun ction) : function; 814 return boundFunction->IsFunction() ? v8::Handle<v8::Function>::Cast(boundFun ction) : function;
785 } 815 }
786 816
787 void addHiddenValueToArray(v8::Isolate* isolate, v8::Handle<v8::Object> object, v8::Local<v8::Value> value, int arrayIndex) 817 void addHiddenValueToArray(v8::Isolate* isolate, v8::Handle<v8::Object> object, v8::Local<v8::Value> value, int arrayIndex)
788 { 818 {
789 v8::Local<v8::Value> arrayValue = object->GetInternalField(arrayIndex); 819 v8::Local<v8::Value> arrayValue = object->GetInternalField(arrayIndex);
790 if (arrayValue->IsNull() || arrayValue->IsUndefined()) { 820 if (arrayValue->IsNull() || arrayValue->IsUndefined()) {
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
948 v8::Local<v8::Value> data = info.Data(); 978 v8::Local<v8::Value> data = info.Data();
949 ASSERT(data->IsExternal()); 979 ASSERT(data->IsExternal());
950 V8PerContextData* perContextData = V8PerContextData::from(info.Holder()->Cre ationContext()); 980 V8PerContextData* perContextData = V8PerContextData::from(info.Holder()->Cre ationContext());
951 if (!perContextData) 981 if (!perContextData)
952 return; 982 return;
953 v8SetReturnValue(info, perContextData->constructorForType(WrapperTypeInfo::u nwrap(data))); 983 v8SetReturnValue(info, perContextData->constructorForType(WrapperTypeInfo::u nwrap(data)));
954 TRACE_EVENT_SET_SAMPLING_STATE("v8", "V8Execution"); 984 TRACE_EVENT_SET_SAMPLING_STATE("v8", "V8Execution");
955 } 985 }
956 986
957 } // namespace blink 987 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698