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:
Andreas Kling 2020-03-19 17:39:13 +01:00
commit 1a10470c1d
Notes: sideshowbarker 2024-07-19 08:13:59 +09:00
3 changed files with 32 additions and 9 deletions

View file

@ -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));
}