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

git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@806 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
Marshall Greenblatt
2012-09-26 21:26:32 +00:00
parent 790ec83c42
commit 7de4dc5aad
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. // 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; 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 // is thrown. For read-only and don't-delete values this method will return
// true even though deletion failed. // 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; 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 // Returns the value with the specified identifier on success. Returns NULL
// if this method is called incorrectly or an exception is thrown. // 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; 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 // is thrown. For read-only values this method will return true even though
// assignment failed. // 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, virtual bool SetValue(const CefString& key, CefRefPtr<CefV8Value> value,
PropertyAttribute attribute) =0; PropertyAttribute attribute) =0;
@ -640,7 +640,7 @@ class CefV8Value : public virtual CefBase {
// incorrectly or an exception is thrown. For read-only values this method // incorrectly or an exception is thrown. For read-only values this method
// will return true even though assignment failed. // 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, virtual bool SetValue(const CefString& key, AccessControl settings,
PropertyAttribute attribute) =0; PropertyAttribute attribute) =0;

View File

@ -954,11 +954,6 @@ bool CefV8ValueImpl::HasValue(const CefString& key) {
CEF_REQUIRE_RT_RETURN(false); CEF_REQUIRE_RT_RETURN(false);
CEF_V8_REQUIRE_OBJECT_RETURN(false); CEF_V8_REQUIRE_OBJECT_RETURN(false);
if (key.empty()) {
NOTREACHED() << "invalid input parameter";
return false;
}
v8::HandleScope handle_scope; v8::HandleScope handle_scope;
v8::Local<v8::Object> obj = GetHandle()->ToObject(); v8::Local<v8::Object> obj = GetHandle()->ToObject();
return obj->Has(GetV8String(key)); return obj->Has(GetV8String(key));
@ -982,11 +977,6 @@ bool CefV8ValueImpl::DeleteValue(const CefString& key) {
CEF_REQUIRE_RT_RETURN(false); CEF_REQUIRE_RT_RETURN(false);
CEF_V8_REQUIRE_OBJECT_RETURN(false); CEF_V8_REQUIRE_OBJECT_RETURN(false);
if (key.empty()) {
NOTREACHED() << "invalid input parameter";
return false;
}
v8::HandleScope handle_scope; v8::HandleScope handle_scope;
v8::Local<v8::Object> obj = GetHandle()->ToObject(); v8::Local<v8::Object> obj = GetHandle()->ToObject();
@ -1018,11 +1008,6 @@ CefRefPtr<CefV8Value> CefV8ValueImpl::GetValue(const CefString& key) {
CEF_REQUIRE_RT_RETURN(NULL); CEF_REQUIRE_RT_RETURN(NULL);
CEF_V8_REQUIRE_OBJECT_RETURN(NULL); CEF_V8_REQUIRE_OBJECT_RETURN(NULL);
if (key.empty()) {
NOTREACHED() << "invalid input parameter";
return NULL;
}
v8::HandleScope handle_scope; v8::HandleScope handle_scope;
v8::Local<v8::Object> obj = GetHandle()->ToObject(); v8::Local<v8::Object> obj = GetHandle()->ToObject();
@ -1061,7 +1046,7 @@ bool CefV8ValueImpl::SetValue(const CefString& key,
CEF_V8_REQUIRE_OBJECT_RETURN(false); CEF_V8_REQUIRE_OBJECT_RETURN(false);
CefV8ValueImpl* impl = static_cast<CefV8ValueImpl*>(value.get()); CefV8ValueImpl* impl = static_cast<CefV8ValueImpl*>(value.get());
if (impl && !key.empty()) { if (impl) {
v8::HandleScope handle_scope; v8::HandleScope handle_scope;
v8::Local<v8::Object> obj = GetHandle()->ToObject(); v8::Local<v8::Object> obj = GetHandle()->ToObject();
@ -1105,11 +1090,6 @@ bool CefV8ValueImpl::SetValue(const CefString& key, AccessControl settings,
CEF_REQUIRE_RT_RETURN(false); CEF_REQUIRE_RT_RETURN(false);
CEF_V8_REQUIRE_OBJECT_RETURN(false); CEF_V8_REQUIRE_OBJECT_RETURN(false);
if (key.empty()) {
NOTREACHED() << "invalid input parameter";
return false;
}
v8::HandleScope handle_scope; v8::HandleScope handle_scope;
v8::Local<v8::Object> obj = GetHandle()->ToObject(); 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); DCHECK(self);
if (!self) if (!self)
return 0; return 0;
// Verify param: key; type: string_byref_const // Unverified params: key
DCHECK(key);
if (!key)
return 0;
// Execute // Execute
bool _retval = CefV8ValueCppToC::Get(self)->HasValue( bool _retval = CefV8ValueCppToC::Get(self)->HasValue(
@ -561,10 +558,7 @@ int CEF_CALLBACK v8value_delete_value_bykey(struct _cef_v8value_t* self,
DCHECK(self); DCHECK(self);
if (!self) if (!self)
return 0; return 0;
// Verify param: key; type: string_byref_const // Unverified params: key
DCHECK(key);
if (!key)
return 0;
// Execute // Execute
bool _retval = CefV8ValueCppToC::Get(self)->DeleteValue( bool _retval = CefV8ValueCppToC::Get(self)->DeleteValue(
@ -601,10 +595,7 @@ struct _cef_v8value_t* CEF_CALLBACK v8value_get_value_bykey(
DCHECK(self); DCHECK(self);
if (!self) if (!self)
return NULL; return NULL;
// Verify param: key; type: string_byref_const // Unverified params: key
DCHECK(key);
if (!key)
return NULL;
// Execute // Execute
CefRefPtr<CefV8Value> _retval = CefV8ValueCppToC::Get(self)->GetValue( 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); DCHECK(self);
if (!self) if (!self)
return 0; return 0;
// Verify param: key; type: string_byref_const
DCHECK(key);
if (!key)
return 0;
// Verify param: value; type: refptr_same // Verify param: value; type: refptr_same
DCHECK(value); DCHECK(value);
if (!value) if (!value)
return 0; return 0;
// Unverified params: key
// Execute // Execute
bool _retval = CefV8ValueCppToC::Get(self)->SetValue( bool _retval = CefV8ValueCppToC::Get(self)->SetValue(
@ -694,10 +682,7 @@ int CEF_CALLBACK v8value_set_value_byaccessor(struct _cef_v8value_t* self,
DCHECK(self); DCHECK(self);
if (!self) if (!self)
return 0; return 0;
// Verify param: key; type: string_byref_const // Unverified params: key
DCHECK(key);
if (!key)
return 0;
// Execute // Execute
bool _retval = CefV8ValueCppToC::Get(self)->SetValue( 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 // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
// Verify param: key; type: string_byref_const // Unverified params: key
DCHECK(!key.empty());
if (key.empty())
return false;
// Execute // Execute
int _retval = struct_->has_value_bykey(struct_, 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 // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
// Verify param: key; type: string_byref_const // Unverified params: key
DCHECK(!key.empty());
if (key.empty())
return false;
// Execute // Execute
int _retval = struct_->delete_value_bykey(struct_, 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 // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
// Verify param: key; type: string_byref_const // Unverified params: key
DCHECK(!key.empty());
if (key.empty())
return NULL;
// Execute // Execute
cef_v8value_t* _retval = struct_->get_value_bykey(struct_, 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 // 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 // Verify param: value; type: refptr_same
DCHECK(value.get()); DCHECK(value.get());
if (!value.get()) if (!value.get())
return false; return false;
// Unverified params: key
// Execute // Execute
int _retval = struct_->set_value_bykey(struct_, 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 // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
// Verify param: key; type: string_byref_const // Unverified params: key
DCHECK(!key.empty());
if (key.empty())
return false;
// Execute // Execute
int _retval = struct_->set_value_byaccessor(struct_, int _retval = struct_->set_value_byaccessor(struct_,

View File

@ -47,6 +47,7 @@ enum V8TestMode {
V8TEST_OBJECT_VALUE_DONTENUM, V8TEST_OBJECT_VALUE_DONTENUM,
V8TEST_OBJECT_VALUE_DELETE, V8TEST_OBJECT_VALUE_DELETE,
V8TEST_OBJECT_VALUE_DONTDELETE, V8TEST_OBJECT_VALUE_DONTDELETE,
V8TEST_OBJECT_VALUE_EMPTYKEY,
V8TEST_FUNCTION_CREATE, V8TEST_FUNCTION_CREATE,
V8TEST_FUNCTION_HANDLER, V8TEST_FUNCTION_HANDLER,
V8TEST_FUNCTION_HANDLER_EXCEPTION, V8TEST_FUNCTION_HANDLER_EXCEPTION,
@ -131,6 +132,9 @@ class V8RendererTest : public ClientApp::RenderDelegate {
case V8TEST_OBJECT_VALUE_DONTDELETE: case V8TEST_OBJECT_VALUE_DONTDELETE:
RunObjectValueDontDeleteTest(); RunObjectValueDontDeleteTest();
break; break;
case V8TEST_OBJECT_VALUE_EMPTYKEY:
RunObjectValueEmptyKeyTest();
break;
case V8TEST_FUNCTION_CREATE: case V8TEST_FUNCTION_CREATE:
RunFunctionCreateTest(); RunFunctionCreateTest();
break; break;
@ -1011,6 +1015,38 @@ class V8RendererTest : public ClientApp::RenderDelegate {
DestroyTest(); 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() { void RunFunctionCreateTest() {
CefRefPtr<CefV8Context> context = GetContext(); CefRefPtr<CefV8Context> context = GetContext();
@ -1691,6 +1727,7 @@ V8_TEST(ObjectValueEnum, V8TEST_OBJECT_VALUE_ENUM);
V8_TEST(ObjectValueDontEnum, V8TEST_OBJECT_VALUE_DONTENUM); V8_TEST(ObjectValueDontEnum, V8TEST_OBJECT_VALUE_DONTENUM);
V8_TEST(ObjectValueDelete, V8TEST_OBJECT_VALUE_DELETE); V8_TEST(ObjectValueDelete, V8TEST_OBJECT_VALUE_DELETE);
V8_TEST(ObjectValueDontDelete, V8TEST_OBJECT_VALUE_DONTDELETE); V8_TEST(ObjectValueDontDelete, V8TEST_OBJECT_VALUE_DONTDELETE);
V8_TEST(ObjectValueEmptyKey, V8TEST_OBJECT_VALUE_EMPTYKEY);
V8_TEST(FunctionCreate, V8TEST_FUNCTION_CREATE); V8_TEST(FunctionCreate, V8TEST_FUNCTION_CREATE);
V8_TEST(FunctionHandler, V8TEST_FUNCTION_HANDLER); V8_TEST(FunctionHandler, V8TEST_FUNCTION_HANDLER);
V8_TEST(FunctionHandlerException, V8TEST_FUNCTION_HANDLER_EXCEPTION); V8_TEST(FunctionHandlerException, V8TEST_FUNCTION_HANDLER_EXCEPTION);