Skip to content

Commit

Permalink
Expose unboxed function environment record
Browse files Browse the repository at this point in the history
  • Loading branch information
sanxiyn committed Oct 23, 2019
1 parent 46c9af0 commit 6dff219
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
8 changes: 4 additions & 4 deletions src/lib/environment/lexical_environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,22 +224,22 @@ pub fn new_declarative_environment(env: Option<Environment>) -> 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>,
) -> 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
home_object: Gc::new(ValueData::Undefined),
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>) -> Environment {
Expand Down
12 changes: 7 additions & 5 deletions src/lib/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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");
Expand Down

0 comments on commit 6dff219

Please sign in to comment.