diff --git a/boa_cli/src/debug/function.rs b/boa_cli/src/debug/function.rs index 3c6736da8c..6ace746f9d 100644 --- a/boa_cli/src/debug/function.rs +++ b/boa_cli/src/debug/function.rs @@ -135,7 +135,7 @@ fn set_trace_flag_in_function_object(object: &JsObject, value: bool) -> JsResult let code = function.codeblock().ok_or_else(|| { JsNativeError::typ().with_message("native functions do not have bytecode") })?; - code.set_trace(value); + code.set_traceable(value); Ok(()) } diff --git a/boa_engine/src/builtins/eval/mod.rs b/boa_engine/src/builtins/eval/mod.rs index 0a4f0b3815..443d3249a4 100644 --- a/boa_engine/src/builtins/eval/mod.rs +++ b/boa_engine/src/builtins/eval/mod.rs @@ -232,14 +232,15 @@ impl Eval { ); compiler.push_compile_environment(strict); - let push_env = compiler.emit_opcode_with_two_operands(Opcode::PushDeclarativeEnvironment); + + let push_env = compiler.emit_opcode_with_operand(Opcode::PushDeclarativeEnvironment); compiler.eval_declaration_instantiation(&body, strict)?; compiler.compile_statement_list(body.statements(), true, false); - let env_info = compiler.pop_compile_environment(); - compiler.patch_jump_with_target(push_env.0, env_info.num_bindings); - compiler.patch_jump_with_target(push_env.1, env_info.index); + let env_index = compiler.pop_compile_environment(); + compiler.patch_jump_with_target(push_env, env_index); + compiler.emit_opcode(Opcode::PopEnvironment); let code_block = Gc::new(compiler.finish()); diff --git a/boa_engine/src/bytecompiler/class.rs b/boa_engine/src/bytecompiler/class.rs index f4b9ea0cbc..bf9e4b14e3 100644 --- a/boa_engine/src/bytecompiler/class.rs +++ b/boa_engine/src/bytecompiler/class.rs @@ -1,5 +1,5 @@ use super::{ByteCompiler, Literal}; -use crate::vm::{BindingOpcode, Opcode}; +use crate::vm::{BindingOpcode, CodeBlockFlags, Opcode}; use boa_ast::{ expression::Identifier, function::{Class, ClassElement, FormalParameterList}, @@ -27,7 +27,7 @@ impl ByteCompiler<'_, '_> { if let Some(class_name) = class.name() { if class.has_binding_identifier() { - compiler.has_binding_identifier = true; + compiler.code_block_flags |= CodeBlockFlags::HAS_BINDING_IDENTIFIER; compiler.push_compile_environment(false); compiler.create_immutable_binding(class_name, true); } @@ -39,7 +39,7 @@ impl ByteCompiler<'_, '_> { compiler.length = expr.parameters().length(); compiler.params = expr.parameters().clone(); - let (env_labels, _) = compiler.function_declaration_instantiation( + let (env_label, _) = compiler.function_declaration_instantiation( expr.body(), expr.parameters(), false, @@ -49,23 +49,20 @@ impl ByteCompiler<'_, '_> { compiler.compile_statement_list(expr.body().statements(), false, false); - let env_info = compiler.pop_compile_environment(); + let env_index = compiler.pop_compile_environment(); - if let Some(env_labels) = env_labels { - compiler.patch_jump_with_target(env_labels.0, env_info.num_bindings); - compiler.patch_jump_with_target(env_labels.1, env_info.index); + if let Some(env_label) = env_label { + compiler.patch_jump_with_target(env_label, env_index); compiler.pop_compile_environment(); } else { - compiler.num_bindings = env_info.num_bindings; - compiler.is_class_constructor = true; + compiler.code_block_flags |= CodeBlockFlags::IS_CLASS_CONSTRUCTOR; } } else { if class.super_ref().is_some() { compiler.emit_opcode(Opcode::SuperCallDerived); } - let env_info = compiler.pop_compile_environment(); - compiler.num_bindings = env_info.num_bindings; - compiler.is_class_constructor = true; + compiler.pop_compile_environment(); + compiler.code_block_flags |= CodeBlockFlags::IS_CLASS_CONSTRUCTOR; } if class.name().is_some() && class.has_binding_identifier() { @@ -81,11 +78,11 @@ impl ByteCompiler<'_, '_> { self.emit(Opcode::GetFunction, &[index]); self.emit_u8(0); - let class_env: Option<(super::Label, super::Label)> = match class.name() { + let class_env: Option = match class.name() { Some(name) if class.has_binding_identifier() => { self.push_compile_environment(false); self.create_immutable_binding(name, true); - Some(self.emit_opcode_with_two_operands(Opcode::PushDeclarativeEnvironment)) + Some(self.emit_opcode_with_operand(Opcode::PushDeclarativeEnvironment)) } _ => None, }; @@ -266,9 +263,8 @@ impl ByteCompiler<'_, '_> { } else { field_compiler.emit_opcode(Opcode::PushUndefined); } - let env_info = field_compiler.pop_compile_environment(); field_compiler.pop_compile_environment(); - field_compiler.num_bindings = env_info.num_bindings; + field_compiler.pop_compile_environment(); field_compiler.emit_opcode(Opcode::Return); let mut code = field_compiler.finish(); @@ -298,9 +294,8 @@ impl ByteCompiler<'_, '_> { } else { field_compiler.emit_opcode(Opcode::PushUndefined); } - let env_info = field_compiler.pop_compile_environment(); field_compiler.pop_compile_environment(); - field_compiler.num_bindings = env_info.num_bindings; + field_compiler.pop_compile_environment(); field_compiler.emit_opcode(Opcode::Return); let mut code = field_compiler.finish(); @@ -340,9 +335,8 @@ impl ByteCompiler<'_, '_> { } else { field_compiler.emit_opcode(Opcode::PushUndefined); } - let env_info = field_compiler.pop_compile_environment(); field_compiler.pop_compile_environment(); - field_compiler.num_bindings = env_info.num_bindings; + field_compiler.pop_compile_environment(); field_compiler.emit_opcode(Opcode::Return); let mut code = field_compiler.finish(); @@ -392,9 +386,8 @@ impl ByteCompiler<'_, '_> { ); compiler.compile_statement_list(body.statements(), false, false); - let env_info = compiler.pop_compile_environment(); compiler.pop_compile_environment(); - compiler.num_bindings = env_info.num_bindings; + compiler.pop_compile_environment(); let code = Gc::new(compiler.finish()); let index = self.functions.len() as u32; @@ -547,9 +540,8 @@ impl ByteCompiler<'_, '_> { self.emit_opcode(Opcode::Pop); if let Some(class_env) = class_env { - let env_info = self.pop_compile_environment(); - self.patch_jump_with_target(class_env.0, env_info.num_bindings); - self.patch_jump_with_target(class_env.1, env_info.index); + let env_index = self.pop_compile_environment(); + self.patch_jump_with_target(class_env, env_index); self.emit_opcode(Opcode::PopEnvironment); } diff --git a/boa_engine/src/bytecompiler/declarations.rs b/boa_engine/src/bytecompiler/declarations.rs index 6c9ec81fee..626b079868 100644 --- a/boa_engine/src/bytecompiler/declarations.rs +++ b/boa_engine/src/bytecompiler/declarations.rs @@ -260,7 +260,7 @@ impl ByteCompiler<'_, '_> { .name(name.sym()) .generator(generator) .r#async(r#async) - .strict(self.strict) + .strict(self.strict()) .binding_identifier(Some(name.sym())) .compile( parameters, @@ -672,7 +672,7 @@ impl ByteCompiler<'_, '_> { .name(name.sym()) .generator(generator) .r#async(r#async) - .strict(self.strict) + .strict(self.strict()) .binding_identifier(Some(name.sym())) .compile( parameters, @@ -777,8 +777,8 @@ impl ByteCompiler<'_, '_> { arrow: bool, strict: bool, generator: bool, - ) -> (Option<(Label, Label)>, bool) { - let mut env_labels = None; + ) -> (Option