Add additional error checking for CefV8Value methods (issue #427).
git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@381 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
parent
0f10560d27
commit
268675fdbe
|
@ -785,7 +785,12 @@ bool CefV8ValueImpl::HasValue(const CefString& key)
|
|||
{
|
||||
CEF_REQUIRE_UI_THREAD(false);
|
||||
if(!GetHandle()->IsObject()) {
|
||||
NOTREACHED();
|
||||
NOTREACHED() << "V8 value is not an object";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (key.empty()) {
|
||||
NOTREACHED() << "invalid input parameter";
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -798,7 +803,12 @@ bool CefV8ValueImpl::HasValue(int index)
|
|||
{
|
||||
CEF_REQUIRE_UI_THREAD(false);
|
||||
if(!GetHandle()->IsObject()) {
|
||||
NOTREACHED();
|
||||
NOTREACHED() << "V8 value is not an object";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (index < 0) {
|
||||
NOTREACHED() << "invalid input parameter";
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -811,7 +821,12 @@ bool CefV8ValueImpl::DeleteValue(const CefString& key)
|
|||
{
|
||||
CEF_REQUIRE_UI_THREAD(false);
|
||||
if(!GetHandle()->IsObject()) {
|
||||
NOTREACHED();
|
||||
NOTREACHED() << "V8 value is not an object";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (key.empty()) {
|
||||
NOTREACHED() << "invalid input parameter";
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -824,7 +839,12 @@ bool CefV8ValueImpl::DeleteValue(int index)
|
|||
{
|
||||
CEF_REQUIRE_UI_THREAD(false);
|
||||
if(!GetHandle()->IsObject()) {
|
||||
NOTREACHED();
|
||||
NOTREACHED() << "V8 value is not an object";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (index < 0) {
|
||||
NOTREACHED() << "invalid input parameter";
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -837,10 +857,15 @@ CefRefPtr<CefV8Value> CefV8ValueImpl::GetValue(const CefString& key)
|
|||
{
|
||||
CEF_REQUIRE_UI_THREAD(NULL);
|
||||
if(!GetHandle()->IsObject()) {
|
||||
NOTREACHED();
|
||||
NOTREACHED() << "V8 value is not an object";
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (key.empty()) {
|
||||
NOTREACHED() << "invalid input parameter";
|
||||
return false;
|
||||
}
|
||||
|
||||
v8::HandleScope handle_scope;
|
||||
v8::Local<v8::Object> obj = GetHandle()->ToObject();
|
||||
return new CefV8ValueImpl(obj->Get(GetV8String(key)));
|
||||
|
@ -850,10 +875,15 @@ CefRefPtr<CefV8Value> CefV8ValueImpl::GetValue(int index)
|
|||
{
|
||||
CEF_REQUIRE_UI_THREAD(NULL);
|
||||
if(!GetHandle()->IsObject()) {
|
||||
NOTREACHED();
|
||||
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();
|
||||
return new CefV8ValueImpl(obj->Get(v8::Number::New(index)));
|
||||
|
@ -865,18 +895,18 @@ bool CefV8ValueImpl::SetValue(const CefString& key,
|
|||
{
|
||||
CEF_REQUIRE_UI_THREAD(false);
|
||||
if(!GetHandle()->IsObject()) {
|
||||
NOTREACHED();
|
||||
NOTREACHED() << "V8 value is not an object";
|
||||
return false;
|
||||
}
|
||||
|
||||
CefV8ValueImpl *impl = static_cast<CefV8ValueImpl*>(value.get());
|
||||
if(impl) {
|
||||
if(impl && !key.empty()) {
|
||||
v8::HandleScope handle_scope;
|
||||
v8::Local<v8::Object> obj = GetHandle()->ToObject();
|
||||
return obj->Set(GetV8String(key), impl->GetHandle(),
|
||||
static_cast<v8::PropertyAttribute>(attribute));
|
||||
} else {
|
||||
NOTREACHED();
|
||||
NOTREACHED() << "invalid input parameter";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -885,11 +915,13 @@ bool CefV8ValueImpl::SetValue(int index, CefRefPtr<CefV8Value> value)
|
|||
{
|
||||
CEF_REQUIRE_UI_THREAD(false);
|
||||
|
||||
if (index < 0)
|
||||
return false;
|
||||
|
||||
if(!GetHandle()->IsObject()) {
|
||||
NOTREACHED();
|
||||
NOTREACHED() << "V8 value is not an object";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (index < 0) {
|
||||
NOTREACHED() << "invalid input parameter";
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -899,7 +931,7 @@ bool CefV8ValueImpl::SetValue(int index, CefRefPtr<CefV8Value> value)
|
|||
v8::Local<v8::Object> obj = GetHandle()->ToObject();
|
||||
return obj->Set(index, impl->GetHandle());
|
||||
} else {
|
||||
NOTREACHED();
|
||||
NOTREACHED() << "invalid input parameter";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -909,7 +941,12 @@ bool CefV8ValueImpl::SetValue(const CefString& key, AccessControl settings,
|
|||
{
|
||||
CEF_REQUIRE_UI_THREAD(false);
|
||||
if(!GetHandle()->IsObject()) {
|
||||
NOTREACHED();
|
||||
NOTREACHED() << "V8 value is not an object";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (key.empty()) {
|
||||
NOTREACHED() << "invalid input parameter";
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -934,7 +971,7 @@ bool CefV8ValueImpl::GetKeys(std::vector<CefString>& keys)
|
|||
{
|
||||
CEF_REQUIRE_UI_THREAD(false);
|
||||
if(!GetHandle()->IsObject()) {
|
||||
NOTREACHED();
|
||||
NOTREACHED() << "V8 value is not an object";
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -955,7 +992,7 @@ CefRefPtr<CefBase> CefV8ValueImpl::GetUserData()
|
|||
{
|
||||
CEF_REQUIRE_UI_THREAD(NULL);
|
||||
if(!GetHandle()->IsObject()) {
|
||||
NOTREACHED();
|
||||
NOTREACHED() << "V8 value is not an object";
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -974,7 +1011,7 @@ int CefV8ValueImpl::GetArrayLength()
|
|||
{
|
||||
CEF_REQUIRE_UI_THREAD(0);
|
||||
if(!GetHandle()->IsArray()) {
|
||||
NOTREACHED();
|
||||
NOTREACHED() << "V8 value is not an array";
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -989,7 +1026,7 @@ CefString CefV8ValueImpl::GetFunctionName()
|
|||
CefString rv;
|
||||
CEF_REQUIRE_UI_THREAD(rv);
|
||||
if(!GetHandle()->IsFunction()) {
|
||||
NOTREACHED();
|
||||
NOTREACHED() << "V8 value is not a function";
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
@ -1004,7 +1041,7 @@ CefRefPtr<CefV8Handler> CefV8ValueImpl::GetFunctionHandler()
|
|||
{
|
||||
CEF_REQUIRE_UI_THREAD(NULL);
|
||||
if(!GetHandle()->IsFunction()) {
|
||||
NOTREACHED();
|
||||
NOTREACHED() << "V8 value is not a function";
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -1041,7 +1078,7 @@ bool CefV8ValueImpl::ExecuteFunctionWithContext(
|
|||
{
|
||||
CEF_REQUIRE_UI_THREAD(false);
|
||||
if(!GetHandle()->IsFunction()) {
|
||||
NOTREACHED();
|
||||
NOTREACHED() << "V8 value is not a function";
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -286,7 +286,8 @@ int CEF_CALLBACK v8value_has_value_bykey(struct _cef_v8value_t* self,
|
|||
const cef_string_t* key)
|
||||
{
|
||||
DCHECK(self);
|
||||
if(!self)
|
||||
DCHECK(key);
|
||||
if(!self || !key)
|
||||
return 0;
|
||||
|
||||
return CefV8ValueCppToC::Get(self)->HasValue(CefString(key));
|
||||
|
@ -296,7 +297,8 @@ int CEF_CALLBACK v8value_has_value_byindex(struct _cef_v8value_t* self,
|
|||
int index)
|
||||
{
|
||||
DCHECK(self);
|
||||
if(!self)
|
||||
DCHECK(index >= 0);
|
||||
if(!self || index < 0)
|
||||
return 0;
|
||||
|
||||
return CefV8ValueCppToC::Get(self)->HasValue(index);
|
||||
|
@ -306,7 +308,8 @@ int CEF_CALLBACK v8value_delete_value_bykey(struct _cef_v8value_t* self,
|
|||
const cef_string_t* key)
|
||||
{
|
||||
DCHECK(self);
|
||||
if(!self)
|
||||
DCHECK(key);
|
||||
if(!self || !key)
|
||||
return 0;
|
||||
|
||||
return CefV8ValueCppToC::Get(self)->DeleteValue(CefString(key));
|
||||
|
@ -316,7 +319,8 @@ int CEF_CALLBACK v8value_delete_value_byindex(struct _cef_v8value_t* self,
|
|||
int index)
|
||||
{
|
||||
DCHECK(self);
|
||||
if(!self)
|
||||
DCHECK(index >= 0);
|
||||
if(!self || index < 0)
|
||||
return 0;
|
||||
|
||||
return CefV8ValueCppToC::Get(self)->DeleteValue(index);
|
||||
|
@ -326,7 +330,8 @@ struct _cef_v8value_t* CEF_CALLBACK v8value_get_value_bykey(
|
|||
struct _cef_v8value_t* self, const cef_string_t* key)
|
||||
{
|
||||
DCHECK(self);
|
||||
if(!self)
|
||||
DCHECK(key);
|
||||
if(!self || !key)
|
||||
return 0;
|
||||
|
||||
CefRefPtr<CefV8Value> valuePtr =
|
||||
|
@ -338,7 +343,8 @@ struct _cef_v8value_t* CEF_CALLBACK v8value_get_value_byindex(
|
|||
struct _cef_v8value_t* self, int index)
|
||||
{
|
||||
DCHECK(self);
|
||||
if(!self)
|
||||
DCHECK(index >= 0);
|
||||
if(!self || index < 0)
|
||||
return 0;
|
||||
|
||||
CefRefPtr<CefV8Value> valuePtr =
|
||||
|
@ -351,7 +357,9 @@ int CEF_CALLBACK v8value_set_value_bykey(struct _cef_v8value_t* self,
|
|||
enum cef_v8_propertyattribute_t attribute)
|
||||
{
|
||||
DCHECK(self);
|
||||
if(!self)
|
||||
DCHECK(key);
|
||||
DCHECK(value);
|
||||
if(!self || !key || !value)
|
||||
return 0;
|
||||
|
||||
CefRefPtr<CefV8Value> valuePtr = CefV8ValueCppToC::Unwrap(value);
|
||||
|
@ -363,7 +371,9 @@ int CEF_CALLBACK v8value_set_value_byindex(struct _cef_v8value_t* self,
|
|||
int index, struct _cef_v8value_t* value)
|
||||
{
|
||||
DCHECK(self);
|
||||
if(!self)
|
||||
DCHECK(index >= 0);
|
||||
DCHECK(value);
|
||||
if(!self || index < 0 || !value)
|
||||
return 0;
|
||||
|
||||
CefRefPtr<CefV8Value> valuePtr = CefV8ValueCppToC::Unwrap(value);
|
||||
|
@ -375,7 +385,8 @@ int CEF_CALLBACK v8value_set_value_byaccessor(struct _cef_v8value_t* self,
|
|||
enum cef_v8_propertyattribute_t attribute)
|
||||
{
|
||||
DCHECK(self);
|
||||
if(!self)
|
||||
DCHECK(key);
|
||||
if(!self || !key)
|
||||
return 0;
|
||||
|
||||
return CefV8ValueCppToC::Get(self)->SetValue(CefString(key),
|
||||
|
@ -386,7 +397,8 @@ int CEF_CALLBACK v8value_get_keys(struct _cef_v8value_t* self,
|
|||
cef_string_list_t keys)
|
||||
{
|
||||
DCHECK(self);
|
||||
if(!self)
|
||||
DCHECK(keys);
|
||||
if(!self || !keys)
|
||||
return 0;
|
||||
|
||||
std::vector<CefString> keysList;
|
||||
|
|
|
@ -276,6 +276,10 @@ bool CefV8ValueCToCpp::HasValue(int index)
|
|||
if(CEF_MEMBER_MISSING(struct_, has_value_byindex))
|
||||
return false;
|
||||
|
||||
DCHECK(index >= 0);
|
||||
if (index < 0)
|
||||
return false;
|
||||
|
||||
return struct_->has_value_byindex(struct_, index)?true:false;
|
||||
}
|
||||
|
||||
|
@ -284,6 +288,10 @@ bool CefV8ValueCToCpp::DeleteValue(const CefString& key)
|
|||
if(CEF_MEMBER_MISSING(struct_, delete_value_bykey))
|
||||
return false;
|
||||
|
||||
DCHECK(!key.empty());
|
||||
if (key.empty())
|
||||
return false;
|
||||
|
||||
return struct_->delete_value_bykey(struct_, key.GetStruct())?true:false;
|
||||
}
|
||||
|
||||
|
@ -292,6 +300,10 @@ bool CefV8ValueCToCpp::DeleteValue(int index)
|
|||
if(CEF_MEMBER_MISSING(struct_, delete_value_byindex))
|
||||
return false;
|
||||
|
||||
DCHECK(index >= 0);
|
||||
if (index < 0)
|
||||
return false;
|
||||
|
||||
return struct_->delete_value_byindex(struct_, index)?true:false;
|
||||
}
|
||||
|
||||
|
@ -300,6 +312,10 @@ CefRefPtr<CefV8Value> CefV8ValueCToCpp::GetValue(const CefString& key)
|
|||
if(CEF_MEMBER_MISSING(struct_, get_value_bykey))
|
||||
return NULL;
|
||||
|
||||
DCHECK(!key.empty());
|
||||
if (key.empty())
|
||||
return NULL;
|
||||
|
||||
cef_v8value_t* valueStruct = struct_->get_value_bykey(struct_,
|
||||
key.GetStruct());
|
||||
if(valueStruct)
|
||||
|
@ -312,6 +328,10 @@ CefRefPtr<CefV8Value> CefV8ValueCToCpp::GetValue(int index)
|
|||
if(CEF_MEMBER_MISSING(struct_, get_value_byindex))
|
||||
return NULL;
|
||||
|
||||
DCHECK(index >= 0);
|
||||
if (index < 0)
|
||||
return NULL;
|
||||
|
||||
cef_v8value_t* valueStruct = struct_->get_value_byindex(struct_, index);
|
||||
if(valueStruct)
|
||||
return CefV8ValueCToCpp::Wrap(valueStruct);
|
||||
|
@ -324,6 +344,11 @@ bool CefV8ValueCToCpp::SetValue(const CefString& key,
|
|||
if(CEF_MEMBER_MISSING(struct_, set_value_bykey))
|
||||
return false;
|
||||
|
||||
DCHECK(!key.empty());
|
||||
DCHECK(value.get());
|
||||
if (key.empty() || !value.get())
|
||||
return false;
|
||||
|
||||
return struct_->set_value_bykey(struct_, key.GetStruct(),
|
||||
CefV8ValueCToCpp::Unwrap(value), attribute)?true:false;
|
||||
}
|
||||
|
@ -333,6 +358,11 @@ bool CefV8ValueCToCpp::SetValue(int index, CefRefPtr<CefV8Value> value)
|
|||
if(CEF_MEMBER_MISSING(struct_, set_value_byindex))
|
||||
return false;
|
||||
|
||||
DCHECK(index >= 0);
|
||||
DCHECK(value.get());
|
||||
if (index < 0 || !value.get())
|
||||
return false;
|
||||
|
||||
return struct_->set_value_byindex(struct_, index,
|
||||
CefV8ValueCToCpp::Unwrap(value))?true:false;
|
||||
}
|
||||
|
@ -343,6 +373,10 @@ bool CefV8ValueCToCpp::SetValue(const CefString& key, AccessControl settings,
|
|||
if(CEF_MEMBER_MISSING(struct_, set_value_byaccessor))
|
||||
return false;
|
||||
|
||||
DCHECK(!key.empty());
|
||||
if (key.empty())
|
||||
return false;
|
||||
|
||||
return struct_->set_value_byaccessor(struct_, key.GetStruct(),
|
||||
settings, attribute)?true:false;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue