mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-22 12:35:14 +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:
parent
ac7459cb40
commit
062d6af16e
Notes:
sideshowbarker
2024-07-19 07:37:48 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/062d6af16ed
3 changed files with 0 additions and 23 deletions
|
@ -828,7 +828,6 @@ void UpdateExpression::dump(int indent) const
|
|||
Value VariableDeclaration::execute(Interpreter& interpreter) const
|
||||
{
|
||||
for (auto& declarator : m_declarations) {
|
||||
interpreter.declare_variable(declarator.id().string(), m_declaration_kind);
|
||||
if (auto* init = declarator.init()) {
|
||||
auto initalizer_result = init->execute(interpreter);
|
||||
if (interpreter.exception())
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -96,7 +96,6 @@ public:
|
|||
|
||||
Optional<Value> get_variable(const FlyString& name);
|
||||
void set_variable(const FlyString& name, Value, bool first_assignment = false);
|
||||
void declare_variable(const FlyString& name, DeclarationKind);
|
||||
|
||||
void gather_roots(Badge<Heap>, HashTable<Cell*>&);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue