diff options
author | Andreas Kling <kling@serenityos.org> | 2020-03-23 19:19:03 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-03-23 19:22:24 +0100 |
commit | 494df529613e1b68619281c6b0cfa6729dac375f (patch) | |
tree | de485734e83fb4207fd7bfaaa15ffcf3f1634274 /Libraries/LibJS/Interpreter.cpp | |
parent | df524203b2ebbe16356e594e9cd6ab845caa15dd (diff) | |
download | serenity-494df529613e1b68619281c6b0cfa6729dac375f.zip |
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.
Diffstat (limited to 'Libraries/LibJS/Interpreter.cpp')
-rw-r--r-- | Libraries/LibJS/Interpreter.cpp | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/Libraries/LibJS/Interpreter.cpp b/Libraries/LibJS/Interpreter.cpp index ac80f688b0..f602336bc4 100644 --- a/Libraries/LibJS/Interpreter.cpp +++ b/Libraries/LibJS/Interpreter.cpp @@ -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) |