- Revert: Change index parameter types from int to size_t to make 0-based range implicit.

- Add checks that index values are >= 0.

git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@409 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
Marshall Greenblatt 2011-12-08 10:22:15 +00:00
parent 64e08c2918
commit ef64033467
15 changed files with 137 additions and 51 deletions

View File

@ -2663,8 +2663,8 @@ public:
///
// Returns true if the object has a value with the specified identifier.
///
/*--cef(capi_name=has_value_byindex)--*/
virtual bool HasValue(size_t index) =0;
/*--cef(capi_name=has_value_byindex,index_param=index)--*/
virtual bool HasValue(int index) =0;
///
// Delete the value with the specified identifier.
@ -2674,8 +2674,8 @@ public:
///
// Delete the value with the specified identifier.
///
/*--cef(capi_name=delete_value_byindex)--*/
virtual bool DeleteValue(size_t index) =0;
/*--cef(capi_name=delete_value_byindex,index_param=index)--*/
virtual bool DeleteValue(int index) =0;
///
// Returns the value with the specified identifier.
@ -2685,8 +2685,8 @@ public:
///
// Returns the value with the specified identifier.
///
/*--cef(capi_name=get_value_byindex)--*/
virtual CefRefPtr<CefV8Value> GetValue(size_t index) =0;
/*--cef(capi_name=get_value_byindex,index_param=index)--*/
virtual CefRefPtr<CefV8Value> GetValue(int index) =0;
///
// Associate a value with the specified identifier.
@ -2697,8 +2697,8 @@ public:
///
// Associate a value with the specified identifier.
///
/*--cef(capi_name=set_value_byindex)--*/
virtual bool SetValue(size_t index, CefRefPtr<CefV8Value> value) =0;
/*--cef(capi_name=set_value_byindex,index_param=index)--*/
virtual bool SetValue(int index, CefRefPtr<CefV8Value> value) =0;
///
// Register an identifier whose access will be forwarded to the CefV8Accessor
@ -3137,8 +3137,8 @@ public:
///
// Returns the value of the attribute at the specified 0-based index.
///
/*--cef(capi_name=get_attribute_byindex)--*/
virtual CefString GetAttribute(size_t index) =0;
/*--cef(capi_name=get_attribute_byindex,index_param=index)--*/
virtual CefString GetAttribute(int index) =0;
///
// Returns the value of the attribute with the specified qualified name.
@ -3182,8 +3182,8 @@ public:
// Moves the cursor to the attribute at the specified 0-based index. Returns
// true if the cursor position was set successfully.
///
/*--cef(capi_name=move_to_attribute_byindex)--*/
virtual bool MoveToAttribute(size_t index) =0;
/*--cef(capi_name=move_to_attribute_byindex,index_param=index)--*/
virtual bool MoveToAttribute(int index) =0;
///
// Moves the cursor to the attribute with the specified qualified name.

View File

@ -2375,8 +2375,7 @@ typedef struct _cef_v8value_t
///
// Returns true (1) if the object has a value with the specified identifier.
///
int (CEF_CALLBACK *has_value_byindex)(struct _cef_v8value_t* self,
size_t index);
int (CEF_CALLBACK *has_value_byindex)(struct _cef_v8value_t* self, int index);
///
// Delete the value with the specified identifier.
@ -2388,7 +2387,7 @@ typedef struct _cef_v8value_t
// Delete the value with the specified identifier.
///
int (CEF_CALLBACK *delete_value_byindex)(struct _cef_v8value_t* self,
size_t index);
int index);
///
// Returns the value with the specified identifier.
@ -2400,7 +2399,7 @@ typedef struct _cef_v8value_t
// Returns the value with the specified identifier.
///
struct _cef_v8value_t* (CEF_CALLBACK *get_value_byindex)(
struct _cef_v8value_t* self, size_t index);
struct _cef_v8value_t* self, int index);
///
// Associate a value with the specified identifier.
@ -2412,8 +2411,8 @@ typedef struct _cef_v8value_t
///
// Associate a value with the specified identifier.
///
int (CEF_CALLBACK *set_value_byindex)(struct _cef_v8value_t* self,
size_t index, struct _cef_v8value_t* value);
int (CEF_CALLBACK *set_value_byindex)(struct _cef_v8value_t* self, int index,
struct _cef_v8value_t* value);
///
// Register an identifier whose access will be forwarded to the
@ -2917,7 +2916,7 @@ typedef struct _cef_xml_reader_t
///
// The resulting string must be freed by calling cef_string_userfree_free().
cef_string_userfree_t (CEF_CALLBACK *get_attribute_byindex)(
struct _cef_xml_reader_t* self, size_t index);
struct _cef_xml_reader_t* self, int index);
///
// Returns the value of the attribute with the specified qualified name.
@ -2965,7 +2964,7 @@ typedef struct _cef_xml_reader_t
// true (1) if the cursor position was set successfully.
///
int (CEF_CALLBACK *move_to_attribute_byindex)(struct _cef_xml_reader_t* self,
size_t index);
int index);
///
// Moves the cursor to the attribute with the specified qualified name.

