Browse Source

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.
pull/2741/head
raskad 2 years ago
parent
commit
b9ad5bcdd0
  1. 6
      boa_engine/src/bytecompiler/statement/if.rs
  2. 2
      boa_engine/src/bytecompiler/statement/mod.rs

6
boa_engine/src/bytecompiler/statement/if.rs

@ -2,11 +2,11 @@ use crate::bytecompiler::ByteCompiler;
use boa_ast::statement::If; use boa_ast::statement::If;
impl ByteCompiler<'_, '_> { 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); self.compile_expr(node.cond(), true);
let jelse = self.jump_if_false(); 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() { match node.else_node() {
None => { None => {
@ -15,7 +15,7 @@ impl ByteCompiler<'_, '_> {
Some(else_body) => { Some(else_body) => {
let exit = self.jump(); let exit = self.jump();
self.patch_jump(jelse); 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); self.patch_jump(exit);
} }
} }

2
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) { pub fn compile_stmt(&mut self, node: &Statement, use_expr: bool, configurable_globals: bool) {
match node { match node {
Statement::Var(var) => self.compile_var_decl(var), 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) => { Statement::ForLoop(for_loop) => {
self.compile_for_loop(for_loop, None, configurable_globals); self.compile_for_loop(for_loop, None, configurable_globals);
} }

Loading…
Cancel
Save