1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 01:08:11 +00:00

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 Optional<Bytecode::Register> ScopeNode::generate_bytecode(Bytecode::Generator& generator) const
{ {
generator.emit<Bytecode::Op::EnterScope>(*this); generator.emit<Bytecode::Op::EnterScope>(*this);
Optional<Bytecode::Register> last_value_reg;
for (auto& child : children()) { 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 Optional<Bytecode::Register> EmptyStatement::generate_bytecode(Bytecode::Generator&) const