LibJS: Make sure scope expressions yield the correct value

When evaluated as an expression "{ 3 }" should yield 3. This updates
the bytecode interpreter to make it so.
This commit is contained in:
Gunnar Beutner
2021-06-07 22:06:02 +02:00
committed by Andreas Kling
parent ed5777eb0a
commit 2c10bd72f2

View File

@@ -21,10 +21,11 @@ Optional<Bytecode::Register> ASTNode::generate_bytecode(Bytecode::Generator&) co
Optional<Bytecode::Register> ScopeNode::generate_bytecode(Bytecode::Generator& generator) const
{
generator.emit<Bytecode::Op::EnterScope>(*this);
Optional<Bytecode::Register> last_value_reg;
for (auto& child : children()) {
[[maybe_unused]] auto reg = child.generate_bytecode(generator);
last_value_reg = child.generate_bytecode(generator);
}
return {};
return last_value_reg;
}
Optional<Bytecode::Register> EmptyStatement::generate_bytecode(Bytecode::Generator&) const