diff --git a/core/engine/src/builtins/eval/mod.rs b/core/engine/src/builtins/eval/mod.rs index 1555473f6f4..7c592d6cfb6 100644 --- a/core/engine/src/builtins/eval/mod.rs +++ b/core/engine/src/builtins/eval/mod.rs @@ -229,7 +229,7 @@ impl Eval { } }); - let var_environment = context.vm.environments.outer_function_environment(); + let var_environment = context.vm.environments.outer_function_environment().clone(); let mut var_env = var_environment.compile_env(); let lex_env = context.vm.environments.current_compile_environment(); diff --git a/core/engine/src/builtins/function/arguments.rs b/core/engine/src/builtins/function/arguments.rs index c21b544a3c4..e8630582235 100644 --- a/core/engine/src/builtins/function/arguments.rs +++ b/core/engine/src/builtins/function/arguments.rs @@ -207,7 +207,7 @@ impl MappedArguments { binding_indices: &[Option], arguments_list: &[JsValue], env: &Gc, - context: &mut Context, + context: &Context, ) -> JsObject { // 1. Assert: formals does not contain a rest parameter, any binding patterns, or any initializers. // It may contain duplicate identifiers. diff --git a/core/engine/src/environments/runtime/mod.rs b/core/engine/src/environments/runtime/mod.rs index b72512a5892..ed67f32f7a6 100644 --- a/core/engine/src/environments/runtime/mod.rs +++ b/core/engine/src/environments/runtime/mod.rs @@ -77,11 +77,11 @@ impl EnvironmentStack { } /// Gets the current global environment. - pub(crate) fn global(&self) -> Gc { - let env = self.stack[0].clone(); + pub(crate) fn global(&self) -> &Gc { + let env = &self.stack[0]; match env { - Environment::Declarative(ref env) => env.clone(), + Environment::Declarative(ref env) => env, Environment::Object(_) => { unreachable!("first environment should be the global environment") } @@ -89,7 +89,7 @@ impl EnvironmentStack { } /// Gets the next outer function environment. - pub(crate) fn outer_function_environment(&self) -> Gc { + pub(crate) fn outer_function_environment(&self) -> &Gc { for env in self .stack .iter() @@ -97,7 +97,7 @@ impl EnvironmentStack { .rev() { if let DeclarativeEnvironmentKind::Function(_) = &env.kind() { - return env.clone(); + return env; } } self.global() @@ -288,11 +288,10 @@ impl EnvironmentStack { /// /// Panics if no environment exists on the stack. #[track_caller] - pub(crate) fn current(&self) -> Environment { + pub(crate) fn current_ref(&self) -> &Environment { self.stack .last() .expect("global environment must always exist") - .clone() } /// Get the compile environment for the current runtime environment. @@ -502,7 +501,7 @@ impl Context { /// are completely removed of runtime checks because the specification guarantees that runtime /// semantics cannot add or remove lexical bindings. pub(crate) fn find_runtime_binding(&mut self, locator: &mut BindingLocator) -> JsResult<()> { - let current = self.vm.environments.current(); + let current = self.vm.environments.current_ref(); if let Some(env) = current.as_declarative() { if !env.with() && !env.poisoned() { return Ok(()); @@ -553,7 +552,7 @@ impl Context { &mut self, locator: &BindingLocator, ) -> JsResult> { - let current = self.vm.environments.current(); + let current = self.vm.environments.current_ref(); if let Some(env) = current.as_declarative() { if !env.with() { return Ok(None); diff --git a/core/engine/src/module/source.rs b/core/engine/src/module/source.rs index f136b3c47c7..81c204ec071 100644 --- a/core/engine/src/module/source.rs +++ b/core/engine/src/module/source.rs @@ -1665,7 +1665,7 @@ impl SourceTextModule { BindingName::Name(name) => context .vm .environments - .current() + .current_ref() .declarative_expect() .kind() .as_module() @@ -1704,7 +1704,7 @@ impl SourceTextModule { let env = frame .environments - .current() + .current_ref() .as_declarative() .cloned() .expect("frame must have a declarative environment"); diff --git a/core/engine/src/module/synthetic.rs b/core/engine/src/module/synthetic.rs index 81446866bf8..330b57995c5 100644 --- a/core/engine/src/module/synthetic.rs +++ b/core/engine/src/module/synthetic.rs @@ -315,7 +315,7 @@ impl SyntheticModule { } let env = envs - .current() + .current_ref() .as_declarative() .cloned() .expect("should have the module environment"); diff --git a/core/engine/src/vm/opcode/arguments.rs b/core/engine/src/vm/opcode/arguments.rs index 92a86560528..8149c84e1d5 100644 --- a/core/engine/src/vm/opcode/arguments.rs +++ b/core/engine/src/vm/opcode/arguments.rs @@ -28,7 +28,7 @@ impl Operation for CreateMappedArgumentsObject { let code = context.vm.frame().code_block().clone(); let args = context.vm.frame().arguments(&context.vm).to_vec(); - let env = context.vm.environments.current(); + let env = context.vm.environments.current_ref(); let arguments = MappedArguments::new( &function_object, &code.mapped_arguments_binding_indices,