From 84ff65b889fd7558d5f1e0cf34ab81ac56eef6f1 Mon Sep 17 00:00:00 2001 From: Marshall Greenblatt Date: Wed, 26 Sep 2012 21:40:18 +0000 Subject: [PATCH] Merge revision 808 changes: - Allow use of empty key string with CefV8Value methods (issue #718). git-svn-id: https://chromiumembedded.googlecode.com/svn/branches/1180@809 5089003a-bbd8-11dd-ad1f-f1f9622dbc98 --- cef1/include/cef_v8.h | 10 +++---- cef1/libcef/v8_impl.cc | 22 +------------- cef1/libcef_dll/cpptoc/v8value_cpptoc.cc | 25 ++++------------ cef1/libcef_dll/ctocpp/v8value_ctocpp.cc | 25 ++++------------ cef1/tests/unittests/v8_unittest.cc | 37 ++++++++++++++++++++++++ 5 files changed, 53 insertions(+), 66 deletions(-) diff --git a/cef1/include/cef_v8.h b/cef1/include/cef_v8.h index 70dd729f6..983ed2979 100644 --- a/cef1/include/cef_v8.h +++ b/cef1/include/cef_v8.h @@ -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 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 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; diff --git a/cef1/libcef/v8_impl.cc b/cef1/libcef/v8_impl.cc index 064c53407..169a14f78 100644 --- a/cef1/libcef/v8_impl.cc +++ b/cef1/libcef/v8_impl.cc @@ -995,11 +995,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 obj = GetHandle()->ToObject(); return obj->Has(GetV8String(key)); @@ -1023,11 +1018,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 obj = GetHandle()->ToObject(); @@ -1059,11 +1049,6 @@ CefRefPtr 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 obj = GetHandle()->ToObject(); @@ -1102,7 +1087,7 @@ bool CefV8ValueImpl::SetValue(const CefString& key, CEF_V8_REQUIRE_OBJECT_RETURN(false); CefV8ValueImpl* impl = static_cast(value.get()); - if (impl && !key.empty()) { + if (impl) { v8::HandleScope handle_scope; v8::Local obj = GetHandle()->ToObject(); @@ -1146,11 +1131,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 obj = GetHandle()->ToObject(); diff --git a/cef1/libcef_dll/cpptoc/v8value_cpptoc.cc b/cef1/libcef_dll/cpptoc/v8value_cpptoc.cc index 0ebed8c85..1fd7add92 100644 --- a/cef1/libcef_dll/cpptoc/v8value_cpptoc.cc +++ b/cef1/libcef_dll/cpptoc/v8value_cpptoc.cc @@ -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 _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( diff --git a/cef1/libcef_dll/ctocpp/v8value_ctocpp.cc b/cef1/libcef_dll/ctocpp/v8value_ctocpp.cc index 39076c824..5e28c4020 100644 --- a/cef1/libcef_dll/ctocpp/v8value_ctocpp.cc +++ b/cef1/libcef_dll/ctocpp/v8value_ctocpp.cc @@ -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 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_, diff --git a/cef1/tests/unittests/v8_unittest.cc b/cef1/tests/unittests/v8_unittest.cc index b881d266d..ddcc891a3 100644 --- a/cef1/tests/unittests/v8_unittest.cc +++ b/cef1/tests/unittests/v8_unittest.cc @@ -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 context = GetContext(); + + static const char* kName = ""; + static const int kVal = 13; + + // Enter the V8 context. + EXPECT_TRUE(context->Enter()); + + CefRefPtr 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 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 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);