Disallow variable name "async" in for-of loops
Categories
(Core :: JavaScript Engine, enhancement, P1)
Tracking
()
Tracking | Status | |
---|---|---|
firefox86 | --- | fixed |
People
(Reporter: anba, Assigned: anba)
Details
Attachments
(3 files)
Implement the changes from https://github.com/tc39/ecma262/pull/2256.
Assignee | ||
Comment 1•3 years ago
|
||
IteratorKind
is only used within frontend code, so by moving it from
"vm/Iteration.h" into its own header, we can avoid including "vm/Iteration.h"
in some header files. And it will also avoid including "vm/Iteration.h" in
"frontend/Parser.h" in part 2.
Assignee | ||
Comment 2•3 years ago
|
||
for-of
loops mustn't start with the token sequence async of
, because that
leads to a shift-reduce conflict when parsing for (async of => {};;)
or
for (async of [])
. This restriction doesn't apply to for-await-of
loops,
because async
in for await (async of ...)
is always parsed as an identifier.
Parsing for (async of ...)
already results in a SyntaxError, but that happens
because assignExpr()
always tries to parse the sequence async [no LineTerminator] of
as the start of an async arrow function. That means forHeadStart()
still needs
to handle the case when async
and of
are separated by a line terminator.
Part 3 will update the parser to allow for await (async of ...)
.
Spec change: https://github.com/tc39/ecma262/pull/2256
Depends on D100994
Assignee | ||
Comment 3•3 years ago
|
||
for await (async of ...)
is valid syntax, but assignExpr()
currently always
tries to parse async [no LineTerminator] of
as the start of an async arrow
function.
There are two possible ways to fix this issue:
- Change
forHeadStart()
to calloptionalExpr()
instead ofexpr()
for
for-await-of
loops. This matches the grammar a bit better which uses
IterationStatement : for await ( LeftHandSideExpression of AssignmentExpression ) Statement
. - Or alternatively change
assignExpr()
to usepeekToken()
instead of
peekTokenSameLine()
and then move theno LineTerminator
restriction for
arrow functions intofunctionFormalParametersAndBody()
.
The former approach requires fewer changes, whereas the latter approach allows
to give a better error message when the =>
of an arrow function is misplaced
into the next line.
Depends on D100995
Updated•3 years ago
|
Pushed by ncsoregi@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/bb458ddf25a7 Part 1: Add frontend/IteratorKind.h. r=yulia https://hg.mozilla.org/integration/autoland/rev/c26000950693 Part 2: Disallow identifiers named "async" in for-of loops. r=yulia https://hg.mozilla.org/integration/autoland/rev/b5c5e4da3f50 Part 3: Allow 'async' as an identifier in for-await-of loops. r=yulia
Comment 5•3 years ago
|
||
bugherder |
https://hg.mozilla.org/mozilla-central/rev/bb458ddf25a7
https://hg.mozilla.org/mozilla-central/rev/c26000950693
https://hg.mozilla.org/mozilla-central/rev/b5c5e4da3f50
Description
•