Bug 206988 - Quantifiers after lookahead assertions should be syntax errors in Unicode patterns only
Summary: Quantifiers after lookahead assertions should be syntax errors in Unicode pat...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: WebKit Nightly Build
Hardware: All All
: P2 Trivial
Assignee: Alexey Shvayka
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2020-01-30 01:27 PST by Alexey Shvayka
Modified: 2020-02-04 11:46 PST (History)
10 users (show)

See Also:


Attachments
Patch (7.19 KB, patch)
2020-01-30 01:53 PST, Alexey Shvayka
no flags Details | Formatted Diff | Diff
Patch (7.21 KB, patch)
2020-01-30 17:28 PST, Alexey Shvayka
no flags Details | Formatted Diff | Diff
Patch (7.41 KB, patch)
2020-01-31 18:48 PST, Alexey Shvayka
no flags Details | Formatted Diff | Diff
Patch (7.40 KB, patch)
2020-02-04 09:45 PST, Alexey Shvayka
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Alexey Shvayka 2020-01-30 01:27:35 PST
Test case:
  /(?!.)+/u

Expected:
  SyntaxError thrown

Actual:
  RegExp instance

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

  Term[U, N] ::
    [~U] QuantifiableAssertion[?N] Quantifier

  Assertion[U, N] ::
    [~U] QuantifiableAssertion[?N]

  QuantifiableAssertion[N] ::
    (?= Disjunction[~U, ?N])
    (?! Disjunction[~U, ?N])

Test262:
  https://test262.report/browse/built-ins/RegExp/unicode_restricted_quantifiable_assertion.js
  https://test262.report/browse/language/literals/regexp/u-invalid-range-lookahead.js
  https://test262.report/browse/language/literals/regexp/u-invalid-optional-negative-lookahead.js
Comment 1 Alexey Shvayka 2020-01-30 01:53:26 PST
Created attachment 389236 [details]
Patch
Comment 2 Alexey Shvayka 2020-01-30 17:28:33 PST
Created attachment 389312 [details]
Patch

Rename bug in ChangeLog.
Comment 3 Darin Adler 2020-01-31 09:05:45 PST
Comment on attachment 389312 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=389312&action=review

> Source/JavaScriptCore/yarr/YarrParser.h:709
> +        auto parensType = m_parenthesesStack.takeLast();
> +        return parensType == ParenthesesType::Subpattern || !m_isUnicode;

In WebKit coding style we normally don’t abbreviate a word like parentheses even in a local variable name. I think calling this just "type" is fine.

> Source/JavaScriptCore/yarr/YarrParser.h:1124
> +    enum ParenthesesType { Subpattern, Assertion };

Might get a slightly more efficient code if this was an enum class based on bool or uint8_t.

> Source/JavaScriptCore/yarr/YarrParser.h:1133
> +    Vector<ParenthesesType, 16> m_parenthesesStack;

Thisis likely going to be a bit inefficient; we could possibly get a more efficient implementation of a bit vector.
Comment 4 Darin Adler 2020-01-31 12:36:50 PST
I didn’t set the commit queue flag yet because I think the change to enum class might be worth doing before landing. If not, add a comment some committer can add commit-queue+.
Comment 5 Alexey Shvayka 2020-01-31 18:48:44 PST
Created attachment 389448 [details]
Patch

Set reviewer, rename vars, and use std::vector with typed enum class.
Comment 6 Alexey Shvayka 2020-02-01 06:20:25 PST
(In reply to Darin Adler from comment #3)
>
> Thisis likely going to be a bit inefficient; we could possibly get a more
> efficient implementation of a bit vector.

I did some isolated profiling of std::vector<bool>: it allocates 8x less memory, but it performs ~30% slower on push_back() + pop_back() and is not compatible with `enum class`.
Comment 7 Ross Kirsling 2020-02-04 09:32:18 PST
Comment on attachment 389448 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=389448&action=review

> Source/JavaScriptCore/yarr/YarrParser.h:1141
> +    std::vector<ParenthesesType> m_parenthesesStack;

Regardless of the enum class type, we should still use a WTF::Vector.
Comment 8 Alexey Shvayka 2020-02-04 09:45:31 PST
Created attachment 389671 [details]
Patch

Replace std::vector with WTF::Vector.
Comment 9 WebKit Commit Bot 2020-02-04 11:45:26 PST
Comment on attachment 389671 [details]
Patch

Clearing flags on attachment: 389671

Committed r255689: <https://trac.webkit.org/changeset/255689>
Comment 10 WebKit Commit Bot 2020-02-04 11:45:28 PST
All reviewed patches have been landed.  Closing bug.
Comment 11 Radar WebKit Bug Importer 2020-02-04 11:46:17 PST
<rdar://problem/59157737>