LibJS: Take PropertyName in Object::set_integrity_level() internal lambda

At least for IntegrityLevel::Frozen we already construct a PropertyName
from the key value, let's reuse that.
This commit is contained in:
Linus Groh 2021-04-20 09:00:11 +02:00
parent 29fd75f22f
commit 085816645f
Notes: sideshowbarker 2024-07-18 19:21:52 +09:00

View file

@ -164,8 +164,7 @@ bool Object::prevent_extensions()
bool Object::set_integrity_level(IntegrityLevel level)
{
// FIXME: This feels clunky and should get nicer abstractions.
auto update_property = [this](auto& key, auto attributes) {
auto property_name = PropertyName::from_value(global_object(), key);
auto update_property = [this](auto& property_name, auto attributes) {
auto metadata = shape().lookup(property_name.to_string_or_symbol());
VERIFY(metadata.has_value());
auto value = get_direct(metadata->offset);
@ -184,7 +183,8 @@ bool Object::set_integrity_level(IntegrityLevel level)
switch (level) {
case IntegrityLevel::Sealed:
for (auto& key : keys) {
update_property(key, ~Attribute::Configurable);
auto property_name = PropertyName::from_value(global_object(), key);
update_property(property_name, ~Attribute::Configurable);
if (vm.exception())
return {};
}
@ -197,7 +197,7 @@ bool Object::set_integrity_level(IntegrityLevel level)
u8 attributes = property_descriptor->is_accessor_descriptor()
? ~Attribute::Configurable
: ~Attribute::Configurable & ~Attribute::Writable;
update_property(key, attributes);
update_property(property_name, attributes);
if (vm.exception())
return {};
}