⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 259536 in webkit


Ignore:
Timestamp:
Apr 4, 2020, 12:36:31 PM (6 years ago)
Author:
Alexey Shvayka
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/JavaScriptCore:

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:
Location:
trunk
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/JSTests/ChangeLog

    r259535 r259536  
     12020-04-04  Alexey Shvayka  <shvaikalesh@gmail.com>
     2
     3        '\u' should throw an early SyntaxError exception, but instead evaluates to 'u'
     4        https://bugs.webkit.org/show_bug.cgi?id=198790
     5
     6        Reviewed by Yusuke Suzuki.
     7
     8        * mozilla/ecma/Array/15.4.5.1-1.js:
     9        * mozilla/ecma/LexicalConventions/7.7.4.js:
     10        * test262/expectations.yaml: Mark 4 test cases as passing.
     11
    1122020-04-04  Yusuke Suzuki  <ysuzuki@apple.com>
    213
  • trunk/JSTests/mozilla/ecma/Array/15.4.5.1-1.js

    r108841 r259536  
    105105
    106106    for ( var i = 0X0020, TEST_STRING = "var A = new Array( " ; i < 0x00ff; i++ ) {
    107         if ( i === 0x58 || i === 0x78 ) // x or X - skip testing invalid hex escapes.
     107        if ( i === 0x58 || i === 0x78 || i === 0x75 ) // skip testing invalid hex (x & X) and Unicode (u) escapes.
    108108            continue;
    109109        TEST_STRING += "\'\\"+ String.fromCharCode( i ) +"\'";
     
    115115    }
    116116
    117     var LENGTH = 0x00ff - 0x0020 - 2; // x & X
     117    var LENGTH = 0x00ff - 0x0020 - 3; // x & X & u
    118118
    119119    array[item++] = new TestCase(   SECTION,
  • trunk/JSTests/mozilla/ecma/LexicalConventions/7.7.4.js

    r108841 r259536  
    191191    array[item++] = new TestCase( SECTION, "\\q",    "q",        "\q" );
    192192    array[item++] = new TestCase( SECTION, "\\s",    "s",        "\s" );
    193     array[item++] = new TestCase( SECTION, "\\u",    "u",        "\u" );
     193// Invalid Unicode escapes are syntax error; these are covered in the test262 suite.
     194//    array[item++] = new TestCase( SECTION, "\\u",    "u",        "\u" );
    194195
    195196    array[item++] = new TestCase( SECTION, "\\w",    "w",        "\w" );
  • trunk/JSTests/test262/expectations.yaml

    r259529 r259536  
    32263226  default: 'Test262Error: Expected SameValue(«�», «null») to be true'
    32273227  strict mode: 'Test262Error: Expected SameValue(«�», «null») to be true'
    3228 test/language/literals/string/unicode-escape-no-hex-err-double.js:
    3229   default: 'Test262: This statement should not be evaluated.'
    3230   strict mode: 'Test262: This statement should not be evaluated.'
    3231 test/language/literals/string/unicode-escape-no-hex-err-single.js:
    3232   default: 'Test262: This statement should not be evaluated.'
    3233   strict mode: 'Test262: This statement should not be evaluated.'
    32343228test/language/module-code/eval-rqstd-once.js:
    32353229  module: "SyntaxError: Unexpected identifier 'as'. Expected 'from' before exported module name."
  • trunk/LayoutTests/ChangeLog

    r259532 r259536  
     12020-04-04  Alexey Shvayka  <shvaikalesh@gmail.com>
     2
     3        '\u' should throw an early SyntaxError exception, but instead evaluates to 'u'
     4        https://bugs.webkit.org/show_bug.cgi?id=198790
     5
     6        Reviewed by Yusuke Suzuki.
     7
     8        * js/script-tests/unicode-escape-sequences.js:
     9        * js/unicode-escape-sequences-expected.txt:
     10
    1112020-04-04  Antti Koivisto  <antti@apple.com>
    212
  • trunk/LayoutTests/js/script-tests/unicode-escape-sequences.js

    r258531 r259536  
    4141}
    4242
    43 testStringUnicodeEscapeSequence("", "0075");
    4443testStringUnicodeEscapeSequence("{0}", "0000");
    4544testStringUnicodeEscapeSequence("{41}", "0041");
     
    6362testStringUnicodeEscapeSequence("{00000000000000000000000010ffff}", "DBFF,DFFF");
    6463
     64testInvalidStringUnicodeEscapeSequence("");
    6565testInvalidStringUnicodeEscapeSequence("x");
    6666testInvalidStringUnicodeEscapeSequence("{");
  • trunk/LayoutTests/js/unicode-escape-sequences-expected.txt

    r258531 r259536  
    44
    55
    6 PASS codeUnits("\u") is "0075"
    76PASS codeUnits("\u{0}") is "0000"
    87PASS codeUnits("\u{41}") is "0041"
     
    2524PASS codeUnits("\u{00000000000000000000000010FFFF}") is "DBFF,DFFF"
    2625PASS codeUnits("\u{00000000000000000000000010ffff}") is "DBFF,DFFF"
     26PASS codeUnits("\u") threw exception SyntaxError: \u can only be followed by a Unicode character sequence.
    2727PASS codeUnits("\ux") threw exception SyntaxError: \u can only be followed by a Unicode character sequence.
    2828PASS codeUnits("\u{") threw exception SyntaxError: \u can only be followed by a Unicode character sequence.
  • trunk/Source/JavaScriptCore/ChangeLog

    r259481 r259536  
     12020-04-04  Alexey Shvayka  <shvaikalesh@gmail.com>
     2
     3        '\u' should throw an early SyntaxError exception, but instead evaluates to 'u'
     4        https://bugs.webkit.org/show_bug.cgi?id=198790
     5
     6        Reviewed by Yusuke Suzuki.
     7
     8        This change removes special-case for '\u', invoking parseUnicodeEscape() right away,
     9        aligning string literals with ES6 template literals. parseComplexEscape() method
     10        signature is greatly simplified, JSC is aligned with V8 and SpiderMonkey.
     11
     12        Grammar: https://tc39.es/ecma262/#prod-UnicodeEscapeSequence
     13        (Hex4Digits or '{' is required, otherwise parsing fails)
     14
     15        * parser/Lexer.cpp:
     16        (JSC::Lexer<T>::parseComplexEscape):
     17        (JSC::Lexer<T>::parseStringSlowCase):
     18        (JSC::Lexer<T>::parseTemplateLiteral):
     19        * parser/Lexer.h:
     20
    1212020-04-03  Yusuke Suzuki  <ysuzuki@apple.com>
    222
  • trunk/Source/JavaScriptCore/parser/Lexer.cpp

    r259096 r259536  
    12341234
    12351235template <typename T>
    1236 template <bool shouldBuildStrings, LexerEscapeParseMode escapeParseMode> ALWAYS_INLINE auto Lexer<T>::parseComplexEscape(bool strictMode, T stringQuoteCharacter) -> StringParseResult
     1236template <bool shouldBuildStrings> ALWAYS_INLINE auto Lexer<T>::parseComplexEscape(bool strictMode) -> StringParseResult
    12371237{
    12381238    if (m_current == 'x') {
     
    12631263    if (m_current == 'u') {
    12641264        shift();
    1265 
    1266         if (escapeParseMode == LexerEscapeParseMode::String && m_current == stringQuoteCharacter) {
    1267             if (shouldBuildStrings)
    1268                 record16('u');
    1269             return StringParsedSuccessfully;
    1270         }
    12711265
    12721266        auto character = parseUnicodeEscape();
     
    13621356                shiftLineTerminator();
    13631357            else {
    1364                 StringParseResult result = parseComplexEscape<shouldBuildStrings, LexerEscapeParseMode::String>(strictMode, stringQuoteCharacter);
     1358                StringParseResult result = parseComplexEscape<shouldBuildStrings>(strictMode);
    13651359                if (result != StringParsedSuccessfully)
    13661360                    return result;
     
    14301424            } else {
    14311425                bool strictMode = true;
    1432                 StringParseResult result = parseComplexEscape<true, LexerEscapeParseMode::Template>(strictMode, '`');
     1426                StringParseResult result = parseComplexEscape<true>(strictMode);
    14331427                if (result != StringParsedSuccessfully) {
    14341428                    if (rawStringsBuildMode == RawStringsBuildMode::BuildRawStrings && result == StringCannotBeParsed)
  • trunk/Source/JavaScriptCore/parser/Lexer.h

    r258531 r259536  
    3939};
    4040
    41 enum class LexerEscapeParseMode { Template, String };
    42 
    4341struct ParsedUnicodeEscapeValue;
    4442
     
    177175
    178176
    179     template <bool shouldBuildStrings, LexerEscapeParseMode escapeParseMode> ALWAYS_INLINE StringParseResult parseComplexEscape(bool strictMode, T stringQuoteCharacter);
     177    template <bool shouldBuildStrings> ALWAYS_INLINE StringParseResult parseComplexEscape(bool strictMode);
    180178    ALWAYS_INLINE StringParseResult parseTemplateLiteral(JSTokenData*, RawStringsBuildMode);
    181179   
Note: See TracChangeset for help on using the changeset viewer.