Open Bug 1193490 Opened 6 years ago Updated 6 years ago
jorendorff brings up the good point that we shouldn't have so many different scope objects. This is true especially going forward, because most scopes will have overlapping functionality. Function scope: [x] vars (scoped to whole function) [x] lets/consts (scoped to top block) [x] extensible (vars via direct eval) Block scope: [ ] vars [x] lets/consts [ ] extensible Module scope: [x] vars (scoped to whole module) [x] lets/consts (scoped to top block) [ ] extensible Global lexical: [ ] vars [x] lets/consts [x] extensible (lets via new script tags) So instead of having BlockObject and CallObject and ModuleScopeObject and all that jazz, we should try to unify into a single LexicalEnvironment representation that can handle all of the above behaviors. Namely, I envision: StaticLexicalEnvironment 1. Has a Bindings-like struct that has all initially present, permanent bindings, aliased and unaliased, distinguished between var, let, const. 2. Holds the Shape of the dynamic scope, generated from aliased bindings only 3. If no bindings are aliased, the shape in (2) is null and this has no dynamic counterpart. 4. Initially present aliased bindings (i.e., those in the shape) are accessible via ScopeCoord. extensible bindings accessible via name only LexicalEnvironment 1. Created by StaticLexicalEnvironment with the shape it holds in (2) above. 2. All aliased lexicals are initialized to the magic TDZ throw-on-touch sentinel. 3. May have addenda for specific scope kinds (e.g., callee, home object, lexical this, etc) Currently, function scopes have a Bindings and a compact CallObject shape. Block scope objects do not have Bindings and only uses a Shape. The static and dynamic block scopes have the same shape, meaning the dynamic scope shape is not compacted to contain only aliased bindings. Further, block scope objects currently cannot distinguish between vars and lets, which module scopes need to do. I don't have time to work on this right now, but I would be happy to mentor if somebody else has time.
You need to log in before you can comment on or make changes to this bug.