Title: [259536] trunk
Revision
259536
Author
[email protected]
Date
2020-04-04 12:36:31 -0700 (Sat, 04 Apr 2020)

Log Message

'\u' should throw an early SyntaxError exception, but instead evaluates to 'u'
https://bugs.webkit.org/show_bug.cgi?id=198790

Reviewed by Yusuke Suzuki.

JSTests:

* mozilla/ecma/Array/15.4.5.1-1.js:
* mozilla/ecma/LexicalConventions/7.7.4.js:
* test262/expectations.yaml: Mark 4 test cases as passing.

Source/_javascript_Core:

This change removes special-case for '\u', invoking parseUnicodeEscape() right away,
aligning string literals with ES6 template literals. parseComplexEscape() method
signature is greatly simplified, JSC is aligned with V8 and SpiderMonkey.

Grammar: https://tc39.es/ecma262/#prod-UnicodeEscapeSequence
(Hex4Digits or '{' is required, otherwise parsing fails)

* parser/Lexer.cpp:
(JSC::Lexer<T>::parseComplexEscape):
(JSC::Lexer<T>::parseStringSlowCase):
(JSC::Lexer<T>::parseTemplateLiteral):
* parser/Lexer.h:

LayoutTests:

* js/script-tests/unicode-escape-sequences.js:
* js/unicode-escape-sequences-expected.txt:

Modified Paths

Diff

Modified: trunk/JSTests/ChangeLog (259535 => 259536)


--- trunk/JSTests/ChangeLog	2020-04-04 18:56:14 UTC (rev 259535)
+++ trunk/JSTests/ChangeLog	2020-04-04 19:36:31 UTC (rev 259536)
@@ -1,3 +1,14 @@
+2020-04-04  Alexey Shvayka  <[email protected]>
+
+        '\u' should throw an early SyntaxError exception, but instead evaluates to 'u'
+        https://bugs.webkit.org/show_bug.cgi?id=198790
+
+        Reviewed by Yusuke Suzuki.
+
+        * mozilla/ecma/Array/15.4.5.1-1.js:
+        * mozilla/ecma/LexicalConventions/7.7.4.js:
+        * test262/expectations.yaml: Mark 4 test cases as passing.
+
 2020-04-04  Yusuke Suzuki  <[email protected]>
 
         Unreviewed, skip stress/typed-array-subarray-can-throw-oom-error.js on memory-limited archs, and mark it slow

Modified: trunk/JSTests/mozilla/ecma/Array/15.4.5.1-1.js (259535 => 259536)


--- trunk/JSTests/mozilla/ecma/Array/15.4.5.1-1.js	2020-04-04 18:56:14 UTC (rev 259535)
+++ trunk/JSTests/mozilla/ecma/Array/15.4.5.1-1.js	2020-04-04 19:36:31 UTC (rev 259536)
@@ -104,7 +104,7 @@
 
 
     for ( var i = 0X0020, TEST_STRING = "var A = new Array( " ; i < 0x00ff; i++ ) {
-        if ( i === 0x58 || i === 0x78 ) // x or X - skip testing invalid hex escapes.
+        if ( i === 0x58 || i === 0x78 || i === 0x75 ) // skip testing invalid hex (x & X) and Unicode (u) escapes.
             continue;
         TEST_STRING += "\'\\"+ String.fromCharCode( i ) +"\'";
         if ( i < 0x00FF - 1   ) {
@@ -114,7 +114,7 @@
         }
     }
 
