Title: [255689] trunk
Revision
255689
Author
[email protected]
Date
2020-02-04 11:45:21 -0800 (Tue, 04 Feb 2020)

Log Message

Quantifiers after lookahead assertions should be syntax errors in Unicode patterns only
https://bugs.webkit.org/show_bug.cgi?id=206988

Reviewed by Darin Adler and Ross Kirsling.

JSTests:

* test262/expectations.yaml: Mark 10 test cases as passing.

Source/_javascript_Core:

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

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

Return value of parseParenthesesEnd() now matches with parseEscape() and
parseAtomEscape().

* yarr/YarrParser.h:
(JSC::Yarr::Parser::parseParenthesesBegin):
(JSC::Yarr::Parser::parseParenthesesEnd):
(JSC::Yarr::Parser::parseTokens):

Modified Paths

Diff

Modified: trunk/JSTests/ChangeLog (255688 => 255689)


--- trunk/JSTests/ChangeLog	2020-02-04 19:06:25 UTC (rev 255688)
+++ trunk/JSTests/ChangeLog	2020-02-04 19:45:21 UTC (rev 255689)
@@ -1,3 +1,12 @@
+2020-02-04  Alexey Shvayka  <[email protected]>
+
+        Quantifiers after lookahead assertions should be syntax errors in Unicode patterns only
+        https://bugs.webkit.org/show_bug.cgi?id=206988
+
+        Reviewed by Darin Adler and Ross Kirsling.
+
+        * test262/expectations.yaml: Mark 10 test cases as passing.
+
 2020-02-03  Alexey Shvayka  <[email protected]>
 
         \0 identity escapes should be syntax errors in Unicode patterns only

Modified: trunk/JSTests/test262/expectations.yaml (255688 => 255689)


--- trunk/JSTests/test262/expectations.yaml	2020-02-04 19:06:25 UTC (rev 255688)
+++ trunk/JSTests/test262/expectations.yaml	2020-02-04 19:45:21 UTC (rev 255689)
@@ -1579,9 +1579,6 @@
 test/built-ins/RegExp/unicode_restricted_octal_escape.js:
   default: 'Test262Error: RegExp("[\1]", "u"):  Expected a SyntaxError to be thrown but no exception was thrown at all'
   strict mode: 'Test262Error: RegExp("[\1]", "u"):  Expected a SyntaxError to be thrown but no exception was thrown at all'
-test/built-ins/RegExp/unicode_restricted_quantifiable_assertion.js:
-  default: 'Test262Error: RegExp("(?=.)*", "u"):  Expected a SyntaxError to be thrown but no exception was thrown at all'
-  strict mode: 'Test262Error: RegExp("(?=.)*", "u"):  Expected a SyntaxError to be thrown but no exception was thrown at all'
 test/built-ins/Set/proto-from-ctor-realm.js:
   default: 'Test262Error: Expected SameValue(«[object Set]», «[object Set]») to be true'
   strict mode: 'Test262Error: Expected SameValue(«[object Set]», «[object Set]») to be true'
@@ -3372,18 +3369,6 @@
 test/language/literals/regexp/u-invalid-oob-decimal-escape.js:
   default: 'Test262: This statement should not be evaluated.'
   strict mode: 'Test262: This statement should not be evaluated.'
-test/language/literals/regexp/u-invalid-optional-lookahead.js:
-  default: 'Test262: This statement should not be evaluated.'
-  strict mode: 'Test262: This statement should not be evaluated.'
-test/language/literals/regexp/u-invalid-optional-negative-lookahead.js:
-  default: 'Test262: This statement should not be evaluated.'
-  strict mode: 'Test262: This statement should not be evaluated.'
-test/language/literals/regexp/u-invalid-range-lookahead.js:
-  default: 'Test262: This statement should not be evaluated.'
-  strict mode: 'Test262: This statement should not be evaluated.'
-test/language/literals/regexp/u-invalid-range-negative-lookahead.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/Source/_javascript_Core/ChangeLog (255688 => 255689)


--- trunk/Source/_javascript_Core/ChangeLog	2020-02-04 19:06:25 UTC (rev 255688)
+++ trunk/Source/_javascript_Core/ChangeLog	2020-02-04 19:45:21 UTC (rev 255689)
@@ -1,3 +1,24 @@
+2020-02-04  Alexey Shvayka  <[email protected]>
+
+        Quantifiers after lookahead assertions should be syntax errors in Unicode patterns only
+        https://bugs.webkit.org/show_bug.cgi?id=206988
+
+        Reviewed by Darin Adler and Ross Kirsling.
+
+        This change adds SyntaxError for quantifiable assertions in Unicode patterns,
+        aligning JSC with V8 and SpiderMonkey.
+
+        Grammar: https://tc39.es/ecma262/#prod-annexB-Term
+        (/u flag precludes the use of QuantifiableAssertion)
+
+        Return value of parseParenthesesEnd() now matches with parseEscape() and
+        parseAtomEscape().
+
+        * yarr/YarrParser.h:
+        (JSC::Yarr::Parser::parseParenthesesBegin):
+        (JSC::Yarr::Parser::parseParenthesesEnd):
+        (JSC::Yarr::Parser::parseTokens):
+
 2020-02-04  Yusuke Suzuki  <[email protected]>
 
         [JSC] Introduce UnlinkedCodeBlockGenerator and reduce sizeof(UnlinkedCodeBlock)

Modified: trunk/Source/_javascript_Core/yarr/YarrParser.h (255688 => 255689)


--- trunk/Source/_javascript_Core/yarr/YarrParser.h	2020-02-04 19:06:25 UTC (rev 255688)
+++ trunk/Source/_javascript_Core/yarr/YarrParser.h	2020-02-04 19:45:21 UTC (rev 255689)
@@ -654,6 +654,8 @@
         ASSERT(peek() == '(');
         consume();
 
+        auto type = ParenthesesType::Subpattern;
+
         if (tryConsume('?')) {
             if (atEndOfPattern()) {
                 m_errorCode = ErrorCode::ParenthesesTypeInvalid;
@@ -667,10 +669,12 @@
             
             case '=':
                 m_delegate.atomParentheticalAssertionBegin();
+                type = ParenthesesType::Assertion;
                 break;
 
             case '!':
                 m_delegate.atomParentheticalAssertionBegin(true);
+                type = ParenthesesType::Assertion;
                 break;
 
             case '<': {
@@ -693,7 +697,7 @@
         } else
             m_delegate.atomParenthesesSubpatternBegin();
 
-        ++m_parenthesesNestingDepth;
+        m_parenthesesStack.append(type);
     }
 
     /*
@@ -700,19 +704,25 @@
      * parseParenthesesEnd():
      *
      * Helper for parseTokens(); checks for parse errors (due to unmatched parentheses).
+     *
+     * The boolean value returned by this method indicates whether the token parsed
+     * was either an Atom or, for web compatibility reasons, QuantifiableAssertion
+     * in non-Unicode pattern.
      */
-    void parseParenthesesEnd()
+    bool parseParenthesesEnd()
     {
         ASSERT(!hasError(m_errorCode));
         ASSERT(peek() == ')');
         consume();
 
-        if (m_parenthesesNestingDepth > 0)
-            m_delegate.atomParenthesesEnd();
-        else
+        if (m_parenthesesStack.isEmpty()) {
             m_errorCode = ErrorCode::ParenthesesUnmatched;
+            return false;
+        }
 
-        --m_parenthesesNestingDepth;
+        m_delegate.atomParenthesesEnd();
+        auto type = m_parenthesesStack.takeLast();
+        return type == ParenthesesType::Subpattern || !m_isUnicode;
     }
 
     /*
@@ -763,8 +773,7 @@
                 break;
 
             case ')':
-                parseParenthesesEnd();
-                lastTokenWasAnAtom = true;
+                lastTokenWasAnAtom = parseParenthesesEnd();
                 break;
 
             case '^':
@@ -863,7 +872,7 @@
                 return;
         }
 
-        if (m_parenthesesNestingDepth > 0)
+        if (!m_parenthesesStack.isEmpty())
             m_errorCode = ErrorCode::MissingParentheses;
     }
 
@@ -1144,6 +1153,8 @@
         return WTF::nullopt;
     }
 
+    enum class ParenthesesType : uint8_t { Subpattern, Assertion };
+
     Delegate& m_delegate;
     unsigned m_backReferenceLimit;
     ErrorCode m_errorCode { ErrorCode::NoError };
@@ -1151,7 +1162,7 @@
     unsigned m_size;
     unsigned m_index { 0 };
     bool m_isUnicode;
-    unsigned m_parenthesesNestingDepth { 0 };
+    Vector<ParenthesesType, 16> m_parenthesesStack;
     HashSet<String> m_captureGroupNames;
 
     // Derived by empirical testing of compile time in PCRE and WREC.
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to