Allow use of an empty key string with CefV8Value methods (issue #718).

git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@808 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
Marshall Greenblatt 2012-09-26 21:39:21 +00:00
parent 7de4dc5aad
commit cc3b8c9cf3
5 changed files with 53 additions and 66 deletions

View File

@ -573,7 +573,7 @@ class CefV8Value : public virtual CefBase {
///
// Returns true if the object has a value with the specified identifier.
///
/*--cef(capi_name=has_value_bykey)--*/
/*--cef(capi_name=has_value_bykey,optional_param=key)--*/
virtual bool HasValue(const CefString& key) =0;
///
@ -588,7 +588,7 @@ class CefV8Value : public virtual CefBase {
// is thrown. For read-only and don't-delete values this method will return
// true even though deletion failed.
///
/*--cef(capi_name=delete_value_bykey)--*/
/*--cef(capi_name=delete_value_bykey,optional_param=key)--*/
virtual bool DeleteValue(const CefString& key) =0;
///
@ -604,7 +604,7 @@ class CefV8Value : public virtual CefBase {
// Returns the value with the specified identifier on success. Returns NULL
// if this method is called incorrectly or an exception is thrown.
///
/*--cef(capi_name=get_value_bykey)--*/
/*--cef(capi_name=get_value_bykey,optional_param=key)--*/
virtual CefRefPtr<CefV8Value> GetValue(const CefString& key) =0;
///
@ -620,7 +620,7 @@ class CefV8Value : public virtual CefBase {
// is thrown. For read-only values this method will return true even though
// assignment failed.
///
/*--cef(capi_name=set_value_bykey)--*/
/*--cef(capi_name=set_value_bykey,optional_param=key)--*/
virtual bool SetValue(const CefString& key, CefRefPtr<CefV8Value> value,
PropertyAttribute attribute) =0;
@ -640,7 +640,7 @@ class CefV8Value : public virtual CefBase {
// incorrectly or an exception is thrown. For read-only values this method
// will return true even though assignment failed.
///
/*--cef(capi_name=set_value_byaccessor)--*/
/*--cef(capi_name=set_value_byaccessor,optional_param=key)--*/
virtual bool SetValue(const CefString& key, AccessControl settings,
PropertyAttribute attribute) =0;

View File

@ -1000,11 +1000,6 @@ bool CefV8ValueImpl::HasValue(const CefString& key) {
CEF_REQUIRE_UI_THREAD(false);
CEF_V8_REQUIRE_OBJECT_RETURN(false);
if (key.empty()) {
NOTREACHED() << "invalid input parameter";
return false;
}
v8::HandleScope handle_scope;
v8::Local<v8::Object> obj = GetHandle()->ToObject();
return obj->Has(GetV8String(key));
@ -1028,11 +1023,6 @@ bool CefV8ValueImpl::DeleteValue(const CefString& key) {
CEF_REQUIRE_UI_THREAD(false);
CEF_V8_REQUIRE_OBJECT_RETURN(false);
if (key.empty()) {
NOTREACHED() << "invalid input parameter";
return false;
}
v8::HandleScope handle_scope;
v8::Local<v8::Object> obj = GetHandle()->ToObject();
@ -1064,11 +1054,6 @@ CefRefPtr<CefV8Value> CefV8ValueImpl::GetValue(const CefString& key) {
CEF_REQUIRE_UI_THREAD(NULL);
CEF_V8_REQUIRE_OBJECT_RETURN(NULL);
if (key.empty()) {
NOTREACHED() << "invalid input parameter";
return NULL;
}
v8::HandleScope handle_scope;
v8::Local<v8::Object> obj = GetHandle()->ToObject();
@ -1107,7 +1092,7 @@ bool CefV8ValueImpl::SetValue(const CefString& key,
CEF_V8_REQUIRE_OBJECT_RETURN(false);
CefV8ValueImpl* impl = static_cast<CefV8ValueImpl*>(value.get());
if (impl && !key.empty()) {
if (impl) {
v8::HandleScope handle_scope;
v8::Local<v8::Object> obj = GetHandle()->ToObject();
@ -1151,11 +1136,6 @@ bool CefV8ValueImpl::SetValue(const CefString& key, AccessControl settings,
CEF_REQUIRE_UI_THREAD(false);
CEF_V8_REQUIRE_OBJECT_RETURN(false);
if (key.empty()) {
NOTREACHED() << "invalid input parameter";
return false;
}
v8::HandleScope handle_scope;
v8::Local<v8::Object> obj = GetHandle()->ToObject();

View File

@ -521,10 +521,7 @@ int CEF_CALLBACK v8value_has_value_bykey(struct _cef_v8value_t* self,
DCHECK(self);
if (!self)
return 0;
// Verify param: key; type: string_byref_const
DCHECK(key);
if (!key)
return 0;
// Unverified params: key
// Execute
bool _retval = CefV8ValueCppToC::Get(self)->HasValue(
@ -561,10 +558,7 @@ int CEF_CALLBACK v8value_delete_value_bykey(struct _cef_v8value_t* self,
DCHECK(self);
if (!self)
return 0;
// Verify param: key; type: string_byref_const
DCHECK(key);
if (!key)
return 0;
// Unverified params: key
// Execute
bool _retval = CefV8ValueCppToC::Get(self)->DeleteValue(
@ -601,10 +595,7 @@ struct _cef_v8value_t* CEF_CALLBACK v8value_get_value_bykey(
DCHECK(self);
if (!self)
return NULL;
// Verify param: key; type: string_byref_const
DCHECK(key);
if (!key)
return NULL;
// Unverified params: key
// Execute
CefRefPtr<CefV8Value> _retval = CefV8ValueCppToC::Get(self)->GetValue(
@ -642,14 +633,11 @@ int CEF_CALLBACK v8value_set_value_bykey(struct _cef_v8value_t* self,
DCHECK(self);
if (!self)
return 0;
// Verify param: key; type: string_byref_const
DCHECK(key);
if (!key)
return 0;
// Verify param: value; type: refptr_same
DCHECK(value);
if (!value)
return 0;
// Unverified params: key
// Execute
bool _retval = CefV8ValueCppToC::Get(self)->SetValue(
@ -694,10 +682,7 @@ int CEF_CALLBACK v8value_set_value_byaccessor(struct _cef_v8value_t* self,
DCHECK(self);
if (!self)
return 0;
// Verify param: key; type: string_byref_const
DCHECK(key);
if (!key)
return 0;
// Unverified params: key
// Execute
bool _retval = CefV8ValueCppToC::Get(self)->SetValue(

View File

@ -486,10 +486,7 @@ bool CefV8ValueCToCpp::HasValue(const CefString& key) {
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
// Verify param: key; type: string_byref_const
DCHECK(!key.empty());
if (key.empty())
return false;
// Unverified params: key
// Execute
int _retval = struct_->has_value_bykey(struct_,
@ -524,10 +521,7 @@ bool CefV8ValueCToCpp::DeleteValue(const CefString& key) {
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
// Verify param: key; type: string_byref_const
DCHECK(!key.empty());
if (key.empty())
return false;
// Unverified params: key
// Execute
int _retval = struct_->delete_value_bykey(struct_,
@ -562,10 +556,7 @@ CefRefPtr<CefV8Value> CefV8ValueCToCpp::GetValue(const CefString& key) {
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
// Verify param: key; type: string_byref_const
DCHECK(!key.empty());
if (key.empty())
return NULL;
// Unverified params: key
// Execute
cef_v8value_t* _retval = struct_->get_value_bykey(struct_,
@ -601,14 +592,11 @@ bool CefV8ValueCToCpp::SetValue(const CefString& key,
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
// Verify param: key; type: string_byref_const
DCHECK(!key.empty());
if (key.empty())
return false;
// Verify param: value; type: refptr_same
DCHECK(value.get());
if (!value.get())
return false;
// Unverified params: key
// Execute
int _retval = struct_->set_value_bykey(struct_,
@ -651,10 +639,7 @@ bool CefV8ValueCToCpp::SetValue(const CefString& key, AccessControl settings,
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
// Verify param: key; type: string_byref_const
DCHECK(!key.empty());
if (key.empty())
return false;
// Unverified params: key
// Execute
int _retval = struct_->set_value_byaccessor(struct_,

View File

@ -44,6 +44,7 @@ enum V8TestMode {
V8TEST_OBJECT_VALUE_DONTENUM,
V8TEST_OBJECT_VALUE_DELETE,
V8TEST_OBJECT_VALUE_DONTDELETE,
V8TEST_OBJECT_VALUE_EMPTYKEY,
V8TEST_FUNCTION_CREATE,
V8TEST_FUNCTION_HANDLER,
V8TEST_FUNCTION_HANDLER_EXCEPTION,
@ -147,6 +148,9 @@ class V8TestHandler : public TestHandler {
case V8TEST_OBJECT_VALUE_DONTDELETE:
RunObjectValueDontDeleteTest();
break;
case V8TEST_OBJECT_VALUE_EMPTYKEY:
RunObjectValueEmptyKeyTest();
break;
case V8TEST_FUNCTION_CREATE:
RunFunctionCreateTest();
break;
@ -1025,6 +1029,38 @@ class V8TestHandler : public TestHandler {
DestroyTest();
}
void RunObjectValueEmptyKeyTest() {
CefRefPtr<CefV8Context> context = GetContext();
static const char* kName = "";
static const int kVal = 13;
// Enter the V8 context.
EXPECT_TRUE(context->Enter());
CefRefPtr<CefV8Value> object = context->GetGlobal();
EXPECT_TRUE(object.get());
EXPECT_FALSE(object->HasValue(kName));
object->SetValue(kName, CefV8Value::CreateInt(kVal),
V8_PROPERTY_ATTRIBUTE_NONE);
EXPECT_TRUE(object->HasValue(kName));
CefRefPtr<CefV8Value> newval = object->GetValue(kName);
EXPECT_TRUE(newval.get());
EXPECT_TRUE(newval->IsInt());
EXPECT_EQ(kVal, newval->GetIntValue());
EXPECT_TRUE(object->DeleteValue(kName));
EXPECT_FALSE(object->HasValue(kName));
// Exit the V8 context.
EXPECT_TRUE(context->Exit());
DestroyTest();
}
void RunFunctionCreateTest() {
CefRefPtr<CefV8Context> context = GetContext();
@ -1599,6 +1635,7 @@ V8_TEST(ObjectValueEnum, V8TEST_OBJECT_VALUE_ENUM);
V8_TEST(ObjectValueDontEnum, V8TEST_OBJECT_VALUE_DONTENUM);
V8_TEST(ObjectValueDelete, V8TEST_OBJECT_VALUE_DELETE);
V8_TEST(ObjectValueDontDelete, V8TEST_OBJECT_VALUE_DONTDELETE);
V8_TEST(ObjectValueEmptyKey, V8TEST_OBJECT_VALUE_EMPTYKEY);
V8_TEST(FunctionCreate, V8TEST_FUNCTION_CREATE);
V8_TEST(FunctionHandler, V8TEST_FUNCTION_HANDLER);
V8_TEST(FunctionHandlerException, V8TEST_FUNCTION_HANDLER_EXCEPTION);