View File

@ -851,13 +851,17 @@ bool CefV8ValueImpl::HasValue(const CefString& key)
return obj->Has(GetV8String(key));
}
bool CefV8ValueImpl::HasValue(size_t index)
bool CefV8ValueImpl::HasValue(int index)
{
CEF_REQUIRE_UI_THREAD(false);
if(!GetHandle()->IsObject()) {
NOTREACHED() << "V8 value is not an object";
return false;
}
if (index < 0) {
NOTREACHED() << "invalid input parameter";
return false;
}
v8::HandleScope handle_scope;
v8::Local<v8::Object> obj = GetHandle()->ToObject();
@ -882,13 +886,17 @@ bool CefV8ValueImpl::DeleteValue(const CefString& key)
return obj->Delete(GetV8String(key));
}
bool CefV8ValueImpl::DeleteValue(size_t index)
bool CefV8ValueImpl::DeleteValue(int index)
{
CEF_REQUIRE_UI_THREAD(false);
if(!GetHandle()->IsObject()) {
NOTREACHED() << "V8 value is not an object";
return false;
}
if (index < 0) {
NOTREACHED() << "invalid input parameter";
return false;
}
v8::HandleScope handle_scope;
v8::Local<v8::Object> obj = GetHandle()->ToObject();
@ -913,13 +921,17 @@ CefRefPtr<CefV8Value> CefV8ValueImpl::GetValue(const CefString& key)
return new CefV8ValueImpl(obj->Get(GetV8String(key)));
}
CefRefPtr<CefV8Value> CefV8ValueImpl::GetValue(size_t index)
CefRefPtr<CefV8Value> CefV8ValueImpl::GetValue(int index)
{
CEF_REQUIRE_UI_THREAD(NULL);
if(!GetHandle()->IsObject()) {
NOTREACHED() << "V8 value is not an object";
return NULL;
}
if (index < 0) {
NOTREACHED() << "invalid input parameter";
return false;
}
v8::HandleScope handle_scope;
v8::Local<v8::Object> obj = GetHandle()->ToObject();
@ -948,7 +960,7 @@ bool CefV8ValueImpl::SetValue(const CefString& key,
}
}
bool CefV8ValueImpl::SetValue(size_t index, CefRefPtr<CefV8Value> value)
bool CefV8ValueImpl::SetValue(int index, CefRefPtr<CefV8Value> value)
{
CEF_REQUIRE_UI_THREAD(false);
@ -956,6 +968,10 @@ bool CefV8ValueImpl::SetValue(size_t index, CefRefPtr<CefV8Value> value)
NOTREACHED() << "V8 value is not an object";
return false;
}
if (index < 0) {
NOTREACHED() << "invalid input parameter";
return false;
}
CefV8ValueImpl *impl = static_cast<CefV8ValueImpl*>(value.get());
if(impl) {

View File

@ -127,14 +127,14 @@ public:
virtual CefTime GetDateValue() OVERRIDE;
virtual CefString GetStringValue() OVERRIDE;
virtual bool HasValue(const CefString& key) OVERRIDE;
virtual bool HasValue(size_t index) OVERRIDE;
virtual bool HasValue(int index) OVERRIDE;
virtual bool DeleteValue(const CefString& key) OVERRIDE;
virtual bool DeleteValue(size_t index) OVERRIDE;
virtual bool DeleteValue(int index) OVERRIDE;
virtual CefRefPtr<CefV8Value> GetValue(const CefString& key) OVERRIDE;
virtual CefRefPtr<CefV8Value> GetValue(size_t index) OVERRIDE;
virtual CefRefPtr<CefV8Value> GetValue(int index) OVERRIDE;
virtual bool SetValue(const CefString& key, CefRefPtr<CefV8Value> value,
PropertyAttribute attribute) OVERRIDE;
virtual bool SetValue(size_t index, CefRefPtr<CefV8Value> value) OVERRIDE;
virtual bool SetValue(int index, CefRefPtr<CefV8Value> value) OVERRIDE;
virtual bool SetValue(const CefString& key, AccessControl settings,
PropertyAttribute attribute) OVERRIDE;
virtual bool GetKeys(std::vector<CefString>& keys) OVERRIDE;

View File

@ -355,7 +355,7 @@ size_t CefXmlReaderImpl::GetAttributeCount()
return xmlTextReaderAttributeCount(reader_);
}
CefString CefXmlReaderImpl::GetAttribute(size_t index)
CefString CefXmlReaderImpl::GetAttribute(int index)
{
if (!VerifyContext())
return CefString();
@ -409,7 +409,7 @@ int CefXmlReaderImpl::GetLineNumber()
return xmlTextReaderGetParserLineNumber(reader_);
}
bool CefXmlReaderImpl::MoveToAttribute(size_t index)
bool CefXmlReaderImpl::MoveToAttribute(int index)
{
if (!VerifyContext())
return false;

View File

@ -38,14 +38,14 @@ public:
virtual CefString GetValue() OVERRIDE;
virtual bool HasAttributes() OVERRIDE;
virtual size_t GetAttributeCount() OVERRIDE;
virtual CefString GetAttribute(size_t index) OVERRIDE;
virtual CefString GetAttribute(int index) OVERRIDE;
virtual CefString GetAttribute(const CefString& qualifiedName) OVERRIDE;
virtual CefString GetAttribute(const CefString& localName,
const CefString& namespaceURI) OVERRIDE;
virtual CefString GetInnerXml() OVERRIDE;
virtual CefString GetOuterXml() OVERRIDE;
virtual int GetLineNumber() OVERRIDE;
virtual bool MoveToAttribute(size_t index) OVERRIDE;
virtual bool MoveToAttribute(int index) OVERRIDE;
virtual bool MoveToAttribute(const CefString& qualifiedName) OVERRIDE;
virtual bool MoveToAttribute(const CefString& localName,
const CefString& namespaceURI) OVERRIDE;

View File

@ -477,13 +477,17 @@ int CEF_CALLBACK v8value_has_value_bykey(struct _cef_v8value_t* self,
int CEF_CALLBACK v8value_has_value_byindex(struct _cef_v8value_t* self,
size_t index)
int index)
{
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
DCHECK(self);
if (!self)
return 0;
// Verify param: index; type: simple_byval
DCHECK(index >= 0);
if (index < 0)
return 0;
// Execute
bool _retval = CefV8ValueCppToC::Get(self)->HasValue(
@ -517,13 +521,17 @@ int CEF_CALLBACK v8value_delete_value_bykey(struct _cef_v8value_t* self,
int CEF_CALLBACK v8value_delete_value_byindex(struct _cef_v8value_t* self,
size_t index)
int index)
{
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
DCHECK(self);
if (!self)
return 0;
// Verify param: index; type: simple_byval
DCHECK(index >= 0);
if (index < 0)
return 0;
// Execute
bool _retval = CefV8ValueCppToC::Get(self)->DeleteValue(
@ -557,13 +565,17 @@ struct _cef_v8value_t* CEF_CALLBACK v8value_get_value_bykey(
struct _cef_v8value_t* CEF_CALLBACK v8value_get_value_byindex(
struct _cef_v8value_t* self, size_t index)
struct _cef_v8value_t* self, int index)
{
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
DCHECK(self);
if (!self)
return NULL;
// Verify param: index; type: simple_byval
DCHECK(index >= 0);
if (index < 0)
return NULL;
// Execute
CefRefPtr<CefV8Value> _retval = CefV8ValueCppToC::Get(self)->GetValue(
@ -604,13 +616,17 @@ int CEF_CALLBACK v8value_set_value_bykey(struct _cef_v8value_t* self,
int CEF_CALLBACK v8value_set_value_byindex(struct _cef_v8value_t* self,
size_t index, struct _cef_v8value_t* value)
int index, struct _cef_v8value_t* value)
{
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
DCHECK(self);
if (!self)
return 0;
// Verify param: index; type: simple_byval
DCHECK(index >= 0);
if (index < 0)
return 0;
// Verify param: value; type: refptr_same
DCHECK(value);
if (!value)

View File

@ -327,13 +327,17 @@ size_t CEF_CALLBACK xml_reader_get_attribute_count(
cef_string_userfree_t CEF_CALLBACK xml_reader_get_attribute_byindex(
struct _cef_xml_reader_t* self, size_t index)
struct _cef_xml_reader_t* self, int index)
{
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
DCHECK(self);
if (!self)
return NULL;
// Verify param: index; type: simple_byval
DCHECK(index >= 0);
if (index < 0)
return NULL;
// Execute
CefString _retval = CefXmlReaderCppToC::Get(self)->GetAttribute(
@ -445,13 +449,17 @@ int CEF_CALLBACK xml_reader_get_line_number(struct _cef_xml_reader_t* self)
int CEF_CALLBACK xml_reader_move_to_attribute_byindex(
struct _cef_xml_reader_t* self, size_t index)
struct _cef_xml_reader_t* self, int index)
{
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
DCHECK(self);
if (!self)
return 0;
// Verify param: index; type: simple_byval
DCHECK(index >= 0);
if (index < 0)
return 0;
// Execute
bool _retval = CefXmlReaderCppToC::Get(self)->MoveToAttribute(

View File

@ -452,13 +452,18 @@ bool CefV8ValueCToCpp::HasValue(const CefString& key)
}
bool CefV8ValueCToCpp::HasValue(size_t index)
bool CefV8ValueCToCpp::HasValue(int index)
{
if (CEF_MEMBER_MISSING(struct_, has_value_byindex))
return false;
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
// Verify param: index; type: simple_byval
DCHECK(index >= 0);
if (index < 0)
return false;
// Execute
int _retval = struct_->has_value_byindex(struct_,
index);
@ -489,13 +494,18 @@ bool CefV8ValueCToCpp::DeleteValue(const CefString& key)
}
bool CefV8ValueCToCpp::DeleteValue(size_t index)
bool CefV8ValueCToCpp::DeleteValue(int index)
{
if (CEF_MEMBER_MISSING(struct_, delete_value_byindex))
return false;
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
// Verify param: index; type: simple_byval
DCHECK(index >= 0);
if (index < 0)
return false;
// Execute
int _retval = struct_->delete_value_byindex(struct_,
index);
@ -526,13 +536,18 @@ CefRefPtr<CefV8Value> CefV8ValueCToCpp::GetValue(const CefString& key)
}
CefRefPtr<CefV8Value> CefV8ValueCToCpp::GetValue(size_t index)
CefRefPtr<CefV8Value> CefV8ValueCToCpp::GetValue(int index)
{
if (CEF_MEMBER_MISSING(struct_, get_value_byindex))
return NULL;
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
// Verify param: index; type: simple_byval
DCHECK(index >= 0);
if (index < 0)
return NULL;
// Execute
cef_v8value_t* _retval = struct_->get_value_byindex(struct_,
index);
@ -570,13 +585,17 @@ bool CefV8ValueCToCpp::SetValue(const CefString& key,
}
bool CefV8ValueCToCpp::SetValue(size_t index, CefRefPtr<CefV8Value> value)
bool CefV8ValueCToCpp::SetValue(int index, CefRefPtr<CefV8Value> value)
{
if (CEF_MEMBER_MISSING(struct_, set_value_byindex))
return false;
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
// Verify param: index; type: simple_byval
DCHECK(index >= 0);
if (index < 0)
return false;
// Verify param: value; type: refptr_same
DCHECK(value.get());
if (!value.get())

View File

@ -49,14 +49,14 @@ public:
virtual CefTime GetDateValue() OVERRIDE;
virtual CefString GetStringValue() OVERRIDE;
virtual bool HasValue(const CefString& key) OVERRIDE;
virtual bool HasValue(size_t index) OVERRIDE;
virtual bool HasValue(int index) OVERRIDE;
virtual bool DeleteValue(const CefString& key) OVERRIDE;
virtual bool DeleteValue(size_t index) OVERRIDE;
virtual bool DeleteValue(int index) OVERRIDE;
virtual CefRefPtr<CefV8Value> GetValue(const CefString& key) OVERRIDE;
virtual CefRefPtr<CefV8Value> GetValue(size_t index) OVERRIDE;
virtual CefRefPtr<CefV8Value> GetValue(int index) OVERRIDE;
virtual bool SetValue(const CefString& key, CefRefPtr<CefV8Value> value,
PropertyAttribute attribute) OVERRIDE;
virtual bool SetValue(size_t index, CefRefPtr<CefV8Value> value) OVERRIDE;
virtual bool SetValue(int index, CefRefPtr<CefV8Value> value) OVERRIDE;
virtual bool SetValue(const CefString& key, AccessControl settings,
PropertyAttribute attribute) OVERRIDE;
virtual bool GetKeys(std::vector<CefString>& keys) OVERRIDE;

View File

@ -315,13 +315,18 @@ size_t CefXmlReaderCToCpp::GetAttributeCount()
}
CefString CefXmlReaderCToCpp::GetAttribute(size_t index)
CefString CefXmlReaderCToCpp::GetAttribute(int index)
{
if (CEF_MEMBER_MISSING(struct_, get_attribute_byindex))
return CefString();
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
// Verify param: index; type: simple_byval
DCHECK(index >= 0);
if (index < 0)
return CefString();
// Execute
cef_string_userfree_t _retval = struct_->get_attribute_byindex(struct_,
index);
@ -434,13 +439,18 @@ int CefXmlReaderCToCpp::GetLineNumber()
}
bool CefXmlReaderCToCpp::MoveToAttribute(size_t index)
bool CefXmlReaderCToCpp::MoveToAttribute(int index)
{
if (CEF_MEMBER_MISSING(struct_, move_to_attribute_byindex))
return false;
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
// Verify param: index; type: simple_byval
DCHECK(index >= 0);
if (index < 0)
return false;
// Execute
int _retval = struct_->move_to_attribute_byindex(struct_,
index);

View File

@ -49,14 +49,14 @@ public:
virtual CefString GetValue() OVERRIDE;
virtual bool HasAttributes() OVERRIDE;
virtual size_t GetAttributeCount() OVERRIDE;
virtual CefString GetAttribute(size_t index) OVERRIDE;
virtual CefString GetAttribute(int index) OVERRIDE;
virtual CefString GetAttribute(const CefString& qualifiedName) OVERRIDE;
virtual CefString GetAttribute(const CefString& localName,
const CefString& namespaceURI) OVERRIDE;
virtual CefString GetInnerXml() OVERRIDE;
virtual CefString GetOuterXml() OVERRIDE;
virtual int GetLineNumber() OVERRIDE;
virtual bool MoveToAttribute(size_t index) OVERRIDE;
virtual bool MoveToAttribute(int index) OVERRIDE;
virtual bool MoveToAttribute(const CefString& qualifiedName) OVERRIDE;
virtual bool MoveToAttribute(const CefString& localName,
const CefString& namespaceURI) OVERRIDE;

View File

@ -114,6 +114,14 @@ def make_cpptoc_function_impl_new(name, func, defined_names):
'\n if ('+arg_name+'Count > 0 && !'+arg_name+')'\
'\n return'+retval_default+';'
# check index params
index_params = arg.parent.get_attrib_list('index_param')
if not index_params is None and arg_name in index_params:
result += comment+\
'\n DCHECK('+arg_name+' >= 0);'\
'\n if ('+arg_name+' < 0)'\
'\n return'+retval_default+';'
if len(optional) > 0:
result += '\n // Unverified params: '+string.join(optional,', ')

View File

@ -120,6 +120,14 @@ def make_ctocpp_function_impl_new(clsname, name, func):
'\n if ('+arg_name+'.empty())'\
'\n return'+retval_default+';'
# check index params
index_params = arg.parent.get_attrib_list('index_param')
if not index_params is None and arg_name in index_params:
result += comment+\
'\n DCHECK('+arg_name+' >= 0);'\
'\n if ('+arg_name+' < 0)'\
'\n return'+retval_default+';'
if len(optional) > 0:
result += '\n // Unverified params: '+string.join(optional,', ')

View File

@ -79,6 +79,8 @@ Supported method/function attributes:
resulting C API function.
optional_param=[param] (Optional) Parameter name that will be optional
instead of required.
index_param=[param] (Optional) Parameter name representing an index
value that will be verified as >= 0.
default_retval=[string] (Required for enumeration types, Optional for other
types) Specify the default return value.
count_func=[param:func] (Required for non-const non-string std::vector