Closed Bug 1431461 Opened 6 years ago Closed 6 years ago

Function body var scope mistakenly adds non-var bindings that are immediately shadowed

Categories

(Core :: JavaScript Engine, enhancement)

enhancement
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla60
Tracking Status
firefox60 --- fixed

People

(Reporter: shu, Assigned: jorendorff)

References

Details

Attachments

(2 files)

Something like

    function f(x,y=x) {
         let z;
    }

results in the Parser generating a separate body-level var scope due to the crazy semantics of parameter expressions.

In the Parser itself, there is just a single body-level Parser::Scope that holds all the declarations to perform redeclaration checks. When it finishes parsing the function, it'll generate the actual VM Scope data. This is where vars all put together, and lets/consts are all put together into different scopes. For functions with parameter expressions, the function body emits two VM Scopes: a FunctionBodyVar and a Lexical. When emitting the FunctionBodyVar, all bindings (including lets/consts) are mistakenly put into it. This has not manifested in observable errors because they are always immediately shadowed by the same-named bindings in the enclosed Lexical.

See the double copy of ma,mb in https://github.com/devtools-html/debugger.html/issues/5061#issuecomment-358106778
Assignee: nobody → jorendorff
Status: NEW → ASSIGNED
Attachment #8944106 - Flags: review+
https://hg.mozilla.org/integration/mozilla-inbound/rev/383d026eaeb7d27f2f2d2ea90e19d07d0b562f3b
Bug 1431461 - Filter for only var declarations when generating FunctionBodyVar scope data. r=jorendorff.
https://hg.mozilla.org/mozilla-central/rev/383d026eaeb7
Status: ASSIGNED → RESOLVED
Closed: 6 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla60
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: