Changeset 276942 in webkit


Ignore:
Timestamp:
May 3, 2021 7:37:17 PM (3 years ago)
Author:
mark.lam@apple.com
Message:

Fix syntax error message for AUTOPLUSPLUS token.
https://bugs.webkit.org/show_bug.cgi?id=225308
rdar://76830934

Reviewed by Saam Barati.

JSTests:

  • stress/prefix-plusplus-syntax-error-should-say-plusplus.js: Added.

Source/JavaScriptCore:

For the record, it's not easy to tell from the code why AUTOPLUSPLUS is needed.
It's needed to distinguish this:

`
statement ++ stuff ++ is a postfix operator applied to statement.
`

from this:

`
statement
++stuff The \n before the ++ makes it a prefix operator applied to stuff`.
`

If we merely tokenize the ++ as a PLUSPLUS token, then it's unclear whether it acts
as a postfix or prefix token in the 2nd case above.

This is why the correct fix is not to get rid of the AUTOPLUSPLUS token, but to
teach the syntax error message to be aware of the AUTOPLUSPLUS token.

  • parser/Parser.cpp:

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

Location:
trunk
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/JSTests/ChangeLog

    r276896 r276942  
     12021-05-03  Mark Lam  <mark.lam@apple.com>
     2
     3        Fix syntax error message for AUTOPLUSPLUS token.
     4        https://bugs.webkit.org/show_bug.cgi?id=225308
     5        rdar://76830934
     6
     7        Reviewed by Saam Barati.
     8
     9        * stress/prefix-plusplus-syntax-error-should-say-plusplus.js: Added.
     10
    1112021-05-03  Dmitry Bezhetskov  <dbezhetskov@igalia.com>
    212
  • trunk/Source/JavaScriptCore/ChangeLog

    r276906 r276942  
     12021-05-03  Mark Lam  <mark.lam@apple.com>
     2
     3        Fix syntax error message for AUTOPLUSPLUS token.
     4        https://bugs.webkit.org/show_bug.cgi?id=225308
     5        rdar://76830934
     6
     7        Reviewed by Saam Barati.
     8
     9        For the record, it's not easy to tell from the code why AUTOPLUSPLUS is needed.
     10        It's needed to distinguish this:
     11            ```
     12            statement ++ stuff  // ++ is a postfix operator applied to `statement`.
     13            ```
     14        from this:
     15            ```
     16            statement
     17            ++stuff    // The `\n` before the ++ makes it a prefix operator applied to `stuff``.
     18            ```
     19
     20        If we merely tokenize the ++ as a PLUSPLUS token, then it's unclear whether it acts
     21        as a postfix or prefix token in the 2nd case above.
     22
     23        This is why the correct fix is not to get rid of the AUTOPLUSPLUS token, but to
     24        teach the syntax error message to be aware of the AUTOPLUSPLUS token.
     25
     26        * parser/Parser.cpp:
     27        (JSC::Parser<LexerType>::parseUnaryExpression):
     28
    1292021-05-03  Chris Dumez  <cdumez@apple.com>
    230
  • trunk/Source/JavaScriptCore/parser/Parser.cpp

    r275542 r276942  
    22 *  Copyright (C) 1999-2001 Harri Porten (porten@kde.org)
    33 *  Copyright (C) 2001 Peter Kelly (pmk@post.com)
    4  *  Copyright (C) 2003-2019 Apple Inc. All rights reserved.
     4 *  Copyright (C) 2003-2021 Apple Inc. All rights reserved.
    55 *
    66 *  This library is free software; you can redistribute it and/or
     
    53935393    if (isUpdateOp(static_cast<JSTokenType>(lastOperator))) {
    53945394        semanticFailIfTrue(context.isMetaProperty(expr), metaPropertyName(context, expr), " can't come after a prefix operator");
    5395         semanticFailIfFalse(isSimpleAssignmentTarget(context, expr), "Prefix ", lastOperator == PLUSPLUS ? "++" : "--", " operator applied to value that is not a reference");
     5395        semanticFailIfFalse(isSimpleAssignmentTarget(context, expr), "Prefix ", lastOperator == PLUSPLUS || lastOperator == AUTOPLUSPLUS ? "++" : "--", " operator applied to value that is not a reference");
    53965396    }
    53975397    bool isEvalOrArguments = false;
Note: See TracChangeset for help on using the changeset viewer.