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

LexicalEnvironment and VariableEnvironment slots [ES5.1] #1056

Closed
dSalieri opened this issue Dec 28, 2017 · 3 comments
Closed

LexicalEnvironment and VariableEnvironment slots [ES5.1] #1056

dSalieri opened this issue Dec 28, 2017 · 3 comments
Labels

Comments

@dSalieri
Copy link

Why do we need LexicalEnvironment and VariableEnvironment if we can use one slot of them. When operations with LexicalEnvironment occur, then its contents are stored in a special variable and then the content of the special variable is given to the LexicalEnvironment slot. Not once in the specification there is no interaction between LexicalEnvironment and VariableEnvironment. VariableEnvironment is used only to create bindings and more and more it is not found anywhere. Explain the meaning of these two slots if there is no interaction between them. Need clarity here!

@littledan
Copy link
Member

It's a bit subtle, but VariableEnvironment is important to implement the way that var declarations are hoisted out of blocks. See the note in 13.3.2 Variable Statement. On the other hand, LexicalEnvironment is used to implement detailed block scoping and variable lookup. I can understand if the notes here are a bit difficult to read; if you have any editorial suggestions for how to organize them to be more apparent, that would be welcome.

@dSalieri
Copy link
Author

Yes, I read this note. But I did not learn anything new for myself. Yes in ES6 appeared let and const that complicated the ECMAScript architecture. By notes of variable declarations it is visible that it is written down in LexicalEnvironment, and that in VariableEnvironment.

  1. In the specification it is said that LexicalEnvironment and VariableEnvironment are initialized by the same value - they contain the same content when entering in the execution context. Further only LexicalEnvironment can change, but not VariableEnvironment. If I correctly understand let and const declarations make LexicalEnvironment different from VariableEnvironment?

  2. Can you give an example with a pseudo-code where you can not do without VariableEnvironment? In another way, I do not know how to comprehend the meaning of these two slots without an example on a pseudo-code or an explanation in which moments you can not do without VariableEnvironment, where it is very important!

@Snjjsvsand
Copy link

It's my personal comprehension:
VariableEnvironment is implicitly used ,cause it has already been a part of environment records chain during declaration instantiation:

  1. In GlobalDeclarationInstantiation,LexicalEnvironment is initialized as the same value as VariableEnvironment .

  2. In FunctionDeclarationInstantiation , LexicalEnvironment is either the same value as VariableEnvironment , or become a new DeclarativeEnvironment which has outerEnv field point to VariableEnvironment.

    Ecma specification states in FunctionDeclarationInstantiation's step 30:
    If strict is false, then let lexEnv be NewDeclarativeEnvironment(varEnv) , else let lexEnv be varEnv.
    The NewDeclarativeEnvironment method receive a E parameter and return a new Environment Record which has ouerEnv field point to E.

When abstract operation ResolveBinding executing, running execution context' s LexicalEnvironment will become start of environment record chain composed by outerEnv field , lots of VariableEnvironment will be used during the identifiers finding process.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants