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

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 760 matching lines...) Expand 10 before | Expand all | Expand 10 after
771 771
772 void crashIfV8IsDead() 772 void crashIfV8IsDead()
773 { 773 {
774 if (v8::V8::IsDead()) { 774 if (v8::V8::IsDead()) {
775 // FIXME: We temporarily deal with V8 internal error situations 775 // FIXME: We temporarily deal with V8 internal error situations
776 // such as out-of-memory by crashing the renderer. 776 // such as out-of-memory by crashing the renderer.
777 CRASH(); 777 CRASH();
778 } 778 }
779 } 779 }
780 780
781 bool isValidEnum(const String value, const char** validValues, size_t length, Ex ceptionState& exceptionState)
782 {
783 for (size_t i = 0; i < length; ++i) {
784 if (value == validValues[i])
785 return true;
786 }
787 exceptionState.throwTypeError("The provided value '" + value + "' is not a v alid enum value.");
788 return false;
789 }
790
791 bool isValidEnum(const Vector<String>& values, const char** validValues, size_t length, ExceptionState& exceptionState)
792 {
793 for (auto value : values) {
794 if (!isValidEnum(value, validValues, length, exceptionState))
795 return false;
796 }
797 return true;
798 }
799
781 v8::Handle<v8::Function> getBoundFunction(v8::Handle<v8::Function> function) 800 v8::Handle<v8::Function> getBoundFunction(v8::Handle<v8::Function> function)
782 { 801 {
783 v8::Handle<v8::Value> boundFunction = function->GetBoundFunction(); 802 v8::Handle<v8::Value> boundFunction = function->GetBoundFunction();
784 return boundFunction->IsFunction() ? v8::Handle<v8::Function>::Cast(boundFun ction) : function; 803 return boundFunction->IsFunction() ? v8::Handle<v8::Function>::Cast(boundFun ction) : function;
785 } 804 }
786 805
787 void addHiddenValueToArray(v8::Isolate* isolate, v8::Handle<v8::Object> object, v8::Local<v8::Value> value, int arrayIndex) 806 void addHiddenValueToArray(v8::Isolate* isolate, v8::Handle<v8::Object> object, v8::Local<v8::Value> value, int arrayIndex)
788 { 807 {
789 v8::Local<v8::Value> arrayValue = object->GetInternalField(arrayIndex); 808 v8::Local<v8::Value> arrayValue = object->GetInternalField(arrayIndex);
790 if (arrayValue->IsNull() || arrayValue->IsUndefined()) { 809 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(); 967 v8::Local<v8::Value> data = info.Data();
949 ASSERT(data->IsExternal()); 968 ASSERT(data->IsExternal());
950 V8PerContextData* perContextData = V8PerContextData::from(info.Holder()->Cre ationContext()); 969 V8PerContextData* perContextData = V8PerContextData::from(info.Holder()->Cre ationContext());
951 if (!perContextData) 970 if (!perContextData)
952 return; 971 return;
953 v8SetReturnValue(info, perContextData->constructorForType(WrapperTypeInfo::u nwrap(data))); 972 v8SetReturnValue(info, perContextData->constructorForType(WrapperTypeInfo::u nwrap(data)));
954 TRACE_EVENT_SET_SAMPLING_STATE("v8", "V8Execution"); 973 TRACE_EVENT_SET_SAMPLING_STATE("v8", "V8Execution");
955 } 974 }
956 975
957 } // namespace blink 976 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698