-    var LENGTH = 0x00ff - 0x0020 - 2; // x & X
+    var LENGTH = 0x00ff - 0x0020 - 3; // x & X & u
 
     array[item++] = new TestCase(   SECTION,
                                     TEST_STRING +" A[150] = 'hello'; A[150]",

Modified: trunk/JSTests/mozilla/ecma/LexicalConventions/7.7.4.js (259535 => 259536)


--- trunk/JSTests/mozilla/ecma/LexicalConventions/7.7.4.js	2020-04-04 18:56:14 UTC (rev 259535)
+++ trunk/JSTests/mozilla/ecma/LexicalConventions/7.7.4.js	2020-04-04 19:36:31 UTC (rev 259536)
@@ -190,7 +190,8 @@
     array[item++] = new TestCase( SECTION, "\\p",    "p",        "\p" );
     array[item++] = new TestCase( SECTION, "\\q",    "q",        "\q" );
     array[item++] = new TestCase( SECTION, "\\s",    "s",        "\s" );
-    array[item++] = new TestCase( SECTION, "\\u",    "u",        "\u" );
+// Invalid Unicode escapes are syntax error; these are covered in the test262 suite.
+//    array[item++] = new TestCase( SECTION, "\\u",    "u",        "\u" );
 
     array[item++] = new TestCase( SECTION, "\\w",    "w",        "\w" );
 // Invalid hex escapes are syntax error; these are covered in the sputnik test suite.

Modified: trunk/JSTests/test262/expectations.yaml (259535 => 259536)


--- trunk/JSTests/test262/expectations.yaml	2020-04-04 18:56:14 UTC (rev 259535)
+++ trunk/JSTests/test262/expectations.yaml	2020-04-04 19:36:31 UTC (rev 259536)
@@ -3225,12 +3225,6 @@
 test/language/literals/regexp/u-astral-char-class-invert.js:
   default: 'Test262Error: Expected SameValue(«�», «null») to be true'
   strict mode: 'Test262Error: Expected SameValue(«�», «null») to be true'
-test/language/literals/string/unicode-escape-no-hex-err-double.js:
-  default: 'Test262: This statement should not be evaluated.'
-  strict mode: 'Test262: This statement should not be evaluated.'
-test/language/literals/string/unicode-escape-no-hex-err-single.js:
-  default: 'Test262: This statement should not be evaluated.'
-  strict mode: 'Test262: This statement should not be evaluated.'
 test/language/module-code/eval-rqstd-once.js:
   module: "SyntaxError: Unexpected identifier 'as'. Expected 'from' before exported module name."
 test/language/module-code/eval-rqstd-order.js:

Modified: trunk/LayoutTests/ChangeLog (259535 => 259536)


--- trunk/LayoutTests/ChangeLog	2020-04-04 18:56:14 UTC (rev 259535)
+++ trunk/LayoutTests/ChangeLog	2020-04-04 19:36:31 UTC (rev 259536)
@@ -1,3 +1,13 @@
+2020-04-04  Alexey Shvayka  <[email protected]>
+
+        '\u' should throw an early SyntaxError exception, but instead evaluates to 'u'
+        https://bugs.webkit.org/show_bug.cgi?id=198790
+
+        Reviewed by Yusuke Suzuki.
+
+        * js/script-tests/unicode-escape-sequences.js:
+        * js/unicode-escape-sequences-expected.txt:
+
 2020-04-04  Antti Koivisto  <[email protected]>
 
         Implement the css-color-4 behavior for inheritance of currentColor

Modified: trunk/LayoutTests/js/script-tests/unicode-escape-sequences.js (259535 => 259536)


--- trunk/LayoutTests/js/script-tests/unicode-escape-sequences.js	2020-04-04 18:56:14 UTC (rev 259535)
+++ trunk/LayoutTests/js/script-tests/unicode-escape-sequences.js	2020-04-04 19:36:31 UTC (rev 259536)
@@ -40,7 +40,6 @@
     shouldThrow('codeUnits(function x\\u' + sequence + '(){}.name.substring(1))');
 }
 
-testStringUnicodeEscapeSequence("", "0075");
 testStringUnicodeEscapeSequence("{0}", "0000");
 testStringUnicodeEscapeSequence("{41}", "0041");
 testStringUnicodeEscapeSequence("{D800}", "D800");
@@ -62,6 +61,7 @@
 testStringUnicodeEscapeSequence("{00000000000000000000000010FFFF}", "DBFF,DFFF");
 testStringUnicodeEscapeSequence("{00000000000000000000000010ffff}", "DBFF,DFFF");
 
+testInvalidStringUnicodeEscapeSequence("");
 testInvalidStringUnicodeEscapeSequence("x");
 testInvalidStringUnicodeEscapeSequence("{");
 testInvalidStringUnicodeEscapeSequence("{}");

Modified: trunk/LayoutTests/js/unicode-escape-sequences-expected.txt (259535 => 259536)


--- trunk/LayoutTests/js/unicode-escape-sequences-expected.txt	2020-04-04 18:56:14 UTC (rev 259535)
+++ trunk/LayoutTests/js/unicode-escape-sequences-expected.txt	2020-04-04 19:36:31 UTC (rev 259536)
@@ -3,7 +3,6 @@
 On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
 
 
-PASS codeUnits("\u") is "0075"
 PASS codeUnits("\u{0}") is "0000"
 PASS codeUnits("\u{41}") is "0041"
 PASS codeUnits("\u{D800}") is "D800"
@@ -24,6 +23,7 @@
 PASS codeUnits("\u{10ffff}") is "DBFF,DFFF"
 PASS codeUnits("\u{00000000000000000000000010FFFF}") is "DBFF,DFFF"
 PASS codeUnits("\u{00000000000000000000000010ffff}") is "DBFF,DFFF"
+PASS codeUnits("\u") threw exception SyntaxError: \u can only be followed by a Unicode character sequence.
 PASS codeUnits("\ux") threw exception SyntaxError: \u can only be followed by a Unicode character sequence.
 PASS codeUnits("\u{") threw exception SyntaxError: \u can only be followed by a Unicode character sequence.
 PASS codeUnits("\u{}") threw exception SyntaxError: \u can only be followed by a Unicode character sequence.

Modified: trunk/Source/_javascript_Core/ChangeLog (259535 => 259536)


--- trunk/Source/_javascript_Core/ChangeLog	2020-04-04 18:56:14 UTC (rev 259535)
+++ trunk/Source/_javascript_Core/ChangeLog	2020-04-04 19:36:31 UTC (rev 259536)
@@ -1,3 +1,23 @@
+2020-04-04  Alexey Shvayka  <[email protected]>
+
+        '\u' should throw an early SyntaxError exception, but instead evaluates to 'u'
+        https://bugs.webkit.org/show_bug.cgi?id=198790
+
+        Reviewed by Yusuke Suzuki.
+
+        This change removes special-case for '\u', invoking parseUnicodeEscape() right away,
+        aligning string literals with ES6 template literals. parseComplexEscape() method
+        signature is greatly simplified, JSC is aligned with V8 and SpiderMonkey.
+
+        Grammar: https://tc39.es/ecma262/#prod-UnicodeEscapeSequence
+        (Hex4Digits or '{' is required, otherwise parsing fails)
+
+        * parser/Lexer.cpp:
+        (JSC::Lexer<T>::parseComplexEscape):
+        (JSC::Lexer<T>::parseStringSlowCase):
+        (JSC::Lexer<T>::parseTemplateLiteral):
+        * parser/Lexer.h:
+
 2020-04-03  Yusuke Suzuki  <[email protected]>
 
         [JSC] canonicalizeLocaleList should gracefully throw OOM error if input + error message is too large

Modified: trunk/Source/_javascript_Core/parser/Lexer.cpp (259535 => 259536)


--- trunk/Source/_javascript_Core/parser/Lexer.cpp	2020-04-04 18:56:14 UTC (rev 259535)
+++ trunk/Source/_javascript_Core/parser/Lexer.cpp	2020-04-04 19:36:31 UTC (rev 259536)
@@ -1233,7 +1233,7 @@
 }
 
 template <typename T>
-template <bool shouldBuildStrings, LexerEscapeParseMode escapeParseMode> ALWAYS_INLINE auto Lexer<T>::parseComplexEscape(bool strictMode, T stringQuoteCharacter) -> StringParseResult
+template <bool shouldBuildStrings> ALWAYS_INLINE auto Lexer<T>::parseComplexEscape(bool strictMode) -> StringParseResult
 {
     if (m_current == 'x') {
         shift();
@@ -1263,12 +1263,6 @@
     if (m_current == 'u') {
         shift();
 
-        if (escapeParseMode == LexerEscapeParseMode::String && m_current == stringQuoteCharacter) {
-            if (shouldBuildStrings)
-                record16('u');
-            return StringParsedSuccessfully;
-        }
-
         auto character = parseUnicodeEscape();
         if (character.isValid()) {
             if (shouldBuildStrings)
@@ -1361,7 +1355,7 @@
             } else if (UNLIKELY(isLineTerminator(m_current)))
                 shiftLineTerminator();
             else {
-                StringParseResult result = parseComplexEscape<shouldBuildStrings, LexerEscapeParseMode::String>(strictMode, stringQuoteCharacter);
+                StringParseResult result = parseComplexEscape<shouldBuildStrings>(strictMode);
                 if (result != StringParsedSuccessfully)
                     return result;
             }
@@ -1429,7 +1423,7 @@
                     shiftLineTerminator();
             } else {
                 bool strictMode = true;
-                StringParseResult result = parseComplexEscape<true, LexerEscapeParseMode::Template>(strictMode, '`');
+                StringParseResult result = parseComplexEscape<true>(strictMode);
                 if (result != StringParsedSuccessfully) {
                     if (rawStringsBuildMode == RawStringsBuildMode::BuildRawStrings && result == StringCannotBeParsed)
                         parseCookedFailed = true;

Modified: trunk/Source/_javascript_Core/parser/Lexer.h (259535 => 259536)


--- trunk/Source/_javascript_Core/parser/Lexer.h	2020-04-04 18:56:14 UTC (rev 259535)
+++ trunk/Source/_javascript_Core/parser/Lexer.h	2020-04-04 19:36:31 UTC (rev 259536)
@@ -38,8 +38,6 @@
     DontBuildKeywords = 1 << 2
 };
 
-enum class LexerEscapeParseMode { Template, String };
-
 struct ParsedUnicodeEscapeValue;
 
 bool isLexerKeyword(const Identifier&);
@@ -176,7 +174,7 @@
     template <bool shouldBuildStrings> NEVER_INLINE StringParseResult parseStringSlowCase(JSTokenData*, bool strictMode);
 
 
-    template <bool shouldBuildStrings, LexerEscapeParseMode escapeParseMode> ALWAYS_INLINE StringParseResult parseComplexEscape(bool strictMode, T stringQuoteCharacter);
+    template <bool shouldBuildStrings> ALWAYS_INLINE StringParseResult parseComplexEscape(bool strictMode);
     ALWAYS_INLINE StringParseResult parseTemplateLiteral(JSTokenData*, RawStringsBuildMode);
     
     using NumberParseResult = Variant<double, const Identifier*>;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to