-
Notifications
You must be signed in to change notification settings - Fork 12
Inconsistencies to RegExp.prototype[@@match] #28
Comments
I'm not sure I understand your second point; can you provide me with a more concrete example? Indeed, the goal when passed a non-global regex was to provide an iterator for a single match, and RegExpExec used naively would provide (and did, in my initial polyfill implementation, oops) an infinite iterator for the same match object. |
We may be talking past each other, I don't understand the connection to my point 1. AFAIK
Sure. Now consider So, |
You're totally right that IsRegExp only needs a non-truthy value; the other part tho is that all the built-in regex symbols are codifying legacy behavior - matchAll isn't necessarily constrained by those limitations. With your specific example, I think you've definitely located an interesting case. An exec loop with that regex provides only a single match; and matchAll as currently specced actually uses exec, not match, under the hood - so the current algorithm intentionally provides an iterator for a single match object. (That said, It's important here that the iterator is for match objects - arrays with an Unrelated to the spec steps, and generally speaking, would it match your intuition if |
Yeah, personally I think staying consistent with |
I think that is both an improvement (smoothing over edge cases I hadn't previously thought of) and also more closely matches the goals of the proposal - and I think it can be achieved with a different spec algorithm. Thanks for the help; I'll keep this open until I've finished that change. |
I'm a bit unclear on how closely
matchAll
should match the behavior ofmatch
. There's two (somewhat related) inconsistencies I noticed:Given a non-global regexp,
@@match
will simply returnReturn ? RegExpExec(rx, S).
, whilematchAll
returns a single-element iterator.matchAll
handles termination throughlastIndex
comparisons and thus terminates on zero-width matches.@@match
terminates on a failed match and advanceslastIndex
throughAdvanceStringIndex
on zero-width matches.I suppose the termination method for
matchAll
was chosen to terminate correctly when passed a non-global regexp(?)It feels strange to have these inconsistencies between such closely-related methods.
The text was updated successfully, but these errors were encountered: