Changeset 255505 in webkit


Ignore:
Timestamp:
Jan 31, 2020 9:59:26 AM (4 years ago)
Author:
Alexey Shvayka
Message:

Unmatched ] or } brackets should be syntax errors in Unicode patterns only
https://bugs.webkit.org/show_bug.cgi?id=207023

Reviewed by Darin Adler.

JSTests:

  • test262/expectations.yaml: Mark 2 test cases as passing.

Source/JavaScriptCore:

This change adds SyntaxError for Unicode patterns, aligning JSC with
V8 and SpiderMonkey.

Grammar: https://tc39.es/ecma262/#prod-annexB-Term
(/u flag precludes the use of ExtendedAtom and thus ExtendedPatternCharacter)

  • yarr/YarrErrorCode.cpp:

(JSC::Yarr::errorMessage):
(JSC::Yarr::errorToThrow):

  • yarr/YarrErrorCode.h:
  • yarr/YarrParser.h:

(JSC::Yarr::Parser::parseTokens):

LayoutTests:

  • js/regexp-unicode-expected.txt:
  • js/script-tests/regexp-unicode.js:
Location:
trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/JSTests/ChangeLog

    r255452 r255505  
     12020-01-31  Alexey Shvayka  <shvaikalesh@gmail.com>
     2
     3        Unmatched ] or } brackets should be syntax errors in Unicode patterns only
     4        https://bugs.webkit.org/show_bug.cgi?id=207023
     5
     6        Reviewed by Darin Adler.
     7
     8        * test262/expectations.yaml: Mark 2 test cases as passing.
     9
    1102020-01-30  Alexey Shvayka  <shvaikalesh@gmail.com>
    211
  • trunk/JSTests/test262/expectations.yaml

    r255452 r255505  
    15741574  default: 'Test262Error: cross-realm RegExp.prototype Expected a TypeError to be thrown but no exception was thrown at all'
    15751575  strict mode: 'Test262Error: cross-realm RegExp.prototype Expected a TypeError to be thrown but no exception was thrown at all'
    1576 test/built-ins/RegExp/unicode_restricted_brackets.js:
    1577   default: 'Test262Error: RegExp("]", "u"):  Expected a SyntaxError to be thrown but no exception was thrown at all'
    1578   strict mode: 'Test262Error: RegExp("]", "u"):  Expected a SyntaxError to be thrown but no exception was thrown at all'
    15791576test/built-ins/RegExp/unicode_restricted_identity_escape.js:
    15801577  default: "Test262Error: Invalid IdentityEscape in AtomEscape: '\\"
  • trunk/LayoutTests/ChangeLog

    r255504 r255505  
     12020-01-31  Alexey Shvayka  <shvaikalesh@gmail.com>
     2
     3        Unmatched ] or } brackets should be syntax errors in Unicode patterns only
     4        https://bugs.webkit.org/show_bug.cgi?id=207023
     5
     6        Reviewed by Darin Adler.
     7
     8        * js/regexp-unicode-expected.txt:
     9        * js/script-tests/regexp-unicode.js:
     10
    1112020-01-31  Antoine Quint  <graouts@apple.com>
    212
  • trunk/LayoutTests/js/regexp-unicode-expected.txt

    r255452 r255505  
    168168PASS /{/u threw exception SyntaxError: Invalid regular expression: incomplete {} quantifier for Unicode pattern.
    169169PASS /[a-\d]/u threw exception SyntaxError: Invalid regular expression: invalid range in character class for Unicode pattern.
     170PASS /]/u threw exception SyntaxError: Invalid regular expression: unmatched ] or } bracket for Unicode pattern.
    170171PASS r = new RegExp("\\-", "u") threw exception SyntaxError: Invalid regular expression: invalid escaped character for Unicode pattern.
    171172PASS r = new RegExp("\\a", "u") threw exception SyntaxError: Invalid regular expression: invalid escaped character for Unicode pattern.
  • trunk/LayoutTests/js/script-tests/regexp-unicode.js

    r255452 r255505  
    233233shouldThrow('/{/u', '"SyntaxError: Invalid regular expression: incomplete {} quantifier for Unicode pattern"');
    234234shouldThrow('/[a-\\d]/u', '"SyntaxError: Invalid regular expression: invalid range in character class for Unicode pattern"');
     235shouldThrow('/]/u', '"SyntaxError: Invalid regular expression: unmatched ] or } bracket for Unicode pattern"');
    235236
    236237var invalidEscapeException = "SyntaxError: Invalid regular expression: invalid escaped character for Unicode pattern";
  • trunk/Source/JavaScriptCore/ChangeLog

    r255491 r255505  
     12020-01-31  Alexey Shvayka  <shvaikalesh@gmail.com>
     2
     3        Unmatched ] or } brackets should be syntax errors in Unicode patterns only
     4        https://bugs.webkit.org/show_bug.cgi?id=207023
     5
     6        Reviewed by Darin Adler.
     7
     8        This change adds SyntaxError for Unicode patterns, aligning JSC with
     9        V8 and SpiderMonkey.
     10
     11        Grammar: https://tc39.es/ecma262/#prod-annexB-Term
     12        (/u flag precludes the use of ExtendedAtom and thus ExtendedPatternCharacter)
     13
     14        * yarr/YarrErrorCode.cpp:
     15        (JSC::Yarr::errorMessage):
     16        (JSC::Yarr::errorToThrow):
     17        * yarr/YarrErrorCode.h:
     18        * yarr/YarrParser.h:
     19        (JSC::Yarr::Parser::parseTokens):
     20
    1212020-01-31  Don Olmstead  <don.olmstead@sony.com>
    222
  • trunk/Source/JavaScriptCore/yarr/YarrErrorCode.cpp

    r255452 r255505  
    4343        REGEXP_ERROR_PREFIX "incomplete {} quantifier for Unicode pattern",         // QuantifierIncomplete
    4444        REGEXP_ERROR_PREFIX "missing )",                                            // MissingParentheses
     45        REGEXP_ERROR_PREFIX "unmatched ] or } bracket for Unicode pattern",         // BracketUnmatched
    4546        REGEXP_ERROR_PREFIX "unmatched parentheses",                                // ParenthesesUnmatched
    4647        REGEXP_ERROR_PREFIX "unrecognized character after (?",                      // ParenthesesTypeInvalid
     
    7576    case ErrorCode::QuantifierIncomplete:
    7677    case ErrorCode::MissingParentheses:
     78    case ErrorCode::BracketUnmatched:
    7779    case ErrorCode::ParenthesesUnmatched:
    7880    case ErrorCode::ParenthesesTypeInvalid:
  • trunk/Source/JavaScriptCore/yarr/YarrErrorCode.h

    r255452 r255505  
    4242    QuantifierIncomplete,
    4343    MissingParentheses,
     44    BracketUnmatched,
    4445    ParenthesesUnmatched,
    4546    ParenthesesTypeInvalid,
  • trunk/Source/JavaScriptCore/yarr/YarrParser.h

    r255452 r255505  
    772772            case '[':
    773773                parseCharacterClass();
     774                lastTokenWasAnAtom = true;
     775                break;
     776
     777            case ']':
     778            case '}':
     779                if (m_isUnicode) {
     780                    m_errorCode = ErrorCode::BracketUnmatched;
     781                    break;
     782                }
     783
     784                m_delegate.atomPatternCharacter(consume());
    774785                lastTokenWasAnAtom = true;
    775786                break;
Note: See TracChangeset for help on using the changeset viewer.