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

Throwing TypeErrors on access of RegExp.prototype flag properties breaks some websites #500

Closed
AnnotationMark opened this Issue Mar 28, 2016 · 4 comments

Comments

Projects
None yet
3 participants
@AnnotationMark

AnnotationMark commented Mar 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?

@AnnotationMark

This comment has been minimized.

Show comment
Hide comment
@AnnotationMark

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.

@littledan

This comment has been minimized.

Show comment
Hide comment
@littledan

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.

Member

littledan commented Mar 28, 2016

@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

This comment has been minimized.

Show comment
Hide comment
@AnnotationMark

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.

@domenic

This comment has been minimized.

Show comment
Hide comment
@domenic

domenic Jul 28, 2016

Member

Looks like this was fixed by #511.

Member

domenic commented Jul 28, 2016

Looks like this was fixed by #511.

@domenic domenic closed this Jul 28, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment