1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 03:27:45 +00:00

LibJS: Add parameter to delete_property since we need DeleteOrThrow

This commit is contained in:
davidot 2021-06-21 16:06:32 +02:00 committed by Linus Groh
parent 8a06a93ce2
commit 16b87b85e3
4 changed files with 16 additions and 9 deletions

View file

@ -768,18 +768,25 @@ bool Object::put_own_property_by_index(u32 property_index, Value value, Property
return true; return true;
} }
bool Object::delete_property(const PropertyName& property_name) bool Object::delete_property(PropertyName const& property_name, bool force_throw_exception)
{ {
VERIFY(property_name.is_valid()); VERIFY(property_name.is_valid());
if (property_name.is_number()) if (property_name.is_number()) {
return m_indexed_properties.remove(property_name.as_number()); if (!m_indexed_properties.remove(property_name.as_number())) {
if (force_throw_exception || vm().in_strict_mode())
vm().throw_exception<TypeError>(global_object(), ErrorType::DescChangeNonConfigurable, property_name.as_number());
return false;
}
return true;
}
auto metadata = shape().lookup(property_name.to_string_or_symbol()); auto metadata = shape().lookup(property_name.to_string_or_symbol());
if (!metadata.has_value()) if (!metadata.has_value())
return true; return true;
if (!metadata.value().attributes.is_configurable()) { if (!metadata.value().attributes.is_configurable()) {
if (vm().in_strict_mode()) if (force_throw_exception || vm().in_strict_mode())
vm().throw_exception<TypeError>(global_object(), ErrorType::DescChangeNonConfigurable, property_name.to_string_or_symbol().to_display_string()); vm().throw_exception<TypeError>(global_object(), ErrorType::DescChangeNonConfigurable, property_name.to_string_or_symbol().to_display_string());
return false; return false;
} }
@ -879,7 +886,7 @@ bool Object::put_by_index(u32 property_index, Value value)
if (vm().exception()) if (vm().exception())
return {}; return {};
} }
return put_own_property_by_index(property_index, value, default_attributes, PutOwnPropertyMode::Put); return put_own_property_by_index(property_index, value, default_attributes, PutOwnPropertyMode::Put, vm().in_strict_mode());
} }
bool Object::put(const PropertyName& property_name, Value value, Value receiver) bool Object::put(const PropertyName& property_name, Value value, Value receiver)

View file

@ -99,7 +99,7 @@ public:
void define_properties(Value properties); void define_properties(Value properties);
virtual bool delete_property(const PropertyName&); virtual bool delete_property(PropertyName const&, bool force_throw_exception = false);
virtual bool is_array() const { return false; } virtual bool is_array() const { return false; }
virtual bool is_function() const { return false; } virtual bool is_function() const { return false; }

View file

@ -375,7 +375,7 @@ bool ProxyObject::put(const PropertyName& name, Value value, Value receiver)
return true; return true;
} }
bool ProxyObject::delete_property(const PropertyName& name) bool ProxyObject::delete_property(PropertyName const& name, bool force_throw_exception)
{ {
auto& vm = this->vm(); auto& vm = this->vm();
if (m_is_revoked) { if (m_is_revoked) {
@ -386,7 +386,7 @@ bool ProxyObject::delete_property(const PropertyName& name)
if (vm.exception()) if (vm.exception())
return false; return false;
if (!trap) if (!trap)
return m_target.delete_property(name); return m_target.delete_property(name, force_throw_exception);
auto trap_result = vm.call(*trap, Value(&m_handler), Value(&m_target), name.to_value(vm)); auto trap_result = vm.call(*trap, Value(&m_handler), Value(&m_target), name.to_value(vm));
if (vm.exception()) if (vm.exception())
return false; return false;

View file

@ -37,7 +37,7 @@ public:
virtual bool has_property(const PropertyName& name) const override; virtual bool has_property(const PropertyName& name) const override;
virtual Value get(const PropertyName& name, Value receiver, AllowSideEffects = AllowSideEffects::Yes) const override; virtual Value get(const PropertyName& name, Value receiver, AllowSideEffects = AllowSideEffects::Yes) const override;
virtual bool put(const PropertyName& name, Value value, Value receiver) override; virtual bool put(const PropertyName& name, Value value, Value receiver) override;
virtual bool delete_property(const PropertyName& name) override; virtual bool delete_property(PropertyName const& name, bool force_throw_exception = false) override;
bool is_revoked() const { return m_is_revoked; } bool is_revoked() const { return m_is_revoked; }
void revoke() { m_is_revoked = true; } void revoke() { m_is_revoked = true; }