Browse Source

Allow to re-assign value to an existing binding. (#92)

pull/97/head
Olle Sandberg 5 years ago committed by Jason Williams
parent
commit
6d81538969
  1. 8
      src/lib/exec.rs

8
src/lib/exec.rs

@ -316,9 +316,15 @@ impl Executor for Interpreter {
let val = self.run(val_e)?; let val = self.run(val_e)?;
match ref_e.def { match ref_e.def {
ExprDef::Local(ref name) => { ExprDef::Local(ref name) => {
self.environment.create_mutable_binding(name.clone(), false); if *self.environment.get_binding_value(&name) != ValueData::Undefined {
// Binding already exists
self.environment
.set_mutable_binding(&name, val.clone(), true);
} else {
self.environment.create_mutable_binding(name.clone(), true);
self.environment.initialize_binding(name, val.clone()); self.environment.initialize_binding(name, val.clone());
} }
}
ExprDef::GetConstField(ref obj, ref field) => { ExprDef::GetConstField(ref obj, ref field) => {
let val_obj = self.run(obj)?; let val_obj = self.run(obj)?;
val_obj.borrow().set_field(field.clone(), val.clone()); val_obj.borrow().set_field(field.clone(), val.clone());

Loading…
Cancel
Save