diff --git a/src/lib/environment/lexical_environment.rs b/src/lib/environment/lexical_environment.rs index 8d0e6ae9206..6183fff4877 100644 --- a/src/lib/environment/lexical_environment.rs +++ b/src/lib/environment/lexical_environment.rs @@ -224,14 +224,14 @@ pub fn new_declarative_environment(env: Option) -> Environment { Gc::new(GcCell::new(boxed_env)) } -pub fn new_function_environment( +pub fn new_function_environment_record( f: Value, new_target: Value, outer: Option, -) -> Environment { +) -> FunctionEnvironmentRecord { debug_assert!(f.is_function()); debug_assert!(new_target.is_object() || new_target.is_undefined()); - Gc::new(GcCell::new(Box::new(FunctionEnvironmentRecord { + FunctionEnvironmentRecord { env_rec: HashMap::new(), function_object: f, this_binding_status: BindingStatus::Uninitialized, // hardcoding to unitialized for now until short functions are properly supported @@ -239,7 +239,7 @@ pub fn new_function_environment( new_target, outer_env: outer, // this will come from Environment set as a private property of F - https://tc39.github.io/ecma262/#sec-ecmascript-function-objects this_value: Gc::new(ValueData::Undefined), // TODO: this_value should start as an Option as its not always there to begin with - }))) + } } pub fn new_object_environment(object: Value, environment: Option) -> Environment { diff --git a/src/lib/exec.rs b/src/lib/exec.rs index cf4210cdefb..c3de9441ae2 100644 --- a/src/lib/exec.rs +++ b/src/lib/exec.rs @@ -5,7 +5,7 @@ use crate::{ value::{from_value, to_value, ResultValue, Value, ValueData}, }, environment::lexical_environment::{ - new_declarative_environment, new_function_environment, VariableScope, + new_declarative_environment, new_function_environment_record, VariableScope, }, realm::Realm, syntax::ast::{ @@ -359,11 +359,12 @@ impl Executor for Interpreter { Function::RegularFunc(ref data) => { // Create new scope let env = &mut self.realm.environment; - env.push(new_function_environment( + let func_rec = new_function_environment_record( construct.clone(), this.clone(), Some(env.get_current_environment_ref().clone()), - )); + ); + env.push(Gc::new(GcCell::new(Box::new(func_rec)))); for i in 0..data.args.len() { let name = data.args.get(i).expect("Could not get data argument"); @@ -508,11 +509,12 @@ impl Interpreter { let env = &mut self.realm.environment; // New target (second argument) is only needed for constructors, just pass undefined let undefined = Gc::new(ValueData::Undefined); - env.push(new_function_environment( + let func_rec = new_function_environment_record( f.clone(), undefined, Some(env.get_current_environment_ref().clone()), - )); + ); + env.push(Gc::new(GcCell::new(Box::new(func_rec)))); for i in 0..data.args.len() { let name = data.args.get(i).expect("Could not get data argument"); let expr: &Value = arguments_list.get(i).expect("Could not get argument");