From b9ad5bcdd07ceba03a458b18219fbbecf7778e0c Mon Sep 17 00:00:00 2001 From: raskad <32105367+raskad@users.noreply.github.com> Date: Sat, 25 Mar 2023 11:26:21 +0000 Subject: [PATCH] Make if statements return their completion values (#2739) This Pull Request changes the following: - Adjust if statement execution to leave their resulting values on the stack when needed. --- boa_engine/src/bytecompiler/statement/if.rs | 6 +++--- boa_engine/src/bytecompiler/statement/mod.rs | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/boa_engine/src/bytecompiler/statement/if.rs b/boa_engine/src/bytecompiler/statement/if.rs index 73ace44ba2..5cf93979fd 100644 --- a/boa_engine/src/bytecompiler/statement/if.rs +++ b/boa_engine/src/bytecompiler/statement/if.rs @@ -2,11 +2,11 @@ use crate::bytecompiler::ByteCompiler; use boa_ast::statement::If; impl ByteCompiler<'_, '_> { - pub(crate) fn compile_if(&mut self, node: &If, configurable_globals: bool) { + pub(crate) fn compile_if(&mut self, node: &If, use_expr: bool, configurable_globals: bool) { self.compile_expr(node.cond(), true); let jelse = self.jump_if_false(); - self.compile_stmt(node.body(), false, configurable_globals); + self.compile_stmt(node.body(), use_expr, configurable_globals); match node.else_node() { None => { @@ -15,7 +15,7 @@ impl ByteCompiler<'_, '_> { Some(else_body) => { let exit = self.jump(); self.patch_jump(jelse); - self.compile_stmt(else_body, false, configurable_globals); + self.compile_stmt(else_body, use_expr, configurable_globals); self.patch_jump(exit); } } diff --git a/boa_engine/src/bytecompiler/statement/mod.rs b/boa_engine/src/bytecompiler/statement/mod.rs index 36688a2d1f..bb32585a7b 100644 --- a/boa_engine/src/bytecompiler/statement/mod.rs +++ b/boa_engine/src/bytecompiler/statement/mod.rs @@ -17,7 +17,7 @@ impl ByteCompiler<'_, '_> { pub fn compile_stmt(&mut self, node: &Statement, use_expr: bool, configurable_globals: bool) { match node { Statement::Var(var) => self.compile_var_decl(var), - Statement::If(node) => self.compile_if(node, configurable_globals), + Statement::If(node) => self.compile_if(node, use_expr, configurable_globals), Statement::ForLoop(for_loop) => { self.compile_for_loop(for_loop, None, configurable_globals); }