mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-21 12:05:15 +00:00
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.
This commit is contained in:
parent
38268f1c53
commit
48d2545572
Notes:
sideshowbarker
2024-07-19 00:59:06 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/48d2545572f
6 changed files with 10 additions and 23 deletions
|
@ -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<VariableDeclaration> decls;
|
||||
decls.append(*static_cast<const VariableDeclaration*>(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<BlockStatement>();
|
||||
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();
|
||||
|
|
|
@ -166,8 +166,6 @@ JS_ENUMERATE_ERROR_SUBCLASSES
|
|||
JS_ENUMERATE_TYPED_ARRAYS
|
||||
#undef __JS_ENUMERATE
|
||||
|
||||
struct Argument;
|
||||
|
||||
template<class T>
|
||||
class Handle;
|
||||
|
||||
|
|
|
@ -90,7 +90,7 @@ const GlobalObject& Interpreter::global_object() const
|
|||
return static_cast<const GlobalObject&>(*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<const ScopeNode&>(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());
|
||||
|
|
|
@ -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&);
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -64,13 +64,6 @@ struct CallFrame {
|
|||
bool is_strict_mode { false };
|
||||
};
|
||||
|
||||
struct Argument {
|
||||
FlyString name;
|
||||
Value value;
|
||||
};
|
||||
|
||||
typedef Vector<Argument, 8> ArgumentVector;
|
||||
|
||||
class VM : public RefCounted<VM> {
|
||||
public:
|
||||
static NonnullRefPtr<VM> create();
|
||||
|
|
Loading…
Add table
Reference in a new issue