Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upThrowing TypeErrors on access of RegExp.prototype flag properties breaks some websites #500
Comments
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
AnnotationMark
Mar 28, 2016
Oops. Looks like this issue was already reported in #262. Sorry for the noise.
AnnotationMark
commented
Mar 28, 2016
|
Oops. Looks like this issue was already reported in #262. Sorry for the noise. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
littledan
Mar 28, 2016
Member
@AnnotationMark Are you seeing this error in any shipping browser? Maybe it'd be useful to forward the bug report to them. In #262 I explained the compatibility workarounds that I have put into Chrome.
|
@AnnotationMark Are you seeing this error in any shipping browser? Maybe it'd be useful to forward the bug report to them. In #262 I explained the compatibility workarounds that I have put into Chrome. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
AnnotationMark
Mar 29, 2016
@littledan I did not observe this in a shipping browser, but only while implementing the RegExp.prototype spec requirements in WebKit.
AnnotationMark
commented
Mar 29, 2016
|
@littledan I did not observe this in a shipping browser, but only while implementing the RegExp.prototype spec requirements in WebKit. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
|
Looks like this was fixed by #511. |
AnnotationMark commentedMar 28, 2016
The spec on the RegExp.prototype object states that it "is not a RegExp instance and does not have a [[RegExpMatcher]] internal slot or any of the other internal slots of RegExp instance objects" (see https://tc39.github.io/ecma262/2016/#sec-properties-of-the-regexp-prototype-object).
As a result, accessing flag properties (like "sticky") on an object should result in a TypeError being thrown according to the spec (see https://tc39.github.io/ecma262/2016/#sec-get-regexp.prototype.sticky).
This breaks websites that do feature testing by checking if the property is undefined. For example, there is a JS library XRegExp (see http://xregexp.com) that extends the regexp implementation, and XRegExp does this form of feature testing (see https://github.com/slevithan/xregexp/blob/d0e665d4068cec4d15919215b098b2373f1f12e9/tests/perf/versions/xregexp-all-v2.0.0.js and https://github.com/slevithan/xregexp/blob/28a2b033c5951477bed8c7c867ddf7e89c431cd4/tests/perf/index.html). As a result, websites that uses XRegExp can break (e.g. some Atlassian tools).
Checking for an undefined property is a common web idiom for feature testing. In light of that, does it make sense for the spec to require that we throw a TypeError doing an undefined check on a RegExp.prototype flag property?