Changeset 266327 in webkit for trunk/Source/JavaScriptCore


Ignore:
Timestamp:
Aug 29, 2020, 1:44:20 PM (5 years ago)
Author:
[email protected]
Message:

[JSC] let [ sequence cannot appear in ExpressionStatement context
https://bugs.webkit.org/show_bug.cgi?id=215977

Reviewed by Ross Kirsling.

JSTests:

  • stress/let-and-open-bracket.js: Added.

(testSyntax):
(testSyntaxError):

  • test262/expectations.yaml:

Source/JavaScriptCore:

Because of ambiguity between destructuring assignment and member access (let IDENTIFIER), ECMA262 does not allow let [ sequence in ExpressionStatement context[1].
We should throw SyntaxError when we see something like this.

if (false)

let [ok] = [42];

[1]: https://tc39.es/ecma262/#sec-expression-statement

  • parser/Parser.cpp:

(JSC::Parser<LexerType>::parseStatement):

Location:
trunk/Source/JavaScriptCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r266326 r266327  
     12020-08-29  Yusuke Suzuki  <[email protected]>
     2
     3        [JSC] `let [` sequence cannot appear in ExpressionStatement context
     4        https://bugs.webkit.org/show_bug.cgi?id=215977
     5
     6        Reviewed by Ross Kirsling.
     7
     8        Because of ambiguity between destructuring assignment and member access (let IDENTIFIER), ECMA262 does not allow `let [` sequence in ExpressionStatement context[1].
     9        We should throw SyntaxError when we see something like this.
     10
     11            if (false)
     12                let [ok] = [42];
     13
     14        [1]: https://tc39.es/ecma262/#sec-expression-statement
     15
     16        * parser/Parser.cpp:
     17        (JSC::Parser<LexerType>::parseStatement):
     18
    1192020-08-29  Yusuke Suzuki  <[email protected]>
    220
  • trunk/Source/JavaScriptCore/parser/Parser.cpp

    r266326 r266327  
    19711971        return 0;
    19721972    case LET: {
     1973        // https://tc39.es/ecma262/#sec-expression-statement
     1974        // ExpressionStatement's lookahead includes `let [` sequence.
     1975        SavePoint savePoint = createSavePoint(context);
     1976        next();
     1977        failIfTrue(match(OPENBRACKET), "Cannot use lexical declaration in single-statement context");
     1978        restoreSavePoint(context, savePoint);
    19731979        if (!strictMode())
    19741980            goto identcase;
Note: See TracChangeset for help on using the changeset viewer.