From ec62783af94bde1fe1724839a2b263da35635710 Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Sat, 10 Apr 2021 17:44:12 +0200 Subject: [PATCH] LibJS: Let Object::delete_property() return a bool, not Value Just like the various define_property functions, this should return a bool directly and let the caller deal with wrapping it in a Value, if necessary. --- Userland/Libraries/LibJS/AST.cpp | 4 ++-- Userland/Libraries/LibJS/Runtime/Object.cpp | 12 ++++++------ Userland/Libraries/LibJS/Runtime/Object.h | 2 +- .../Libraries/LibJS/Runtime/ProxyObject.cpp | 18 +++++++++--------- Userland/Libraries/LibJS/Runtime/ProxyObject.h | 2 +- .../Libraries/LibJS/Runtime/ReflectObject.cpp | 2 +- 6 files changed, 20 insertions(+), 20 deletions(-) diff --git a/Userland/Libraries/LibJS/AST.cpp b/Userland/Libraries/LibJS/AST.cpp index 0ce0d456b3..1816115ed1 100644 --- a/Userland/Libraries/LibJS/AST.cpp +++ b/Userland/Libraries/LibJS/AST.cpp @@ -683,11 +683,11 @@ Value UnaryExpression::execute(Interpreter& interpreter, GlobalObject& global_ob // FIXME: Support deleting locals VERIFY(!reference.is_local_variable()); if (reference.is_global_variable()) - return global_object.delete_property(reference.name()); + return Value(global_object.delete_property(reference.name())); auto* base_object = reference.base().to_object(global_object); if (!base_object) return {}; - return base_object->delete_property(reference.name()); + return Value(base_object->delete_property(reference.name())); } Value lhs_result; diff --git a/Userland/Libraries/LibJS/Runtime/Object.cpp b/Userland/Libraries/LibJS/Runtime/Object.cpp index 2a92344f46..aa42fda180 100644 --- a/Userland/Libraries/LibJS/Runtime/Object.cpp +++ b/Userland/Libraries/LibJS/Runtime/Object.cpp @@ -711,24 +711,24 @@ bool Object::put_own_property_by_index(u32 property_index, Value value, Property return true; } -Value Object::delete_property(const PropertyName& property_name) +bool Object::delete_property(const PropertyName& property_name) { VERIFY(property_name.is_valid()); if (property_name.is_number()) - return Value(m_indexed_properties.remove(property_name.as_number())); + return m_indexed_properties.remove(property_name.as_number()); if (property_name.is_string()) { i32 property_index = property_name.as_string().to_int().value_or(-1); if (property_index >= 0) - return Value(m_indexed_properties.remove(property_index)); + return m_indexed_properties.remove(property_index); } auto metadata = shape().lookup(property_name.to_string_or_symbol()); if (!metadata.has_value()) - return Value(true); + return true; if (!metadata.value().attributes.is_configurable()) - return Value(false); + return false; size_t deleted_offset = metadata.value().offset; @@ -736,7 +736,7 @@ Value Object::delete_property(const PropertyName& property_name) shape().remove_property_from_unique_shape(property_name.to_string_or_symbol(), deleted_offset); m_storage.remove(deleted_offset); - return Value(true); + return true; } void Object::ensure_shape_is_unique() diff --git a/Userland/Libraries/LibJS/Runtime/Object.h b/Userland/Libraries/LibJS/Runtime/Object.h index bcfc660c8b..7ad8c91a9c 100644 --- a/Userland/Libraries/LibJS/Runtime/Object.h +++ b/Userland/Libraries/LibJS/Runtime/Object.h @@ -115,7 +115,7 @@ public: bool define_native_function(const StringOrSymbol& property_name, AK::Function, i32 length = 0, PropertyAttributes attributes = default_attributes); bool define_native_property(const StringOrSymbol& property_name, AK::Function getter, AK::Function setter, PropertyAttributes attributes = default_attributes); - virtual Value delete_property(const PropertyName&); + virtual bool delete_property(const PropertyName&); virtual bool is_array() const { return false; } virtual bool is_function() const { return false; } diff --git a/Userland/Libraries/LibJS/Runtime/ProxyObject.cpp b/Userland/Libraries/LibJS/Runtime/ProxyObject.cpp index 7f1add5238..59c3201b5d 100644 --- a/Userland/Libraries/LibJS/Runtime/ProxyObject.cpp +++ b/Userland/Libraries/LibJS/Runtime/ProxyObject.cpp @@ -390,33 +390,33 @@ bool ProxyObject::put(const PropertyName& name, Value value, Value receiver) return true; } -Value ProxyObject::delete_property(const PropertyName& name) +bool ProxyObject::delete_property(const PropertyName& name) { auto& vm = this->vm(); if (m_is_revoked) { vm.throw_exception(global_object(), ErrorType::ProxyRevoked); - return {}; + return false; } auto trap = get_method(global_object(), Value(&m_handler), vm.names.deleteProperty); if (vm.exception()) - return {}; + return false; if (!trap) return m_target.delete_property(name); auto trap_result = vm.call(*trap, Value(&m_handler), Value(&m_target), name.to_value(vm)); if (vm.exception()) - return {}; + return false; if (!trap_result.to_boolean()) - return Value(false); + return false; auto target_desc = m_target.get_own_property_descriptor(name); if (vm.exception()) - return {}; + return false; if (!target_desc.has_value()) - return Value(true); + return true; if (!target_desc.value().attributes.is_configurable()) { vm.throw_exception(global_object(), ErrorType::ProxyDeleteNonConfigurable); - return {}; + return false; } - return Value(true); + return true; } void ProxyObject::visit_edges(Cell::Visitor& visitor) diff --git a/Userland/Libraries/LibJS/Runtime/ProxyObject.h b/Userland/Libraries/LibJS/Runtime/ProxyObject.h index 70f30fac2c..046c985c14 100644 --- a/Userland/Libraries/LibJS/Runtime/ProxyObject.h +++ b/Userland/Libraries/LibJS/Runtime/ProxyObject.h @@ -57,7 +57,7 @@ public: virtual bool has_property(const PropertyName& name) const override; virtual Value get(const PropertyName& name, Value receiver) const override; virtual bool put(const PropertyName& name, Value value, Value receiver) override; - virtual Value delete_property(const PropertyName& name) override; + virtual bool delete_property(const PropertyName& name) override; void revoke() { m_is_revoked = true; } diff --git a/Userland/Libraries/LibJS/Runtime/ReflectObject.cpp b/Userland/Libraries/LibJS/Runtime/ReflectObject.cpp index 7e936abb7c..eec0f113f9 100644 --- a/Userland/Libraries/LibJS/Runtime/ReflectObject.cpp +++ b/Userland/Libraries/LibJS/Runtime/ReflectObject.cpp @@ -176,7 +176,7 @@ JS_DEFINE_NATIVE_FUNCTION(ReflectObject::delete_property) if (property_key_as_double >= 0 && (i32)property_key_as_double == property_key_as_double) property_name = PropertyName(property_key_as_double); } - return target->delete_property(property_name); + return Value(target->delete_property(property_name)); } JS_DEFINE_NATIVE_FUNCTION(ReflectObject::get)