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)
Core
JavaScript Engine
Tracking
()
RESOLVED
FIXED
Tracking | Status | |
---|---|---|
firefox49 | --- | affected |
People
(Reporter: asqueella, Unassigned)
References
(Blocks 1 open bug)
Details
(Keywords: testcase)
Attachments
(1 file)
(deleted),
text/html
|
Details |
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
Reporter | ||
Comment 1•8 years ago
|
||
Comment 2•8 years ago
|
||
Seems correct to me. Needinfo efaust for confirmation.
Flags: needinfo?(efaustbmo)
Comment 3•8 years ago
|
||
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?
Updated•8 years ago
|
Flags: needinfo?(efaustbmo) → needinfo?(jorendorff)
Comment 4•8 years ago
|
||
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.
Updated•8 years ago
|
Updated•8 years ago
|
Updated•8 years ago
|
Blocks: es6bindings
Comment 5•8 years ago
|
||
Fixed by bug 1263355.
Status: NEW → RESOLVED
Closed: 8 years ago
Resolution: --- → FIXED
Reporter | ||
Comment 6•8 years ago
|
||
Thanks! Indeed this works as intended in the 2016-08-28 nightly.
Updated•8 years ago
|
You need to log in
before you can comment on or make changes to this bug.
Description
•