From b7940ce153554e7f44d79d97e9536524b91111f3 Mon Sep 17 00:00:00 2001 From: Daniel Ehrenberg Date: Mon, 11 Dec 2017 15:12:27 +0100 Subject: [PATCH] Normative: Create a groups property unconditionally 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 --- spec.html | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/spec.html b/spec.html index 00194d8..9ca9c48 100644 --- a/spec.html +++ b/spec.html @@ -205,7 +205,9 @@

Runtime Semantics: RegExpBuiltinExec ( _R_, _S_ )

1. Perform ! CreateDataProperty(_A_, `"0"`, _matchedSubstr_). 1. If _R_ contains any |GroupName|, then 1. Let _groups_ be ObjectCreate(*null*). - 1. Perform ! CreateDataProperty(_A_, `"groups"`, _groups_). + 1. Else, + 1. Let _groups_ be *undefined*. + 1. Perform ! CreateDataProperty(_A_, `"groups"`, _groups_). 1. For each integer _i_ such that _i_ > 0 and _i_ ≤ _n_ 1. Let _captureI_ be _i_th element of _r_'s _captures_ List. 1. If _captureI_ is *undefined*, let _capturedValue_ be *undefined*.