Title: [276942] trunk
Revision
276942
Author
mark....@apple.com
Date
2021-05-03 19:37:17 -0700 (Mon, 03 May 2021)

Log 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/_javascript_Core:

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):

Modified Paths

Added Paths

Diff

Modified: trunk/JSTests/ChangeLog (276941 => 276942)


--- trunk/JSTests/ChangeLog	2021-05-04 02:03:04 UTC (rev 276941)
+++ trunk/JSTests/ChangeLog	2021-05-04 02:37:17 UTC (rev 276942)
@@ -1,3 +1,13 @@
+2021-05-03  Mark Lam  <mark....@apple.com>
+
+        Fix syntax error message for AUTOPLUSPLUS token.
+        https://bugs.webkit.org/show_bug.cgi?id=225308
+        rdar://76830934
+
+        Reviewed by Saam Barati.
+
+        * stress/prefix-plusplus-syntax-error-should-say-plusplus.js: Added.
+
 2021-05-03  Dmitry Bezhetskov  <dbezhets...@igalia.com>
 
         [WASM-Function-References] Add call_ref instruction

Added: trunk/JSTests/stress/prefix-plusplus-syntax-error-should-say-plusplus.js (0 => 276942)


--- trunk/JSTests/stress/prefix-plusplus-syntax-error-should-say-plusplus.js	                        (rev 0)
+++ trunk/JSTests/stress/prefix-plusplus-syntax-error-should-say-plusplus.js	2021-05-04 02:37:17 UTC (rev 276942)
@@ -0,0 +1,13 @@
+//@ runDefault
+
+str = "\n++x?.y;";
+
+var exception;
+try {
+    eval(str);
+} catch (e) {
+    exception = e;
+}
+
+if (exception != "SyntaxError: Prefix ++ operator applied to value that is not a reference.")
+    throw "FAILED";

Modified: trunk/Source/_javascript_Core/ChangeLog (276941 => 276942)


--- trunk/Source/_javascript_Core/ChangeLog	2021-05-04 02:03:04 UTC (rev 276941)
+++ trunk/Source/_javascript_Core/ChangeLog	2021-05-04 02:37:17 UTC (rev 276942)
@@ -1,3 +1,31 @@
+2021-05-03  Mark Lam  <mark....@apple.com>
+
+        Fix syntax error message for AUTOPLUSPLUS token.
+        https://bugs.webkit.org/show_bug.cgi?id=225308
+        rdar://76830934
+
+        Reviewed by Saam Barati.
+
+        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):
+
 2021-05-03  Chris Dumez  <cdu...@apple.com>
 
         Restore pre-r276879 behavior for FileSystem::deleteFile() and FileSystem::deleteEmptyDirectory()

Modified: trunk/Source/_javascript_Core/parser/Parser.cpp (276941 => 276942)


--- trunk/Source/_javascript_Core/parser/Parser.cpp	2021-05-04 02:03:04 UTC (rev 276941)
+++ trunk/Source/_javascript_Core/parser/Parser.cpp	2021-05-04 02:37:17 UTC (rev 276942)
@@ -1,7 +1,7 @@
 /*
  *  Copyright (C) 1999-2001 Harri Porten (por...@kde.org)
  *  Copyright (C) 2001 Peter Kelly (p...@post.com)
- *  Copyright (C) 2003-2019 Apple Inc. All rights reserved.
+ *  Copyright (C) 2003-2021 Apple Inc. All rights reserved.
  *
  *  This library is free software; you can redistribute it and/or
  *  modify it under the terms of the GNU Library General Public
@@ -5392,7 +5392,7 @@
         ASSERT(oldTokenStackDepth + tokenStackDepth == context.unaryTokenStackDepth());
     if (isUpdateOp(static_cast<JSTokenType>(lastOperator))) {
         semanticFailIfTrue(context.isMetaProperty(expr), metaPropertyName(context, expr), " can't come after a prefix operator");
-        semanticFailIfFalse(isSimpleAssignmentTarget(context, expr), "Prefix ", lastOperator == PLUSPLUS ? "++" : "--", " operator applied to value that is not a reference");
+        semanticFailIfFalse(isSimpleAssignmentTarget(context, expr), "Prefix ", lastOperator == PLUSPLUS || lastOperator == AUTOPLUSPLUS ? "++" : "--", " operator applied to value that is not a reference");
     }
     bool isEvalOrArguments = false;
     if (strictMode()) {
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to