mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 14:28:12 +00:00
LibJS: Implement basic object property assignment
This is pretty naive, we just walk up the prototype chain and call any NativeProperty setter that we find. If we don't find one, we put/set the value as an own property of the object itself.
This commit is contained in:
parent
7268499c76
commit
1a10470c1d
3 changed files with 32 additions and 9 deletions
|
@ -60,6 +60,17 @@ Value Object::get(String property_name) const
|
|||
|
||||
void Object::put(String property_name, Value value)
|
||||
{
|
||||
Object* object = this;
|
||||
while (object) {
|
||||
auto value_here = object->m_properties.get(property_name);
|
||||
if (value_here.has_value()) {
|
||||
if (value_here.value().is_object() && value_here.value().as_object()->is_native_property()) {
|
||||
static_cast<NativeProperty*>(value_here.value().as_object())->set(const_cast<Object*>(this), value);
|
||||
return;
|
||||
}
|
||||
}
|
||||
object = object->prototype();
|
||||
}
|
||||
m_properties.set(property_name, move(value));
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue