Closed Bug 1685482 Opened 3 years ago Closed 3 years ago

Disallow variable name "async" in for-of loops

Categories

(Core :: JavaScript Engine, enhancement, P1)

enhancement

Tracking

()

RESOLVED FIXED
86 Branch
Tracking Status
firefox86 --- fixed

People

(Reporter: anba, Assigned: anba)

Details

Attachments

(3 files)

Implement the changes from https://github.com/tc39/ecma262/pull/2256.

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.

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

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:

  1. Change forHeadStart() to call optionalExpr() instead of expr() for
    for-await-of loops. This matches the grammar a bit better which uses
    IterationStatement : for await ( LeftHandSideExpression of AssignmentExpression ) Statement.
  2. Or alternatively change assignExpr() to use peekToken() instead of
    peekTokenSameLine() and then move the no LineTerminator restriction for
    arrow functions into functionFormalParametersAndBody().

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

Severity: -- → N/A
Priority: -- → P1
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
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: