From f084460e5a23b6c373aef2a8ff3737afe6785367 Mon Sep 17 00:00:00 2001 From: Haled Odat <8566042+HalidOdat@users.noreply.github.com> Date: Sun, 29 Oct 2023 22:17:05 +0100 Subject: [PATCH] Move parameter environment creation to opcode --- boa_engine/src/bytecompiler/declarations.rs | 9 +++------ .../src/object/internal_methods/function.rs | 16 ---------------- boa_engine/src/vm/code_block.rs | 12 +----------- 3 files changed, 4 insertions(+), 33 deletions(-) diff --git a/boa_engine/src/bytecompiler/declarations.rs b/boa_engine/src/bytecompiler/declarations.rs index 78551fc6ff0..3d3109b8dbb 100644 --- a/boa_engine/src/bytecompiler/declarations.rs +++ b/boa_engine/src/bytecompiler/declarations.rs @@ -4,10 +4,7 @@ use crate::{ bytecompiler::{ByteCompiler, FunctionCompiler, FunctionSpec, NodeKind}, environments::CompileTimeEnvironment, js_string, - vm::{ - create_function_object_fast, create_generator_function_object, BindingOpcode, - CodeBlockFlags, Opcode, - }, + vm::{create_function_object_fast, create_generator_function_object, BindingOpcode, Opcode}, JsNativeError, JsResult, }; use boa_ast::{ @@ -930,8 +927,8 @@ impl ByteCompiler<'_, '_> { // c. Let env be NewDeclarativeEnvironment(calleeEnv). // d. Assert: The VariableEnvironment of calleeContext is calleeEnv. // e. Set the LexicalEnvironment of calleeContext to env. - let _ = self.push_compile_environment(false); - self.code_block_flags |= CodeBlockFlags::PARAMETERS_ENV_BINDINGS; + let env_index = self.push_compile_environment(false); + self.emit_with_varying_operand(Opcode::PushDeclarativeEnvironment, env_index); }; let env = self.lexical_environment.clone(); diff --git a/boa_engine/src/object/internal_methods/function.rs b/boa_engine/src/object/internal_methods/function.rs index 91a76142c7e..d9139b6c14c 100644 --- a/boa_engine/src/object/internal_methods/function.rs +++ b/boa_engine/src/object/internal_methods/function.rs @@ -113,14 +113,6 @@ pub(crate) fn function_call( FunctionSlots::new(this, function_object.clone(), None), ); - if code.has_parameters_env_bindings() { - last_env += 1; - context - .vm - .environments - .push_lexical(code.constant_compile_time_environment(last_env)); - } - Ok(CallValue::Ready) } @@ -216,14 +208,6 @@ fn function_construct( ), ); - if code.has_parameters_env_bindings() { - last_env += 1; - context - .vm - .environments - .push_lexical(code.constant_compile_time_environment(last_env)); - } - // Insert `this` value context .vm diff --git a/boa_engine/src/vm/code_block.rs b/boa_engine/src/vm/code_block.rs index 38b925b51ff..63cf7021689 100644 --- a/boa_engine/src/vm/code_block.rs +++ b/boa_engine/src/vm/code_block.rs @@ -58,11 +58,8 @@ bitflags! { /// The `[[IsClassConstructor]]` internal slot. const IS_CLASS_CONSTRUCTOR = 0b0000_0100; - /// Does this function have a parameters environment. - const PARAMETERS_ENV_BINDINGS = 0b0000_1000; - /// The `[[ClassFieldInitializerName]]` internal slot. - const IN_CLASS_FIELD_INITIALIZER = 0b0010_0000; + const IN_CLASS_FIELD_INITIALIZER = 0b0000_1000; /// `[[ConstructorKind]]` const IS_DERIVED_CONSTRUCTOR = 0b0100_0000; @@ -222,13 +219,6 @@ impl CodeBlock { .contains(CodeBlockFlags::HAS_BINDING_IDENTIFIER) } - /// Does this function have a parameters environment. - pub(crate) fn has_parameters_env_bindings(&self) -> bool { - self.flags - .get() - .contains(CodeBlockFlags::PARAMETERS_ENV_BINDINGS) - } - /// Does this function have the `[[ClassFieldInitializerName]]` internal slot set to non-empty value. pub(crate) fn in_class_field_initializer(&self) -> bool { self.flags