diff --git a/include/cef.h b/include/cef.h index cb1b4e18b..64596722a 100644 --- a/include/cef.h +++ b/include/cef.h @@ -2547,7 +2547,8 @@ public: // Associate a value with the specified identifier. /// /*--cef(capi_name=set_value_bykey)--*/ - virtual bool SetValue(const CefString& key, CefRefPtr value) =0; + virtual bool SetValue(const CefString& key, CefRefPtr value, + PropertyAttribute attribute) =0; /// // Associate a value with the specified identifier. /// diff --git a/include/cef_capi.h b/include/cef_capi.h index 9169f855b..ce76644cb 100644 --- a/include/cef_capi.h +++ b/include/cef_capi.h @@ -2267,7 +2267,8 @@ typedef struct _cef_v8value_t // Associate a value with the specified identifier. /// int (CEF_CALLBACK *set_value_bykey)(struct _cef_v8value_t* self, - const cef_string_t* key, struct _cef_v8value_t* value); + const cef_string_t* key, struct _cef_v8value_t* value, + enum cef_v8_propertyattribute_t attribute); /// // Associate a value with the specified identifier. diff --git a/libcef/v8_impl.cc b/libcef/v8_impl.cc index eb69a4323..6c9d5f4f2 100644 --- a/libcef/v8_impl.cc +++ b/libcef/v8_impl.cc @@ -26,6 +26,13 @@ namespace { +static const char kCefAccessor[] = "Cef::Accessor"; +static const char kCefHandler[] = "Cef::Handler"; +static const char kCefUserData[] = "Cef::UserData"; +static const v8::PropertyAttribute kInternalAttributes = + static_cast(v8::ReadOnly | v8::DontEnum | + v8::DontDelete); + // Memory manager. base::LazyInstance g_v8_tracker(base::LINKER_INITIALIZED); @@ -202,7 +209,7 @@ v8::Handle AccessorGetterCallbackImpl(v8::Local property, v8::HandleScope handle_scope; v8::Handle obj = info.This(); - v8::Handle key = v8::String::New("Cef::Accessor"); + v8::Handle key = v8::String::New(kCefAccessor); CefV8Accessor* accessorPtr = NULL; if (obj->Has(key)) { @@ -237,7 +244,7 @@ void AccessorSetterCallbackImpl(v8::Local property, v8::HandleScope handle_scope; v8::Handle obj = info.This(); - v8::Handle key = v8::String::New("Cef::Accessor"); + v8::Handle key = v8::String::New(kCefAccessor); CefV8Accessor* accessorPtr = NULL; if (obj->Has(key)) { @@ -547,13 +554,13 @@ CefRefPtr CefV8Value::CreateObject( // Attach the user data to the V8 object. if (user_data.get()) { v8::Local data = v8::External::Wrap(user_data.get()); - obj->Set(v8::String::New("Cef::UserData"), data); + obj->Set(v8::String::New(kCefUserData), data, kInternalAttributes); } // Attach the accessor to the V8 object. if (accessor.get()) { v8::Local data = v8::External::Wrap(accessor.get()); - obj->Set(v8::String::New("Cef::Accessor"), data); + obj->Set(v8::String::New(kCefAccessor), data, kInternalAttributes); } return new CefV8ValueImpl(obj, tracker); @@ -591,7 +598,7 @@ CefRefPtr CefV8Value::CreateFunction(const CefString& name, func->SetName(GetV8String(name)); // Attach the handler instance to the V8 object. - func->Set(v8::String::New("Cef::Handler"), data); + func->Set(v8::String::New(kCefHandler), data, kInternalAttributes); // Create the CefV8ValueImpl and provide a tracker object that will cause // the handler reference to be released when the V8 object is destroyed. @@ -821,7 +828,8 @@ CefRefPtr CefV8ValueImpl::GetValue(int index) } bool CefV8ValueImpl::SetValue(const CefString& key, - CefRefPtr value) + CefRefPtr value, + PropertyAttribute attribute) { CEF_REQUIRE_UI_THREAD(false); if(IsReservedKey(key)) @@ -835,7 +843,8 @@ bool CefV8ValueImpl::SetValue(const CefString& key, if(impl) { v8::HandleScope handle_scope; v8::Local obj = GetHandle()->ToObject(); - return obj->Set(GetV8String(key), impl->GetHandle()); + return obj->Set(GetV8String(key), impl->GetHandle(), + static_cast(attribute)); } else { NOTREACHED(); return false; @@ -919,7 +928,7 @@ CefRefPtr CefV8ValueImpl::GetUserData() v8::HandleScope handle_scope; v8::Local obj = GetHandle()->ToObject(); - v8::Local key = v8::String::New("Cef::UserData"); + v8::Local key = v8::String::New(kCefUserData); if(obj->Has(key)) return static_cast(v8::External::Unwrap(obj->Get(key))); return NULL; @@ -965,7 +974,7 @@ CefRefPtr CefV8ValueImpl::GetFunctionHandler() v8::HandleScope handle_scope; v8::Local obj = GetHandle()->ToObject(); - v8::Local key = v8::String::New("Cef::Handler"); + v8::Local key = v8::String::New(kCefHandler); if (obj->Has(key)) return static_cast(v8::External::Unwrap(obj->Get(key))); return NULL; diff --git a/libcef/v8_impl.h b/libcef/v8_impl.h index 9464af0fb..23822b3aa 100644 --- a/libcef/v8_impl.h +++ b/libcef/v8_impl.h @@ -131,8 +131,8 @@ public: virtual bool DeleteValue(int index) OVERRIDE; virtual CefRefPtr GetValue(const CefString& key) OVERRIDE; virtual CefRefPtr GetValue(int index) OVERRIDE; - virtual bool SetValue(const CefString& key, CefRefPtr value) - OVERRIDE; + virtual bool SetValue(const CefString& key, CefRefPtr value, + PropertyAttribute attribute) OVERRIDE; virtual bool SetValue(int index, CefRefPtr value) OVERRIDE; virtual bool SetValue(const CefString& key, AccessControl settings, PropertyAttribute attribute) OVERRIDE; diff --git a/libcef_dll/cpptoc/v8value_cpptoc.cc b/libcef_dll/cpptoc/v8value_cpptoc.cc index 31f2ea93b..3df6731f1 100644 --- a/libcef_dll/cpptoc/v8value_cpptoc.cc +++ b/libcef_dll/cpptoc/v8value_cpptoc.cc @@ -346,14 +346,16 @@ struct _cef_v8value_t* CEF_CALLBACK v8value_get_value_byindex( } int CEF_CALLBACK v8value_set_value_bykey(struct _cef_v8value_t* self, - const cef_string_t* key, struct _cef_v8value_t* value) + const cef_string_t* key, struct _cef_v8value_t* value, + enum cef_v8_propertyattribute_t attribute) { DCHECK(self); if(!self) return 0; CefRefPtr valuePtr = CefV8ValueCppToC::Unwrap(value); - return CefV8ValueCppToC::Get(self)->SetValue(CefString(key), valuePtr); + return CefV8ValueCppToC::Get(self)->SetValue(CefString(key), valuePtr, + attribute); } int CEF_CALLBACK v8value_set_value_byindex(struct _cef_v8value_t* self, diff --git a/libcef_dll/ctocpp/v8value_ctocpp.cc b/libcef_dll/ctocpp/v8value_ctocpp.cc index 7f1b2b1db..566b88c87 100644 --- a/libcef_dll/ctocpp/v8value_ctocpp.cc +++ b/libcef_dll/ctocpp/v8value_ctocpp.cc @@ -318,13 +318,13 @@ CefRefPtr CefV8ValueCToCpp::GetValue(int index) } bool CefV8ValueCToCpp::SetValue(const CefString& key, - CefRefPtr value) + CefRefPtr value, PropertyAttribute attribute) { if(CEF_MEMBER_MISSING(struct_, set_value_bykey)) return false; return struct_->set_value_bykey(struct_, key.GetStruct(), - CefV8ValueCToCpp::Unwrap(value))?true:false; + CefV8ValueCToCpp::Unwrap(value), attribute)?true:false; } bool CefV8ValueCToCpp::SetValue(int index, CefRefPtr value) diff --git a/libcef_dll/ctocpp/v8value_ctocpp.h b/libcef_dll/ctocpp/v8value_ctocpp.h index 8b6d5add8..3caf5d263 100644 --- a/libcef_dll/ctocpp/v8value_ctocpp.h +++ b/libcef_dll/ctocpp/v8value_ctocpp.h @@ -53,8 +53,8 @@ public: virtual bool DeleteValue(int index) OVERRIDE; virtual CefRefPtr GetValue(const CefString& key) OVERRIDE; virtual CefRefPtr GetValue(int index) OVERRIDE; - virtual bool SetValue(const CefString& key, - CefRefPtr value) OVERRIDE; + virtual bool SetValue(const CefString& key, CefRefPtr value, + PropertyAttribute attribute) OVERRIDE; virtual bool SetValue(int index, CefRefPtr value) OVERRIDE; virtual bool SetValue(const CefString& key, AccessControl settings, PropertyAttribute attribute) OVERRIDE; diff --git a/tests/cefclient/binding_test.cpp b/tests/cefclient/binding_test.cpp index c80a74e68..8e9a7a801 100644 --- a/tests/cefclient/binding_test.cpp +++ b/tests/cefclient/binding_test.cpp @@ -135,17 +135,19 @@ void InitBindingTest(CefRefPtr browser, CefRefPtr testObjPtr = CefV8Value::CreateObject(NULL); // Add the new V8 object to the global window object with the name // "cef_test". - object->SetValue("cef_test", testObjPtr); + object->SetValue("cef_test", testObjPtr, V8_PROPERTY_ATTRIBUTE_NONE); // Create an instance of ClientV8FunctionHandler as the V8 handler. CefRefPtr handlerPtr = new ClientV8FunctionHandler(); // Add a new V8 function to the cef_test object with the name "Dump". testObjPtr->SetValue("Dump", - CefV8Value::CreateFunction("Dump", handlerPtr)); + CefV8Value::CreateFunction("Dump", handlerPtr), + V8_PROPERTY_ATTRIBUTE_NONE); // Add a new V8 function to the cef_test object with the name "Call". testObjPtr->SetValue("Call", - CefV8Value::CreateFunction("Call", handlerPtr)); + CefV8Value::CreateFunction("Call", handlerPtr), + V8_PROPERTY_ATTRIBUTE_NONE); } void RunBindingTest(CefRefPtr browser) diff --git a/tests/cefclient/extension_test.cpp b/tests/cefclient/extension_test.cpp index b439ec6ae..9fe4e1382 100644 --- a/tests/cefclient/extension_test.cpp +++ b/tests/cefclient/extension_test.cpp @@ -49,10 +49,12 @@ public: retval = CefV8Value::CreateObject(NULL); // Add a string parameter to the new V8 object. retval->SetValue("param", CefV8Value::CreateString( - "Retrieving a parameter on a native object succeeded.")); + "Retrieving a parameter on a native object succeeded."), + V8_PROPERTY_ATTRIBUTE_NONE); // Add a function to the new V8 object. retval->SetValue("GetMessage", - CefV8Value::CreateFunction("GetMessage", this)); + CefV8Value::CreateFunction("GetMessage", this), + V8_PROPERTY_ATTRIBUTE_NONE); return true; } else if(name == "GetMessage") diff --git a/tests/unittests/storage_unittest.cc b/tests/unittests/storage_unittest.cc index 176b7379e..7dc34eaff 100644 --- a/tests/unittests/storage_unittest.cc +++ b/tests/unittests/storage_unittest.cc @@ -329,8 +329,9 @@ public: { CefRefPtr handler = new V8Handler(this); CefRefPtr testObj = CefV8Value::CreateObject(NULL, NULL); - testObj->SetValue("result", CefV8Value::CreateFunction("result", handler)); - object->SetValue("test", testObj); + testObj->SetValue("result", CefV8Value::CreateFunction("result", handler), + V8_PROPERTY_ATTRIBUTE_NONE); + object->SetValue("test", testObj, V8_PROPERTY_ATTRIBUTE_NONE); } CefStorageType type_; diff --git a/tests/unittests/v8_unittest.cc b/tests/unittests/v8_unittest.cc index a44335d7d..0fd1980be 100644 --- a/tests/unittests/v8_unittest.cc +++ b/tests/unittests/v8_unittest.cc @@ -300,7 +300,7 @@ public: // Create the new V8 object CefRefPtr testObj = CefV8Value::CreateObject(NULL); ASSERT_TRUE(testObj.get() != NULL); - ASSERT_TRUE(object->SetValue("test", testObj)); + ASSERT_TRUE(object->SetValue("test", testObj, V8_PROPERTY_ATTRIBUTE_NONE)); // Create an instance of V8ExecuteV8Handler CefRefPtr testHandler(new V8TestV8Handler(true)); @@ -310,27 +310,31 @@ public: CefRefPtr testFunc; testFunc = CefV8Value::CreateFunction("execute", testHandler); ASSERT_TRUE(testFunc.get() != NULL); - ASSERT_TRUE(testObj->SetValue("execute", testFunc)); + ASSERT_TRUE(testObj->SetValue("execute", testFunc, + V8_PROPERTY_ATTRIBUTE_NONE)); testFunc = CefV8Value::CreateFunction("execute2", testHandler); ASSERT_TRUE(testFunc.get() != NULL); - ASSERT_TRUE(testObj->SetValue("execute2", testFunc)); + ASSERT_TRUE(testObj->SetValue("execute2", testFunc, + V8_PROPERTY_ATTRIBUTE_NONE)); // Add the values ASSERT_TRUE(testObj->SetValue("intVal", - CefV8Value::CreateInt(12))); + CefV8Value::CreateInt(12), V8_PROPERTY_ATTRIBUTE_NONE)); ASSERT_TRUE(testObj->SetValue("doubleVal", - CefV8Value::CreateDouble(5.432))); + CefV8Value::CreateDouble(5.432), V8_PROPERTY_ATTRIBUTE_NONE)); ASSERT_TRUE(testObj->SetValue("boolVal", - CefV8Value::CreateBool(true))); + CefV8Value::CreateBool(true), V8_PROPERTY_ATTRIBUTE_NONE)); ASSERT_TRUE(testObj->SetValue("stringVal", - CefV8Value::CreateString("the string"))); + CefV8Value::CreateString("the string"), V8_PROPERTY_ATTRIBUTE_NONE)); cef_time_t date = {2010, 5, 1, 3, 12, 30, 10, 100}; - ASSERT_TRUE(testObj->SetValue("dateVal", CefV8Value::CreateDate(date))); + ASSERT_TRUE(testObj->SetValue("dateVal", CefV8Value::CreateDate(date), + V8_PROPERTY_ATTRIBUTE_NONE)); CefRefPtr testArray(CefV8Value::CreateArray()); ASSERT_TRUE(testArray.get() != NULL); - ASSERT_TRUE(testObj->SetValue("arrayVal", testArray)); + ASSERT_TRUE(testObj->SetValue("arrayVal", testArray, + V8_PROPERTY_ATTRIBUTE_NONE)); ASSERT_TRUE(testArray->SetValue(0, CefV8Value::CreateInt(4))); ASSERT_TRUE(testArray->SetValue(1, CefV8Value::CreateDouble(120.43))); ASSERT_TRUE(testArray->SetValue(2, CefV8Value::CreateBool(true))); @@ -593,31 +597,33 @@ public: CefRefPtr funcHandler(new DelegatingV8Handler(this)); CefRefPtr helloFunc = CefV8Value::CreateFunction("hello", funcHandler); - object->SetValue("hello", helloFunc); + object->SetValue("hello", helloFunc, V8_PROPERTY_ATTRIBUTE_NONE); CefRefPtr fromIFrameFunc = CefV8Value::CreateFunction("fromIFrame", funcHandler); - object->SetValue("fromIFrame", fromIFrameFunc); + object->SetValue("fromIFrame", fromIFrameFunc, V8_PROPERTY_ATTRIBUTE_NONE); CefRefPtr goFunc = CefV8Value::CreateFunction("begin", funcHandler); - object->SetValue("begin", goFunc); + object->SetValue("begin", goFunc, V8_PROPERTY_ATTRIBUTE_NONE); CefRefPtr doneFunc = CefV8Value::CreateFunction("end", funcHandler); - object->SetValue("end", doneFunc); + object->SetValue("end", doneFunc, V8_PROPERTY_ATTRIBUTE_NONE); CefRefPtr compFunc = CefV8Value::CreateFunction("comp", funcHandler); - object->SetValue("comp", compFunc); + object->SetValue("comp", compFunc, V8_PROPERTY_ATTRIBUTE_NONE); // Used for testing exceptions returned from accessors. CefRefPtr gotGetExceptionFunc = CefV8Value::CreateFunction("gotGetException", funcHandler); - object->SetValue("gotGetException", gotGetExceptionFunc); + object->SetValue("gotGetException", gotGetExceptionFunc, + V8_PROPERTY_ATTRIBUTE_NONE); CefRefPtr gotSetExceptionFunc = CefV8Value::CreateFunction("gotSetException", funcHandler); - object->SetValue("gotSetException", gotSetExceptionFunc); + object->SetValue("gotSetException", gotSetExceptionFunc, + V8_PROPERTY_ATTRIBUTE_NONE); // Create an object with accessor based properties: CefRefPtr blankBase; @@ -629,7 +635,7 @@ public: point->SetValue("y", V8_ACCESS_CONTROL_DEFAULT, V8_PROPERTY_ATTRIBUTE_NONE); - object->SetValue("point", point); + object->SetValue("point", point, V8_PROPERTY_ATTRIBUTE_NONE); // Create another object with accessor based properties: CefRefPtr exceptObj = @@ -638,7 +644,7 @@ public: exceptObj->SetValue("makeException", V8_ACCESS_CONTROL_DEFAULT, V8_PROPERTY_ATTRIBUTE_NONE); - object->SetValue("exceptObj", exceptObj); + object->SetValue("exceptObj", exceptObj, V8_PROPERTY_ATTRIBUTE_NONE); } void CallIFrame() @@ -715,9 +721,9 @@ public: obj = CefV8Value::CreateObject(NULL); url = CefV8Value::CreateString("http://tests/end.html"); - obj->SetValue("url", url); - obj->SetValue("foobar", foobarFunc); - obj->SetValue("anArray", anArray); + obj->SetValue("url", url, V8_PROPERTY_ATTRIBUTE_NONE); + obj->SetValue("foobar", foobarFunc, V8_PROPERTY_ATTRIBUTE_NONE); + obj->SetValue("anArray", anArray, V8_PROPERTY_ATTRIBUTE_NONE); args.push_back(obj);