Skip to content
This repository has been archived by the owner on Jan 25, 2022. It is now read-only.

Commit

Permalink
Normative: Create a groups property unconditionally
Browse files Browse the repository at this point in the history
If the RegExp does not have named groups, set a groups property
of the result to undefined. This change is made to facilitate
optimizing RegExp implementations, which often take a "fast path"
for built-in, unmodified to not incur the overhead of the full
subclassable semantics. If the "groups" property may be read
from higher up on the prototype chain, the fast path for
RegExp.prototype.replace would become more complex or slower, or
alternatively, more conditions about the environment might need
to be checked as a precondition to apply the fast path.

An alternate approach would be to only read an own groups property
based on a HasOwnProperty test followed by a Get. I don't see big
advantages or disadvantages to that approach vs this one, and I'd
be fine to revisit this patch if more differentiating factors
are raised before Stage 4.

Closes #34
  • Loading branch information
littledan committed Dec 12, 2017
1 parent fb78299 commit b7940ce
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion spec.html
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,9 @@ <h1>Runtime Semantics: RegExpBuiltinExec ( _R_, _S_ )</h1>
1. Perform ! CreateDataProperty(_A_, `"0"`, _matchedSubstr_).
1. <ins>If _R_ contains any |GroupName|, then</ins>
1. <ins>Let _groups_ be ObjectCreate(*null*).</ins>
1. <ins>Perform ! CreateDataProperty(_A_, `"groups"`, _groups_).</ins>
1. <ins>Else,</ins>
1. <ins>Let _groups_ be *undefined*.</ins>
1. <ins>Perform ! CreateDataProperty(_A_, `"groups"`, _groups_).</ins>
1. For each integer _i_ such that _i_ &gt; 0 and _i_ &le; _n_
1. Let _captureI_ be _i_<sup>th</sup> element of _r_'s _captures_ List.
1. If _captureI_ is *undefined*, let _capturedValue_ be *undefined*.
Expand Down

0 comments on commit b7940ce

Please sign in to comment.