mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 10:28:10 +00:00
LibJS: Actually leave the current function scope on "return"
We now unwind until the nearest function-level scope on the scope stack when executing a return statement.
This commit is contained in:
parent
df524203b2
commit
494df52961
3 changed files with 13 additions and 6 deletions
|
@ -61,8 +61,13 @@ Value Interpreter::run(const Statement& statement, Vector<Argument> arguments, S
|
|||
Value last_value = js_undefined();
|
||||
for (auto& node : block.children()) {
|
||||
last_value = node.execute(*this);
|
||||
if (m_unwind_until != ScopeType::None)
|
||||
break;
|
||||
}
|
||||
|
||||
if (m_unwind_until == scope_type)
|
||||
m_unwind_until = ScopeType::None;
|
||||
|
||||
exit_scope(block);
|
||||
return last_value;
|
||||
}
|
||||
|
@ -80,11 +85,10 @@ void Interpreter::exit_scope(const ScopeNode& scope_node)
|
|||
{
|
||||
while (m_scope_stack.last().scope_node.ptr() != &scope_node)
|
||||
m_scope_stack.take_last();
|
||||
}
|
||||
|
||||
void Interpreter::do_return()
|
||||
{
|
||||
dbg() << "FIXME: Implement Interpreter::do_return()";
|
||||
// If we unwind all the way, just reset m_unwind_until so that future "return" doesn't break.
|
||||
if (m_scope_stack.is_empty())
|
||||
m_unwind_until = ScopeType::None;
|
||||
}
|
||||
|
||||
void Interpreter::declare_variable(const FlyString& name, DeclarationType declaration_type)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue