Allow to re-assign value to an existing binding.
@@ -316,9 +316,15 @@ impl Executor for Interpreter {
let val = self.run(val_e)?;
match ref_e.def {
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());
}
+ }
ExprDef::GetConstField(ref obj, ref field) => {
let val_obj = self.run(obj)?;
val_obj.borrow().set_field(field.clone(), val.clone());
