Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify environment binding behaviour of function #1010

Merged
merged 3 commits into from
Jan 8, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 17 additions & 11 deletions boa/src/syntax/ast/node/declaration/function_decl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,17 +94,23 @@ impl Executable for FunctionDecl {

// Set the name and assign it in the current environment
val.set_field("name", self.name());
context
.realm_mut()
.environment
.create_mutable_binding(self.name().to_owned(), false, VariableScope::Function)
.map_err(|e| e.to_error(context))?;

context
.realm_mut()
.environment
.initialize_binding(self.name(), val)
.map_err(|e| e.to_error(context))?;

let environment = &mut context.realm_mut().environment;
if environment.has_binding(self.name()) {
environment
.set_mutable_binding(self.name(), val, true)
.map_err(|e| e.to_error(context))?;
} else {
environment
.create_mutable_binding(self.name().to_owned(), false, VariableScope::Function)
.map_err(|e| e.to_error(context))?;

context
.realm_mut()
.environment
.initialize_binding(self.name(), val)
.map_err(|e| e.to_error(context))?;
}

Ok(Value::undefined())
}
Expand Down