Skip to content

Commit

Permalink
Removed unnecessary Boxs in global environment
Browse files Browse the repository at this point in the history
  • Loading branch information
HalidOdat committed Jun 19, 2020
1 parent 2ef288a commit 15f6b21
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 21 deletions.
6 changes: 3 additions & 3 deletions boa/src/builtins/object/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -476,10 +476,10 @@ pub fn has_own_property(this: &Value, args: &[Value], ctx: &mut Interpreter) ->
}

pub fn property_is_enumerable(this: &Value, args: &[Value], ctx: &mut Interpreter) -> ResultValue {
let key = if args.is_empty() {
return Ok(Value::from(false));
let key = if let Some(key) = args.get(0) {
key
} else {
args.get(0).expect("Cannot get key")
return Ok(Value::from(false));
};

let property_key = ctx.to_property_key(key)?;
Expand Down
4 changes: 2 additions & 2 deletions boa/src/environment/global_environment_record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ use rustc_hash::FxHashSet;

#[derive(Debug, Trace, Finalize, Clone)]
pub struct GlobalEnvironmentRecord {
pub object_record: Box<ObjectEnvironmentRecord>,
pub object_record: ObjectEnvironmentRecord,
pub global_this_binding: Value,
pub declarative_record: Box<DeclarativeEnvironmentRecord>,
pub declarative_record: DeclarativeEnvironmentRecord,
pub var_names: FxHashSet<String>,
}

Expand Down
10 changes: 5 additions & 5 deletions boa/src/environment/lexical_environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ pub fn new_object_environment(object: Value, environment: Option<Environment>) -
}

pub fn new_global_environment(global: Value, this_value: Value) -> Environment {
let obj_rec = Box::new(ObjectEnvironmentRecord {
let obj_rec = ObjectEnvironmentRecord {
bindings: global,
outer_env: None,
/// Object Environment Records created for with statements (13.11)
Expand All @@ -269,12 +269,12 @@ pub fn new_global_environment(global: Value, this_value: Value) -> Environment {
/// with each object Environment Record. By default, the value of withEnvironment is false
/// for any object Environment Record.
with_environment: false,
});
};

let dcl_rec = Box::new(DeclarativeEnvironmentRecord {
let dcl_rec = DeclarativeEnvironmentRecord {
env_rec: FxHashMap::default(),
outer_env: None,
});
};

Gc::new(GcCell::new(Box::new(GlobalEnvironmentRecord {
object_record: obj_rec,
Expand Down Expand Up @@ -311,7 +311,7 @@ mod tests {
{
const bar = "bar";
}
try{
bar;
} catch (err) {
Expand Down
19 changes: 8 additions & 11 deletions boa/src/realm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use rustc_hash::{FxHashMap, FxHashSet};
#[derive(Debug)]
pub struct Realm {
pub global_obj: Value,
pub global_env: Gc<GcCell<Box<GlobalEnvironmentRecord>>>,
pub global_env: Gc<GcCell<GlobalEnvironmentRecord>>,
pub environment: LexicalEnvironment,
}

Expand Down Expand Up @@ -72,11 +72,8 @@ impl Realm {
}

// Similar to new_global_environment in lexical_environment, except we need to return a GlobalEnvirionment
fn new_global_environment(
global: Value,
this_value: Value,
) -> Gc<GcCell<Box<GlobalEnvironmentRecord>>> {
let obj_rec = Box::new(ObjectEnvironmentRecord {
fn new_global_environment(global: Value, this_value: Value) -> Gc<GcCell<GlobalEnvironmentRecord>> {
let obj_rec = ObjectEnvironmentRecord {
bindings: global,
outer_env: None,
/// Object Environment Records created for with statements (13.11)
Expand All @@ -85,17 +82,17 @@ fn new_global_environment(
/// with each object Environment Record. By default, the value of withEnvironment is false
/// for any object Environment Record.
with_environment: false,
});
};

let dcl_rec = Box::new(DeclarativeEnvironmentRecord {
let dcl_rec = DeclarativeEnvironmentRecord {
env_rec: FxHashMap::default(),
outer_env: None,
});
};

Gc::new(GcCell::new(Box::new(GlobalEnvironmentRecord {
Gc::new(GcCell::new(GlobalEnvironmentRecord {
object_record: obj_rec,
global_this_binding: this_value,
declarative_record: dcl_rec,
var_names: FxHashSet::default(),
})))
}))
}

0 comments on commit 15f6b21

Please sign in to comment.