Added support for property setting.

This commit is contained in:
Per Lundberg
2013-05-11 09:46:47 +03:00
committed by Per Lundberg
parent 35dfcebe1a
commit 36bf863329
2 changed files with 34 additions and 3 deletions
+9 -1
View File
@@ -314,7 +314,15 @@ namespace CefSharp
{
// TODO: Handle read-only properties correctly here.
auto nameStr = toNative(propertyName);
javascriptObject->SetValue(nameStr, V8_ACCESS_CONTROL_DEFAULT, V8_PROPERTY_ATTRIBUTE_NONE);
cef_v8_propertyattribute_t propertyAttribute = V8_PROPERTY_ATTRIBUTE_NONE;
if (properties[propertyName]->GetSetMethod() == nullptr)
{
propertyAttribute = V8_PROPERTY_ATTRIBUTE_READONLY;
}
javascriptObject->SetValue(nameStr, V8_ACCESS_CONTROL_DEFAULT, propertyAttribute);
}
}
}
+25 -2
View File
@@ -66,8 +66,31 @@ namespace CefSharp
virtual bool Set(const CefString& name, const CefRefPtr<CefV8Value> object, const CefRefPtr<CefV8Value> value,
CefString& exception) override
{
// TODO: implement.
return false;
auto unmanagedWrapper = static_cast<UnmanagedWrapper*>(object->GetUserData().get());
auto clrName = toClr(name);
PropertyInfo^ property;
if (unmanagedWrapper->Properties->TryGetValue(clrName, property))
{
auto wrappedObject = unmanagedWrapper->Get();
if (wrappedObject == nullptr)
{
exception = "Binding's CLR object is null.";
return true;
}
auto clrValue = convertFromCef(value);
property->SetValue(wrappedObject, clrValue, nullptr);
return true;
}
else
{
// Will probably never get here in reality, since V8 knows the name of the properties that exist on this
// object and will only call us for existant properties.
return false;
}
}
IMPLEMENT_REFCOUNTING(PropertyAccessor)