Skip to content

Commit

Permalink
Handle different declaration types
Browse files Browse the repository at this point in the history
  • Loading branch information
0x7D2B committed Mar 17, 2021
1 parent 25a55c1 commit 4749c3a
Showing 1 changed file with 22 additions and 12 deletions.
34 changes: 22 additions & 12 deletions boa/src/syntax/ast/node/declaration/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,28 @@ impl Executable for DeclarationList {
(_, Some(init)) => init.run(context)?,
(_, None) => Value::undefined(),
};
context
.realm_mut()
.environment
.create_mutable_binding(
decl.name().to_owned(),
false,
match &self.declaration_type {
Var => VariableScope::Function,
_ => VariableScope::Block,
},
)
.map_err(|e| e.to_error(context))?;

let environment = &mut context.realm_mut().environment;

if self.declaration_type == Var && environment.has_binding(decl.name()) {
environment
.set_mutable_binding(decl.name(), val, true)
.map_err(|e| e.to_error(context))?;
return Ok(Value::undefined());
}

match &self.declaration_type {
Const => environment
.create_immutable_binding(decl.name().to_owned(), false, VariableScope::Block)
.map_err(|e| e.to_error(context))?,
Let => environment
.create_mutable_binding(decl.name().to_owned(), false, VariableScope::Block)
.map_err(|e| e.to_error(context))?,
Var => environment
.create_mutable_binding(decl.name().to_owned(), false, VariableScope::Function)
.map_err(|e| e.to_error(context))?,
}

context
.realm_mut()
.environment
Expand Down

0 comments on commit 4749c3a

Please sign in to comment.