1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 07:38:10 +00:00

LibJS: Remove Interpreter::declare_variable()

Since declarations are now hoisted and handled on scope entry, the job
of a VariableDeclaration becomes to actually initialize variables.

As such, we can remove the part where we insert variables into the
nearest relevant scope. Less work == more speed! :^)
This commit is contained in:
Andreas Kling 2020-04-13 16:45:51 +02:00
parent ac7459cb40
commit 062d6af16e
3 changed files with 0 additions and 23 deletions

View file

@ -122,27 +122,6 @@ void Interpreter::exit_scope(const ScopeNode& scope_node)
m_unwind_until = ScopeType::None;
}
void Interpreter::declare_variable(const FlyString& name, DeclarationKind declaration_kind)
{
switch (declaration_kind) {
case DeclarationKind::Var:
for (ssize_t i = m_scope_stack.size() - 1; i >= 0; --i) {
auto& scope = m_scope_stack.at(i);
if (scope.type == ScopeType::Function) {
scope.variables.set(move(name), { js_undefined(), declaration_kind });
return;
}
}
global_object().put(move(name), js_undefined());
break;
case DeclarationKind::Let:
case DeclarationKind::Const:
m_scope_stack.last().variables.set(move(name), { js_undefined(), declaration_kind });
break;
}
}
void Interpreter::set_variable(const FlyString& name, Value value, bool first_assignment)
{
for (ssize_t i = m_scope_stack.size() - 1; i >= 0; --i) {