From 231d58dd62a56d9229f8299b11787b51a29addbf Mon Sep 17 00:00:00 2001 From: Aliaksandr Kalenik Date: Thu, 20 Jul 2023 16:43:32 +0200 Subject: [PATCH] LibJS: Delete Declaration::for_each_bound_name We can delete for_each_bound_name() because there is more generic version of this function called for_each_bound_identifier() that gives you identifier using which you can get both name and check if it is local/global. --- Userland/Libraries/LibJS/AST.cpp | 59 -------------------------------- Userland/Libraries/LibJS/AST.h | 15 -------- 2 files changed, 74 deletions(-) diff --git a/Userland/Libraries/LibJS/AST.cpp b/Userland/Libraries/LibJS/AST.cpp index c3147d4c51a..d94f81ed519 100644 --- a/Userland/Libraries/LibJS/AST.cpp +++ b/Userland/Libraries/LibJS/AST.cpp @@ -2296,14 +2296,6 @@ void ClassDeclaration::dump(int indent) const m_class_expression->dump(indent + 1); } -ThrowCompletionOr ClassDeclaration::for_each_bound_name(ThrowCompletionOrVoidCallback&& callback) const -{ - if (m_class_expression->name().is_empty()) - return {}; - - return callback(m_class_expression->name()); -} - ThrowCompletionOr ClassDeclaration::for_each_bound_identifier(ThrowCompletionOrVoidCallback&& callback) const { if (!m_class_expression->m_name) @@ -2434,23 +2426,6 @@ bool BindingPattern::contains_expression() const return false; } -ThrowCompletionOr BindingPattern::for_each_bound_name(ThrowCompletionOrVoidCallback&& callback) const -{ - for (auto const& entry : entries) { - auto const& alias = entry.alias; - if (alias.has>()) { - TRY(callback(alias.get>()->string())); - } else if (alias.has>()) { - TRY(alias.get>()->for_each_bound_name(forward(callback))); - } else { - auto const& name = entry.name; - if (name.has>()) - TRY(callback(name.get>()->string())); - } - } - return {}; -} - ThrowCompletionOr BindingPattern::for_each_bound_identifier(ThrowCompletionOrVoidCallback&& callback) const { for (auto const& entry : entries) { @@ -2558,13 +2533,6 @@ void FunctionDeclaration::dump(int indent) const FunctionNode::dump(indent, class_name()); } -ThrowCompletionOr FunctionDeclaration::for_each_bound_name(ThrowCompletionOrVoidCallback&& callback) const -{ - if (name().is_empty()) - return {}; - return callback(name()); -} - ThrowCompletionOr FunctionDeclaration::for_each_bound_identifier(ThrowCompletionOrVoidCallback&& callback) const { if (!m_name) @@ -3115,23 +3083,6 @@ Completion VariableDeclarator::execute(Interpreter& interpreter) const VERIFY_NOT_REACHED(); } -ThrowCompletionOr VariableDeclaration::for_each_bound_name(ThrowCompletionOrVoidCallback&& callback) const -{ - for (auto const& entry : declarations()) { - TRY(entry->target().visit( - [&](NonnullRefPtr const& id) { - return callback(id->string()); - }, - [&](NonnullRefPtr const& binding) { - return binding->for_each_bound_identifier([&](auto const& identifier) { - return callback(identifier.string()); - }); - })); - } - - return {}; -} - ThrowCompletionOr VariableDeclaration::for_each_bound_identifier(ThrowCompletionOrVoidCallback&& callback) const { for (auto const& entry : declarations()) { @@ -3196,16 +3147,6 @@ Completion UsingDeclaration::execute(Interpreter& interpreter) const return normal_completion({}); } -ThrowCompletionOr UsingDeclaration::for_each_bound_name(ThrowCompletionOrVoidCallback&& callback) const -{ - for (auto const& entry : m_declarations) { - VERIFY(entry->target().has>()); - TRY(callback(entry->target().get>()->string())); - } - - return {}; -} - ThrowCompletionOr UsingDeclaration::for_each_bound_identifier(ThrowCompletionOrVoidCallback&& callback) const { for (auto const& entry : m_declarations) { diff --git a/Userland/Libraries/LibJS/AST.h b/Userland/Libraries/LibJS/AST.h index 8c8d9f36d7a..61e32129cb1 100644 --- a/Userland/Libraries/LibJS/AST.h +++ b/Userland/Libraries/LibJS/AST.h @@ -609,7 +609,6 @@ public: { } - virtual ThrowCompletionOr for_each_bound_name(ThrowCompletionOrVoidCallback&& callback) const = 0; virtual ThrowCompletionOr for_each_bound_identifier(ThrowCompletionOrVoidCallback&& callback) const = 0; // 8.1.3 Static Semantics: IsConstantDeclaration, https://tc39.es/ecma262/#sec-static-semantics-isconstantdeclaration @@ -626,11 +625,6 @@ public: } Completion execute(Interpreter&) const override { return {}; } - ThrowCompletionOr for_each_bound_name(ThrowCompletionOrVoidCallback&&) const override - { - VERIFY_NOT_REACHED(); - } - ThrowCompletionOr for_each_bound_identifier(ThrowCompletionOrVoidCallback&&) const override { VERIFY_NOT_REACHED(); @@ -656,7 +650,6 @@ struct BindingPattern : RefCounted { void dump(int indent) const; - ThrowCompletionOr for_each_bound_name(ThrowCompletionOrVoidCallback&& callback) const; ThrowCompletionOr for_each_bound_identifier(ThrowCompletionOrVoidCallback&& callback) const; bool contains_expression() const; @@ -774,8 +767,6 @@ public: virtual void dump(int indent) const override; virtual Bytecode::CodeGenerationErrorOr generate_bytecode(Bytecode::Generator&) const override; - virtual ThrowCompletionOr for_each_bound_name(ThrowCompletionOrVoidCallback&& callback) const override; - ThrowCompletionOr for_each_bound_identifier(ThrowCompletionOrVoidCallback&&) const override; virtual bool is_function_declaration() const override { return true; } @@ -1496,8 +1487,6 @@ public: virtual void dump(int indent) const override; virtual Bytecode::CodeGenerationErrorOr generate_bytecode(Bytecode::Generator&) const override; - virtual ThrowCompletionOr for_each_bound_name(ThrowCompletionOrVoidCallback&& callback) const override; - ThrowCompletionOr for_each_bound_identifier(ThrowCompletionOrVoidCallback&&) const override; virtual bool is_lexical_declaration() const override { return true; } @@ -1804,8 +1793,6 @@ public: Vector> const& declarations() const { return m_declarations; } - virtual ThrowCompletionOr for_each_bound_name(ThrowCompletionOrVoidCallback&& callback) const override; - ThrowCompletionOr for_each_bound_identifier(ThrowCompletionOrVoidCallback&&) const override; virtual bool is_constant_declaration() const override { return m_declaration_kind == DeclarationKind::Const; } @@ -1830,8 +1817,6 @@ public: virtual Completion execute(Interpreter&) const override; virtual void dump(int indent) const override; - virtual ThrowCompletionOr for_each_bound_name(ThrowCompletionOrVoidCallback&& callback) const override; - ThrowCompletionOr for_each_bound_identifier(ThrowCompletionOrVoidCallback&&) const override; virtual bool is_constant_declaration() const override { return true; }