Disabling nonstandard RegExp functionalities for proper subclasses of RegExp

Claude Pache claude.pache at gmail.com
Tue Apr 26 18:20:02 UTC 2016


Hi,

About the bad old nonstandard RegExp functionalities:

* `RegExp.prototype.compile()` — currently in Annex B;
* `RegExp.$1`, `RegExp.leftContext`, etc. — currently unspecced.

Although we could probably not get rid of them for plain regexps, I think it is a good idea to disable them for proper subclasses of RegExp (e.g., `class MyRegExp extends RegExp {}`).

Basically, the reason is that these methods break encapsulation (they operate on the raw regexp), leading to potential bugs when using them. Moreover `RegExp.$1` and friends have the additional troublesome property of relying on a global state that could be unexpectedly modified. For concrete examples of what could go wrong, see the subclass-restriction-motivation.md subpage in the proposal linked below.

Here is a link to a possible specification for the regexp statics (RegExp.$1, ...), that includes the disabling of bad legacy features for proper subclasses of RegExp (and for some edge-cases around cross-realm interactions):

     https://github.com/claudepache/es-regexp-legacy-static-properties <https://github.com/claudepache/es-regexp-legacy-static-properties>

What do you think? Are implementations willing to try?

—Claude

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20160426/420cac63/attachment.html>


More information about the es-discuss mailing list