1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 09:28:11 +00:00

LibJS: Hoist function declarations

This patch adds function declaration hoisting. The mechanism
is similar to var hoisting. Hoisted function declarations are to be put
before the hoisted var declarations, hence they have to be treated
separately.
This commit is contained in:
Marcin Gasperowicz 2020-06-04 14:48:36 +02:00 committed by Andreas Kling
parent e162b59a5e
commit 2579d0bf55
6 changed files with 73 additions and 15 deletions

View file

@ -67,10 +67,8 @@ Value ScopeNode::execute(Interpreter& interpreter) const
return interpreter.run(*this);
}
Value FunctionDeclaration::execute(Interpreter& interpreter) const
Value FunctionDeclaration::execute(Interpreter&) const
{
auto* function = ScriptFunction::create(interpreter.global_object(), name(), body(), parameters(), function_length(), interpreter.current_environment());
interpreter.set_variable(name(), function);
return js_undefined();
}
@ -1765,4 +1763,9 @@ void ScopeNode::add_variables(NonnullRefPtrVector<VariableDeclaration> variables
m_variables.append(move(variables));
}
void ScopeNode::add_functions(NonnullRefPtrVector<FunctionDeclaration> functions)
{
m_functions.append(move(functions));
}
}