-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Normative: correct spec bug in RegExp.prototype[Symbol.matchAll]
#1517
base: main
Are you sure you want to change the base?
Conversation
Filed on v8 as https://bugs.chromium.org/p/v8/issues/detail?id=9174, which it turns out matched the spec but not the intention/convention of the RegExp flags value.
cc @schuay @peterwmwong PTAL |
This was a mistake on my part - https://tc39.github.io/ecma262/#sec-regexpinitialize has a special case for |
@@ -31129,7 +31129,8 @@ <h1>RegExp.prototype [ @@matchAll ] ( _string_ )</h1> | |||
1. If Type(_R_) is not Object, throw a *TypeError* exception. | |||
1. Let _S_ be ? ToString(_string_). | |||
1. Let _C_ be ? SpeciesConstructor(_R_, %RegExp%). | |||
1. Let _flags_ be ? ToString(? Get(_R_, `"flags"`)). | |||
1. Let _flagsValue_ be ? Get(_R_, `"flags"`). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think that @@split
suffers from a similar issue?
var str = 'a\u{1d11e}b';
var pattern = /\u{1d11e}/u;
Object.defineProperty(pattern, 'flags', { value: undefined, configurable: true });
str.split(pattern);
// SyntaxError: Invalid flags supplied to RegExp constructor 'undefinedy'
undefinedy
🤣
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that also seems like the same spec bug to me.
I'd be happy to pursue changing this in the other methods too, if folks feel that's viable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we're going to do this in multiple places, should we have something like a ToStringOrEmpty
operation to handle undefined
(or null
)?
BTW: null
is an issue too, both for matchAll and split
I'm not convinced we should be adding defensive cases like this in subclassing built-ins. There remain lots of other silly things you can do to interfere with how things run. |
@littledan this isn't about subclassing; my example in the v8 bug is about a mutated base regex literal, and it follows the convention in |
I know; I was using "subclassing" in the broad sense where this is all caused by "subclassable built-ins", the justification in ES6 to read |
That was about people deleting things off of RegExp.prototype. This is about following existing conventions when reading flags off of an object, which are that undefined becomes the empty string, not the string “undefined”. If i were merely handling edge cases I’d want to do the same for null, but that’s not the convention so I’m not proposing that. |
We discussed a case of deleting things off of |
This may change in the future, pending tc39/ecma262#1517
…chAll]` implementation in node 12/chrome See https://bugs.chromium.org/p/v8/issues/detail?id=9173 / tc39/ecma262#1517
(Posting here since Jordan asked) The V8 team is not in favor of this patch. It enables even more esoteric RegExp subclassing behavior than is already possible today, and if accepted, would set precedent for similar changes. Subclassing built-ins is an important use case, but in particular for |
3d0c24c
to
7a79833
Compare
Filed on v8 as https://bugs.chromium.org/p/v8/issues/detail?id=9174, which it turns out matched the spec but not the intention/convention of the RegExp flags value.