Skip to content

Annex B: Specify non-standard RegExp static properties #137

@claudepache

Description

@claudepache

Update: Link to proposal: https://github.com/tc39/proposal-regexp-legacy-features


All web browsers expose non-standard properties on the RegExp constructor, that are updated each time a match is done.

The list of properties that are exposed by all common browsers are the following. They typically expose other properties not mentioned here, but not shared by all implementations:

$1, $2, $3, $4, $5, $6, $7, $8, $9,

and (in pairs, where the first and the second one return the same value):

input, $_
lastMatch, $&
lastParen, $+
leftContext, $`
rightContext, $'

Some observations:

  • their value is always a string;
  • some implementations expose them as data properties, others as accessor properties;
  • those properties are non-enumerable;
  • they cannot be deleted or modified manually.

It would be useful to specify them. I think that the following should be required:

  1. Those properties should be accessors. That would be more honest about the changing nature of their value;
  2. They should be deletable. Indeed, they represent global communication channels that may be unwanted in some environments;
  3. It should be specified when they are updated, presumably sometime during the execution of the builtin RegExp#exec method. This is useful if we want, in some future, separate the part of RegExp#exec that does the real work, and the part that does stateful updates on various objects.

Metadata

Metadata

Assignees

No one assigned

    Labels

    normative changeAffects behavior required to correctly evaluate some ECMAScript source textproposalThis is related to a specific proposal, and will be closed/merged when the proposal reaches stage 4.web reality

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions