From 48d2545572f1281bd9526f64798e51ecc862bb93 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Tue, 8 Dec 2020 18:21:55 +0100 Subject: [PATCH] LibJS: Get rid of Argument and ArgumentVector This was used for a feature where you could pass a vector of arguments to enter_scope(). Since that way of passing arguments was not GC-aware (as vectors use C++ heap storage), let's avoid using it and make sure everything that needs to stay alive is either on the stack or in traced storage instead. --- Libraries/LibJS/AST.cpp | 8 ++++---- Libraries/LibJS/Forward.h | 2 -- Libraries/LibJS/Interpreter.cpp | 10 +++------- Libraries/LibJS/Interpreter.h | 4 ++-- Libraries/LibJS/Runtime/ScriptFunction.cpp | 2 +- Libraries/LibJS/Runtime/VM.h | 7 ------- 6 files changed, 10 insertions(+), 23 deletions(-) diff --git a/Libraries/LibJS/AST.cpp b/Libraries/LibJS/AST.cpp index 89aefe544f..154c3a2719 100644 --- a/Libraries/LibJS/AST.cpp +++ b/Libraries/LibJS/AST.cpp @@ -93,7 +93,7 @@ Value ScopeNode::execute(Interpreter& interpreter, GlobalObject& global_object) Value Program::execute(Interpreter& interpreter, GlobalObject& global_object) const { - return interpreter.execute_statement(global_object, *this, {}, ScopeType::Block); + return interpreter.execute_statement(global_object, *this, ScopeType::Block); } Value FunctionDeclaration::execute(Interpreter&, GlobalObject&) const @@ -340,7 +340,7 @@ Value ForStatement::execute(Interpreter& interpreter, GlobalObject& global_objec NonnullRefPtrVector decls; decls.append(*static_cast(m_init.ptr())); wrapper->add_variables(decls); - interpreter.enter_scope(*wrapper, {}, ScopeType::Block, global_object); + interpreter.enter_scope(*wrapper, ScopeType::Block, global_object); } auto wrapper_cleanup = ScopeGuard([&] { @@ -416,7 +416,7 @@ static FlyString variable_from_for_declaration(Interpreter& interpreter, GlobalO ASSERT(!variable_declaration->declarations().is_empty()); if (variable_declaration->declaration_kind() != DeclarationKind::Var) { wrapper = create_ast_node(); - interpreter.enter_scope(*wrapper, {}, ScopeType::Block, global_object); + interpreter.enter_scope(*wrapper, ScopeType::Block, global_object); } variable_declaration->execute(interpreter, global_object); variable_name = variable_declaration->declarations().first().id().string(); @@ -1897,7 +1897,7 @@ void ThrowStatement::dump(int indent) const Value TryStatement::execute(Interpreter& interpreter, GlobalObject& global_object) const { - interpreter.execute_statement(global_object, m_block, {}, ScopeType::Try); + interpreter.execute_statement(global_object, m_block, ScopeType::Try); if (auto* exception = interpreter.exception()) { if (m_handler) { interpreter.vm().clear_exception(); diff --git a/Libraries/LibJS/Forward.h b/Libraries/LibJS/Forward.h index 4275607604..bb6412f506 100644 --- a/Libraries/LibJS/Forward.h +++ b/Libraries/LibJS/Forward.h @@ -166,8 +166,6 @@ JS_ENUMERATE_ERROR_SUBCLASSES JS_ENUMERATE_TYPED_ARRAYS #undef __JS_ENUMERATE -struct Argument; - template class Handle; diff --git a/Libraries/LibJS/Interpreter.cpp b/Libraries/LibJS/Interpreter.cpp index d57b90f5c5..b6a35610e6 100644 --- a/Libraries/LibJS/Interpreter.cpp +++ b/Libraries/LibJS/Interpreter.cpp @@ -90,7 +90,7 @@ const GlobalObject& Interpreter::global_object() const return static_cast(*m_global_object.cell()); } -void Interpreter::enter_scope(const ScopeNode& scope_node, ArgumentVector arguments, ScopeType scope_type, GlobalObject& global_object) +void Interpreter::enter_scope(const ScopeNode& scope_node, ScopeType scope_type, GlobalObject& global_object) { for (auto& declaration : scope_node.functions()) { auto* function = ScriptFunction::create(global_object, declaration.name(), declaration.body(), declaration.parameters(), declaration.function_length(), current_scope(), declaration.is_strict_mode()); @@ -117,10 +117,6 @@ void Interpreter::enter_scope(const ScopeNode& scope_node, ArgumentVector argume } } - for (auto& argument : arguments) { - scope_variables_with_declaration_kind.set(argument.name, { argument.value, DeclarationKind::Var }); - } - bool pushed_lexical_environment = false; if (!scope_variables_with_declaration_kind.is_empty()) { @@ -152,13 +148,13 @@ void Interpreter::push_scope(ScopeFrame frame) m_scope_stack.append(move(frame)); } -Value Interpreter::execute_statement(GlobalObject& global_object, const Statement& statement, ArgumentVector arguments, ScopeType scope_type) +Value Interpreter::execute_statement(GlobalObject& global_object, const Statement& statement, ScopeType scope_type) { if (!statement.is_scope_node()) return statement.execute(*this, global_object); auto& block = static_cast(statement); - enter_scope(block, move(arguments), scope_type, global_object); + enter_scope(block, scope_type, global_object); if (block.children().is_empty()) vm().set_last_value({}, js_undefined()); diff --git a/Libraries/LibJS/Interpreter.h b/Libraries/LibJS/Interpreter.h index e9a89d7993..9d27ac9c2c 100644 --- a/Libraries/LibJS/Interpreter.h +++ b/Libraries/LibJS/Interpreter.h @@ -74,10 +74,10 @@ public: ScopeObject* current_scope() { return vm().current_scope(); } LexicalEnvironment* current_environment(); - void enter_scope(const ScopeNode&, ArgumentVector, ScopeType, GlobalObject&); + void enter_scope(const ScopeNode&, ScopeType, GlobalObject&); void exit_scope(const ScopeNode&); - Value execute_statement(GlobalObject&, const Statement&, ArgumentVector = {}, ScopeType = ScopeType::Block); + Value execute_statement(GlobalObject&, const Statement&, ScopeType = ScopeType::Block); private: explicit Interpreter(VM&); diff --git a/Libraries/LibJS/Runtime/ScriptFunction.cpp b/Libraries/LibJS/Runtime/ScriptFunction.cpp index 1b39fbb6eb..bea77a1eae 100644 --- a/Libraries/LibJS/Runtime/ScriptFunction.cpp +++ b/Libraries/LibJS/Runtime/ScriptFunction.cpp @@ -147,7 +147,7 @@ Value ScriptFunction::execute_function_body() vm.current_scope()->put_to_scope(parameter.name, { argument_value, DeclarationKind::Var }); } - return interpreter->execute_statement(global_object(), m_body, {}, ScopeType::Function); + return interpreter->execute_statement(global_object(), m_body, ScopeType::Function); } Value ScriptFunction::call() diff --git a/Libraries/LibJS/Runtime/VM.h b/Libraries/LibJS/Runtime/VM.h index c504d71e84..0b74f28d7b 100644 --- a/Libraries/LibJS/Runtime/VM.h +++ b/Libraries/LibJS/Runtime/VM.h @@ -64,13 +64,6 @@ struct CallFrame { bool is_strict_mode { false }; }; -struct Argument { - FlyString name; - Value value; -}; - -typedef Vector ArgumentVector; - class VM : public RefCounted { public: static NonnullRefPtr create();