diff --git a/Tests/LibJS/test-js.cpp b/Tests/LibJS/test-js.cpp index 5da868d4b1..c2246f7574 100644 --- a/Tests/LibJS/test-js.cpp +++ b/Tests/LibJS/test-js.cpp @@ -73,7 +73,7 @@ TESTJS_GLOBAL_FUNCTION(mark_as_garbage, markAsGarbage) return vm.throw_completion(global_object, JS::ErrorType::NotAnObject, String::formatted("Variable with name {}", variable_name.string())); vm.heap().uproot_cell(&value.as_object()); - reference.delete_(global_object); + TRY(reference.delete_(global_object)); return JS::js_undefined(); } diff --git a/Userland/Libraries/LibJS/AST.cpp b/Userland/Libraries/LibJS/AST.cpp index e140edba1a..227fe95140 100644 --- a/Userland/Libraries/LibJS/AST.cpp +++ b/Userland/Libraries/LibJS/AST.cpp @@ -1120,7 +1120,7 @@ Value UnaryExpression::execute(Interpreter& interpreter, GlobalObject& global_ob auto reference = m_lhs->to_reference(interpreter, global_object); if (interpreter.exception()) return {}; - return Value(reference.delete_(global_object)); + return Value(TRY_OR_DISCARD(reference.delete_(global_object))); } Value lhs_result; diff --git a/Userland/Libraries/LibJS/Runtime/Reference.cpp b/Userland/Libraries/LibJS/Runtime/Reference.cpp index 5468feec1a..74133d6ef6 100644 --- a/Userland/Libraries/LibJS/Runtime/Reference.cpp +++ b/Userland/Libraries/LibJS/Runtime/Reference.cpp @@ -97,7 +97,7 @@ Value Reference::get_value(GlobalObject& global_object) const } // 13.5.1.2 Runtime Semantics: Evaluation, https://tc39.es/ecma262/#sec-delete-operator-runtime-semantics-evaluation -bool Reference::delete_(GlobalObject& global_object) +ThrowCompletionOr Reference::delete_(GlobalObject& global_object) { // 13.5.1.2 Runtime Semantics: Evaluation, https://tc39.es/ecma262/#sec-delete-operator-runtime-semantics-evaluation // UnaryExpression : delete UnaryExpression @@ -123,22 +123,18 @@ bool Reference::delete_(GlobalObject& global_object) VERIFY(!is_private_reference()); // b. If IsSuperReference(ref) is true, throw a ReferenceError exception. - if (is_super_reference()) { - vm.throw_exception(global_object, ErrorType::UnsupportedDeleteSuperProperty); - return {}; - } + if (is_super_reference()) + return vm.throw_completion(global_object, ErrorType::UnsupportedDeleteSuperProperty); // c. Let baseObj be ! ToObject(ref.[[Base]]). auto* base_obj = MUST(m_base_value.to_object(global_object)); // d. Let deleteStatus be ? baseObj.[[Delete]](ref.[[ReferencedName]]). - bool delete_status = TRY_OR_DISCARD(base_obj->internal_delete(m_name)); + bool delete_status = TRY(base_obj->internal_delete(m_name)); // e. If deleteStatus is false and ref.[[Strict]] is true, throw a TypeError exception. - if (!delete_status && m_strict) { - vm.throw_exception(global_object, ErrorType::ReferenceNullishDeleteProperty, m_name, m_base_value.to_string_without_side_effects()); - return {}; - } + if (!delete_status && m_strict) + return vm.throw_completion(global_object, ErrorType::ReferenceNullishDeleteProperty, m_name, m_base_value.to_string_without_side_effects()); // f. Return deleteStatus. return delete_status; @@ -151,7 +147,7 @@ bool Reference::delete_(GlobalObject& global_object) VERIFY(m_base_type == BaseType::Environment); // c. Return ? base.DeleteBinding(ref.[[ReferencedName]]). - return TRY_OR_DISCARD(m_base_environment->delete_binding(global_object, m_name.as_string())); + return m_base_environment->delete_binding(global_object, m_name.as_string()); } String Reference::to_string() const diff --git a/Userland/Libraries/LibJS/Runtime/Reference.h b/Userland/Libraries/LibJS/Runtime/Reference.h index ac31b61e61..b720419494 100644 --- a/Userland/Libraries/LibJS/Runtime/Reference.h +++ b/Userland/Libraries/LibJS/Runtime/Reference.h @@ -131,7 +131,7 @@ public: void put_value(GlobalObject&, Value); Value get_value(GlobalObject&) const; - bool delete_(GlobalObject&); + ThrowCompletionOr delete_(GlobalObject&); String to_string() const;