diff --git a/boa_engine/src/bytecompiler/env.rs b/boa_engine/src/bytecompiler/env.rs index ffe025a94d3..7d189de9fe7 100644 --- a/boa_engine/src/bytecompiler/env.rs +++ b/boa_engine/src/bytecompiler/env.rs @@ -7,6 +7,7 @@ use boa_ast::expression::Identifier; impl ByteCompiler<'_, '_> { /// Push either a new declarative or function environment on the compile time environment stack. pub(crate) fn push_compile_environment(&mut self, function_scope: bool) { + self.current_open_environments_count += 1; self.current_environment = Rc::new(RefCell::new(CompileTimeEnvironment::new( self.current_environment.clone(), function_scope, @@ -16,6 +17,7 @@ impl ByteCompiler<'_, '_> { /// Pops the top compile time environment and returns its index in the compile time environments array. #[track_caller] pub(crate) fn pop_compile_environment(&mut self) -> u32 { + self.current_open_environments_count -= 1; let index = self.compile_environments.len() as u32; self.compile_environments .push(self.current_environment.clone()); diff --git a/boa_engine/src/bytecompiler/jump_control.rs b/boa_engine/src/bytecompiler/jump_control.rs index 0c86fbd0ba4..a58e29853b1 100644 --- a/boa_engine/src/bytecompiler/jump_control.rs +++ b/boa_engine/src/bytecompiler/jump_control.rs @@ -9,19 +9,59 @@ //! [try spec]: https://tc39.es/ecma262/#sec-try-statement //! [labelled spec]: https://tc39.es/ecma262/#sec-labelled-statements -use crate::bytecompiler::{ByteCompiler, Label}; +use crate::{ + bytecompiler::{ByteCompiler, Label}, + vm::Opcode, +}; use bitflags::bitflags; use boa_interner::Sym; +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub(crate) enum JumpRecordKind { + Break, + Continue, +} + +#[derive(Debug, Clone, Copy)] +pub(crate) struct JumpRecord { + kind: JumpRecordKind, + label: Option, + address: Label, + target_index: Option, +} + +impl JumpRecord { + pub(crate) const fn new( + kind: JumpRecordKind, + label: Option, + address: Label, + target_index: Option, + ) -> Self { + Self { + kind, + label, + address, + target_index, + } + } + + pub(crate) const fn label(&self) -> Option { + self.label + } + + pub(crate) const fn target_index(&self) -> Option { + self.target_index + } +} + /// Boa's `ByteCompiler` jump information tracking struct. #[derive(Debug, Clone)] pub(crate) struct JumpControlInfo { label: Option, start_address: u32, flags: JumpControlInfoFlags, - set_jumps: Vec