You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Now that environment traversal has been refactored, we no longer need to hold environments in a Vec. Initially we used this to traverse through and get bindings.
function f1() {
return a
}
function f2() {
let a = 1
return f1()
}
f2()
f1() getting called in f2() will have a new environment with the global scope as its parent - it would not have access to a declared inside of f1, for example. The environment stack of f1 would be: Global -> f1. This means that we can't assume that a new environment will have the previous environment as its parent.
The issue in #989 was that resolving bindings was not being done correctly: it was done by traversing through the stack instead of traversing through parent environments. This created a situation where the environment stack for f1 would look like this: Global -> f2 -> f1, creating the problem of variables in f2 being visible in f1.
If we get rid of the stack and use parent environments to return to the previous environment, there will be a different problem: we won't be able to come back to f2's environment, since the parent stack of f1 would be Global.
I think it's still possible to get rid of the environment stack by manually managing environments in parts of the code that currently push and pop environments (implicitly using function calls in Rust as the stack, I suppose), but we can't replace it with traversing parent environments.
Now that environment traversal has been refactored, we no longer need to hold environments in a
Vec
. Initially we used this to traverse through and get bindings.This means we will only ever care about the
last
environment in the Vec. See examples here:https://github.com/boa-dev/boa/blob/master/boa/src/environment/lexical_environment.rs#L154-L168
We only ever get the
back
environment.Task
Instead of using a
Vec<Environment>
just use a singleEnvironment
placeholder to hold the current env.get_current_environment_ref
andget_current_environment
usingself.env
instead of the vector.push
andpop
should be renamed toget
andset
and overwrite the current env or return itThe text was updated successfully, but these errors were encountered: