mirror of
https://github.com/cefsharp/CefSharp.git
synced 2026-12-04 10:22:55 +00:00
Added support for property setting.
This commit is contained in:
committed by
Per Lundberg
parent
35dfcebe1a
commit
36bf863329
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user