mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 16:17:45 +00:00
LibJS: Update Object::define_accessor() to take both getter and setter
This replaces the current 'function plus boolean indicating the type' API, which makes it easier to set both getter and setter at once. This was already possible before but required two calls of this function, which wasn't intuitive: define_accessor(name, getter, true, ...); define_accessor(name, setter, false, ...); Which now becomes: define_accessor(name, getter, setter, ...);
This commit is contained in:
parent
ec62783af9
commit
275da6fcc9
3 changed files with 36 additions and 29 deletions
|
@ -536,7 +536,7 @@ bool Object::define_property(const PropertyName& property_name, Value value, Pro
|
|||
return put_own_property(property_name.to_string_or_symbol(), value, attributes, PutOwnPropertyMode::DefineProperty, throw_exceptions);
|
||||
}
|
||||
|
||||
bool Object::define_accessor(const PropertyName& property_name, Function& getter_or_setter, bool is_getter, PropertyAttributes attributes, bool throw_exceptions)
|
||||
bool Object::define_accessor(const PropertyName& property_name, Function* getter, Function* setter, PropertyAttributes attributes, bool throw_exceptions)
|
||||
{
|
||||
VERIFY(property_name.is_valid());
|
||||
|
||||
|
@ -548,18 +548,18 @@ bool Object::define_accessor(const PropertyName& property_name, Function& getter
|
|||
accessor = &existing_property.as_accessor();
|
||||
}
|
||||
if (!accessor) {
|
||||
accessor = Accessor::create(vm(), nullptr, nullptr);
|
||||
accessor = Accessor::create(vm(), getter, setter);
|
||||
bool definition_success = define_property(property_name, accessor, attributes, throw_exceptions);
|
||||
if (vm().exception())
|
||||
return {};
|
||||
if (!definition_success)
|
||||
return false;
|
||||
} else {
|
||||
if (getter)
|
||||
accessor->set_getter(getter);
|
||||
if (setter)
|
||||
accessor->set_setter(setter);
|
||||
}
|
||||
if (is_getter)
|
||||
accessor->set_getter(&getter_or_setter);
|
||||
else
|
||||
accessor->set_setter(&getter_or_setter);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue