Bug 205783 - RegExp.prototype[Symbol.replace] does not support named capture groups
Summary: RegExp.prototype[Symbol.replace] does not support named capture groups
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: WebKit Nightly Build
Hardware: All All
: P2 Minor
Assignee: Alexey Shvayka
URL:
Keywords: InRadar
Depends on: 176435
Blocks:
  Show dependency treegraph
 
Reported: 2020-01-05 18:01 PST by Alexey Shvayka
Modified: 2020-01-08 05:49 PST (History)
10 users (show)

See Also:


Attachments
Patch (6.47 KB, patch)
2020-01-05 19:25 PST, Alexey Shvayka
ross.kirsling: review+
Details | Formatted Diff | Diff
Patch (6.48 KB, patch)
2020-01-07 12:31 PST, Alexey Shvayka
no flags Details | Formatted Diff | Diff
Patch (6.47 KB, patch)
2020-01-07 22:09 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-05 18:01:30 PST
While String.prototype.replace() works as expected with named capture groups, slow path is not implemented.

Test case:
  /(?<a>.)/[Symbol.replace]("b", "$<a>")

Expected:
  "b"

Actual:
  "$<a>"

ECMA262:
  https://tc39.es/ecma262/#sec-regexp.prototype-@@replace (step 14.j)

Test262:
  https://test262.report/browse/built-ins/RegExp/named-groups/groups-object-subclass-sans.js
  https://test262.report/browse/built-ins/RegExp/named-groups/groups-object-subclass.js
Comment 1 Alexey Shvayka 2020-01-05 19:25:26 PST
Created attachment 386803 [details]
Patch
Comment 2 Ross Kirsling 2020-01-06 15:43:14 PST
Comment on attachment 386803 [details]
Patch

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

r=me with nits

> Source/JavaScriptCore/ChangeLog:10
> +        (step 14.j of https://tc39.es/ecma262/#sec-regexp.prototype-@@replace)

Probably better to indicate that it's not just 14.j but 14.j-l.

> Source/JavaScriptCore/builtins/RegExpPrototype.js:360
> +                namedCaptures = @toObject(namedCaptures, "RegExp.prototype[Symbol.replace] requires result.group not be null or undefined");

Hmm, this is meant to be `result.groups`, right?  Though that still seems a bit problematic since `result` is an internal name. And I guess we've verified that it's not undefined.

How about this?
"RegExp.prototype.@@replace does not allow matches to have a null 'groups' property."
Comment 3 Alexey Shvayka 2020-01-07 12:31:00 PST
Created attachment 387020 [details]
Patch

Set reviewer, tweak ChangeLog and error message.
Comment 4 Alexey Shvayka 2020-01-07 12:33:59 PST
(In reply to Ross Kirsling from comment #2)
> How about this?
> "RegExp.prototype.@@replace does not allow matches to have a null 'groups'
> property."

Thank you for review, I went with "RegExp.prototype[Symbol.replace] requires 'groups' property of a match not be null" to avoid @@ notation (because of https://github.com/tc39/ecma262/pull/1314) and for consistency with other @toObject error messages.
Comment 5 Ross Kirsling 2020-01-07 16:25:21 PST
Guess there's a rebase conflict here.
Comment 6 Alexey Shvayka 2020-01-07 22:09:22 PST
Created attachment 387075 [details]
Patch

Rebase patch.
Comment 7 WebKit Commit Bot 2020-01-08 05:48:28 PST
Comment on attachment 387075 [details]
Patch

Clearing flags on attachment: 387075

Committed r254195: <https://trac.webkit.org/changeset/254195>
Comment 8 WebKit Commit Bot 2020-01-08 05:48:30 PST
All reviewed patches have been landed.  Closing bug.
Comment 9 Radar WebKit Bug Importer 2020-01-08 05:49:14 PST
<rdar://problem/58406622>