Closed Bug 1276469 Opened 8 years ago Closed 8 years ago

ES6 class declaration unavailable in a closure function defined above it

Categories

(Core :: JavaScript Engine, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
Tracking Status
firefox49 --- affected

People

(Reporter: asqueella, Unassigned)

References

(Blocks 1 open bug)

Details

(Keywords: testcase)

Attachments

(1 file)

This results in a "ReferenceError: FooClass is not defined" in the 2016-05-28 Nightly and 46.0.1, but not in Chrome: var g = (function () { function f() { new FooClass(); } class FooClass { } return f; })(); g(); I expect it to succeed based on this explanation: http://stackoverflow.com/a/35537963/1026 As far as I understand, the "FooClass" binding should be in place (though not having a value yet) when the closure is initialized. After the outer function returns, the FooClass binding will point to the class. Everything works fine - if I move the `function f()` below the class declaration. - or if I use `let` with class expression (`let FooClass = class {}`) This reproduces in a web page (simply wrapped in <script>) and in the JS shell. Curiously, running the code from the Web Console works
Keywords: testcase
Seems correct to me. Needinfo efaust for confirmation.
Flags: needinfo?(efaustbmo)
Yeah, this is a bug. Even if it weren't, the bytecode used for the name access is clearly wrong and would represent a bug: js> dis(g) flags: CONSTRUCTOR loc op ----- -- main: 00000: getgname "FooClass" 00005: undefined 00006: dupat 1 00010: new 0 00013: pop 00014: retrval Source notes: ofs line pc delta desc args ---- ---- ----- ------ -------- ------ 0: 2 0 [ 0] newline 1: 3 0 [ 0] colspan 8 3: 3 14 [ 14] xdelta 4: 3 14 [ 0] newline 5: 4 14 [ 0] colspan 4 Truly shocking that we'd get def-use chain information wrong anywhere, y'know?
Flags: needinfo?(efaustbmo) → needinfo?(jorendorff)
I put this on the bakc burner, because that hoisting will be much easier to ensure is right with the new bindings story that shu is working on. It's clearly a bug, due to the way the Parser::classDefinition is written.
Depends on: 1263355
Flags: needinfo?(jorendorff)
Blocks: 1263355
No longer depends on: 1263355
No longer blocks: 1263355
Depends on: 1263355
Fixed by bug 1263355.
Status: NEW → RESOLVED
Closed: 8 years ago
Resolution: --- → FIXED
Thanks! Indeed this works as intended in the 2016-08-28 nightly.
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: