ECMA-262 (12th Edition) ECMAScript 2021 Language Specification - page 31

 

  Главная      Manuals     ECMA-262 (12th Edition) ECMAScript 2021 Language Specification

 

Search            copyright infringement  

 

 

 

 

 

 

 

 

 

 

 

Content      ..     29      30      31      32     ..

 

 

 

ECMA-262 (12th Edition) ECMAScript 2021 Language Specification - page 31

 

 

The initial value of 

Boolean.prototype

Boolean.prototype

 is the 

Boolean prototype object

.

This property has the attributes { [[Writable]]: 

false

, [[Enumerable]]: 

false

, [[Configurable]]: 

false

 }.

The 

Boolean prototype object

:

is 

%Boolean.prototype%

.

is an 

ordinary object

.

is itself a Boolean object; it has a [[BooleanData]] internal slot with the value 

false

.

has a [[Prototype]] internal slot whose value is 

%Object.prototype%

.

The abstract operation 

thisBooleanValue

 takes argument 

value

. It performs the following steps when called:

1.  If 

Type

(

value

) is Boolean, return 

value

.

2.  If 

Type

(

value

) is Object and 

value

 has a [[BooleanData]] internal slot, then

a.  Let 

b

 be 

value

.[[BooleanData]].

b. 

Assert

Type

(

b

) is Boolean.

c.  Return 

b

.

3.  Throw a 

TypeError

 exception.

The initial value of 

Boolean.prototype.constructor

Boolean.prototype.constructor

 is 

%Boolean%

.

The following steps are taken:

1.  Let 

b

 be ? 

thisBooleanValue

(

this

 value).

2.  If 

b

 is 

true

, return 

"true"

; else return 

"false"

.

The following steps are taken:

1.  Return ? 

thisBooleanValue

(

this

 value).

Boolean instances are ordinary objects that inherit properties from the 

Boolean prototype object

. Boolean instances

have a [[BooleanData]] internal slot. The [[BooleanData]] internal slot is the Boolean value represented by this Boolean
object.

20.3.2.1  Boolean.prototype

20.3.3  Properties of the Boolean Prototype Object

20.3.3.1  Boolean.prototype.constructor

20.3.3.2  Boolean.prototype.toString ( )

20.3.3.3  Boolean.prototype.valueOf ( )

20.3.4  Properties of Boolean Instances

20.4  Symbol Objects

496

The Symbol 

constructor

:

is 

%Symbol%

.

is the initial value of the 

"Symbol"

 property of the 

global object

.

returns a new Symbol value when called as a function.
is not intended to be used with the 

new

new

 operator.

is not intended to be subclassed.
may be used as the value of an 

extends

extends

 clause of a class definition but a 

super

super

 call to it will cause an

exception.

When 

Symbol

Symbol

 is called with optional argument 

description

, the following steps are taken:

1.  If NewTarget is not 

undefined

, throw a 

TypeError

 exception.

2.  If 

description

 is 

undefined

, let 

descString

 be 

undefined

.

3.  Else, let 

descString

 be ? 

ToString

(

description

).

4.  Return a new unique Symbol value whose [[Description]] value is 

descString

.

The Symbol 

constructor

:

has a [[Prototype]] internal slot whose value is 

%Function.prototype%

.

has the following properties:

The initial value of 

Symbol.asyncIterator

Symbol.asyncIterator

 is the well known symbol 

@@asyncIterator

 (

Table 1

).

This property has the attributes { [[Writable]]: 

false

, [[Enumerable]]: 

false

, [[Configurable]]: 

false

 }.

When 

Symbol.for

Symbol.for

 is called with argument 

key

 it performs the following steps:

1.  Let 

stringKey

 be ? 

ToString

(

key

).

2.  For each element 

e

 of the GlobalSymbolRegistry 

List

, do

a.  If 

SameValue

(

e

.[[Key]], 

stringKey

) is 

true

, return 

e

.[[Symbol]].

3. 

Assert

: GlobalSymbolRegistry does not currently contain an entry for 

stringKey

.

4.  Let 

newSymbol

 be a new unique Symbol value whose [[Description]] value is 

stringKey

.

5.  Append the 

Record

 { [[Key]]: 

stringKey

, [[Symbol]]: 

newSymbol

 } to the GlobalSymbolRegistry 

List

.

6.  Return 

newSymbol

.

The GlobalSymbolRegistry is a 

List

 that is globally available. It is shared by all realms. Prior to the evaluation of any

ECMAScript code it is initialized as a new empty 

List

. Elements of the GlobalSymbolRegistry are Records with the

structure defined in 

Table 51

.

20.4.1  The Symbol Constructor

20.4.1.1  Symbol ( [ 

description

 ] )

20.4.2  Properties of the Symbol Constructor

20.4.2.1  Symbol.asyncIterator

20.4.2.2  Symbol.for ( 

key

 )

497

Table 51: GlobalSymbolRegistry 

Record

 Fields

Field Name

Value

Usage

[[Key]]

A String

A string key used to globally identify a Symbol.

[[Symbol]]

A Symbol A symbol that can be retrieved from any 

realm

.

The initial value of 

Symbol.hasInstance

Symbol.hasInstance

 is the well-known symbol 

@@hasInstance

 (

Table 1

).

This property has the attributes { [[Writable]]: 

false

, [[Enumerable]]: 

false

, [[Configurable]]: 

false

 }.

The initial value of 

Symbol.isConcatSpreadable

Symbol.isConcatSpreadable

 is the well-known symbol 

@@isConcatSpreadable

 (

Table 1

).

This property has the attributes { [[Writable]]: 

false

, [[Enumerable]]: 

false

, [[Configurable]]: 

false

 }.

The initial value of 

Symbol.iterator

Symbol.iterator

 is the well-known symbol 

@@iterator

 (

Table 1

).

This property has the attributes { [[Writable]]: 

false

, [[Enumerable]]: 

false

, [[Configurable]]: 

false

 }.

When 

Symbol.keyFor

Symbol.keyFor

 is called with argument 

sym

 it performs the following steps:

1.  If 

Type

(

sym

) is not Symbol, throw a 

TypeError

 exception.

2.  For each element 

e

 of the GlobalSymbolRegistry 

List

 (see 

20.4.2.2

), do

a.  If 

SameValue

(

e

.[[Symbol]], 

sym

) is 

true

, return 

e

.[[Key]].

3. 

Assert

: GlobalSymbolRegistry does not currently contain an entry for 

sym

.

4.  Return 

undefined

.

The initial value of 

Symbol.match

Symbol.match

 is the well-known symbol 

@@match

 (

Table 1

).

This property has the attributes { [[Writable]]: 

false

, [[Enumerable]]: 

false

, [[Configurable]]: 

false

 }.

The initial value of 

Symbol.matchAll

Symbol.matchAll

 is the well-known symbol 

@@matchAll

 (

Table 1

).

This property has the attributes { [[Writable]]: 

false

, [[Enumerable]]: 

false

, [[Configurable]]: 

false

 }.

The initial value of 

Symbol.prototype

Symbol.prototype

 is the 

Symbol prototype object

.

20.4.2.3  Symbol.hasInstance

20.4.2.4  Symbol.isConcatSpreadable

20.4.2.5  Symbol.iterator

20.4.2.6  Symbol.keyFor ( 

sym

 )

20.4.2.7  Symbol.match

20.4.2.8  Symbol.matchAll

20.4.2.9  Symbol.prototype

498

Marchen

Marchen

Marchen

Marchen

Marc

Marc

Medefaidrin

Medefaidrin

Medefaidrin

Medefaidrin

Medf

Medf

Masaram_Gondi

Masaram_Gondi

Masaram_Gondi

Masaram_Gondi

Gonm

Gonm

Meetei_Mayek

Meetei_Mayek

Meetei_Mayek

Meetei_Mayek

Mtei

Mtei

Mende_Kikakui

Mende_Kikakui

Mende_Kikakui

Mende_Kikakui

Mend

Mend

Meroitic_Cursive

Meroitic_Cursive

Meroitic_Cursive

Meroitic_Cursive

Merc

Merc

Meroitic_Hieroglyphs

Meroitic_Hieroglyphs

Meroitic_Hieroglyphs

Meroitic_Hieroglyphs

Mero

Mero

Miao

Miao

Miao

Miao

Plrd

Plrd

Modi

Modi

Modi

Modi

Mongolian

Mongolian

Mongolian

Mongolian

Mong

Mong

Mro

Mro

Mro

Mro

Mroo

Mroo

Multani

Multani

Multani

Multani

Mult

Mult

Myanmar

Myanmar

Myanmar

Myanmar

Mymr

Mymr

Nabataean

Nabataean

Nabataean

Nabataean

Nbat

Nbat

Nandinagari

Nandinagari

Nandinagari

Nandinagari

Nand

Nand

New_Tai_Lue

New_Tai_Lue

New_Tai_Lue

New_Tai_Lue

Talu

Talu

Newa

Newa

Newa

Newa

Nko

Nko

Nko

Nko

Nkoo

Nkoo

Nushu

Nushu

Nushu

Nushu

Nshu

Nshu

608

Nyiakeng_Puachue_Hmong

Nyiakeng_Puachue_Hmong

Nyiakeng_Puachue_Hmong

Nyiakeng_Puachue_Hmong

Hmnp

Hmnp

Ogham

Ogham

Ogham

Ogham

Ogam

Ogam

Ol_Chiki

Ol_Chiki

Ol_Chiki

Ol_Chiki

Olck

Olck

Old_Hungarian

Old_Hungarian

Old_Hungarian

Old_Hungarian

Hung

Hung

Old_Italic

Old_Italic

Old_Italic

Old_Italic

Ital

Ital

Old_North_Arabian

Old_North_Arabian

Old_North_Arabian

Old_North_Arabian

Narb

Narb

Old_Permic

Old_Permic

Old_Permic

Old_Permic

Perm

Perm

Old_Persian

Old_Persian

Old_Persian

Old_Persian

Xpeo

Xpeo

Old_Sogdian

Old_Sogdian

Old_Sogdian

Old_Sogdian

Sogo

Sogo

Old_South_Arabian

Old_South_Arabian

Old_South_Arabian

Old_South_Arabian

Sarb

Sarb

Old_Turkic

Old_Turkic

Old_Turkic

Old_Turkic

Orkh

Orkh

Oriya

Oriya

Oriya

Oriya

Orya

Orya

Osage

Osage

Osage

Osage

Osge

Osge

Osmanya

Osmanya

Osmanya

Osmanya

Osma

Osma

Pahawh_Hmong

Pahawh_Hmong

Pahawh_Hmong

Pahawh_Hmong

Hmng

Hmng

Palmyrene

Palmyrene

Palmyrene

Palmyrene

Palm

Palm

Pau_Cin_Hau

Pau_Cin_Hau

Pau_Cin_Hau

Pau_Cin_Hau

Pauc

Pauc

Phags_Pa

Phags_Pa

Phags_Pa

Phags_Pa

Phag

Phag

609

Phoenician

Phoenician

Phoenician

Phoenician

Phnx

Phnx

Psalter_Pahlavi

Psalter_Pahlavi

Psalter_Pahlavi

Psalter_Pahlavi

Phlp

Phlp

Rejang

Rejang

Rejang

Rejang

Rjng

Rjng

Runic

Runic

Runic

Runic

Runr

Runr

Samaritan

Samaritan

Samaritan

Samaritan

Samr

Samr

Saurashtra

Saurashtra

Saurashtra

Saurashtra

Saur

Saur

Sharada

Sharada

Sharada

Sharada

Shrd

Shrd

Shavian

Shavian

Shavian

Shavian

Shaw

Shaw

Siddham

Siddham

Siddham

Siddham

Sidd

Sidd

SignWriting

SignWriting

SignWriting

SignWriting

Sgnw

Sgnw

Sinhala

Sinhala

Sinhala

Sinhala

Sinh

Sinh

Sogdian

Sogdian

Sogdian

Sogdian

Sogd

Sogd

Sora_Sompeng

Sora_Sompeng

Sora_Sompeng

Sora_Sompeng

Sora

Sora

Soyombo

Soyombo

Soyombo

Soyombo

Soyo

Soyo

Sundanese

Sundanese

Sundanese

Sundanese

Sund

Sund

Syloti_Nagri

Syloti_Nagri

Syloti_Nagri

Syloti_Nagri

Sylo

Sylo

Syriac

Syriac

Syriac

Syriac

Syrc

Syrc

Tagalog

Tagalog

Tagalog

Tagalog

Tglg

Tglg

610

Tagbanwa

Tagbanwa

Tagbanwa

Tagbanwa

Tagb

Tagb

Tai_Le

Tai_Le

Tai_Le

Tai_Le

Tale

Tale

Tai_Tham

Tai_Tham

Tai_Tham

Tai_Tham

Lana

Lana

Tai_Viet

Tai_Viet

Tai_Viet

Tai_Viet

Tavt

Tavt

Takri

Takri

Takri

Takri

Takr

Takr

Tamil

Tamil

Tamil

Tamil

Taml

Taml

Tangut

Tangut

Tangut

Tangut

Tang

Tang

Telugu

Telugu

Telugu

Telugu

Telu

Telu

Thaana

Thaana

Thaana

Thaana

Thaa

Thaa

Thai

Thai

Thai

Thai

Tibetan

Tibetan

Tibetan

Tibetan

Tibt

Tibt

Tifinagh

Tifinagh

Tifinagh

Tifinagh

Tfng

Tfng

Tirhuta

Tirhuta

Tirhuta

Tirhuta

Tirh

Tirh

Ugaritic

Ugaritic

Ugaritic

Ugaritic

Ugar

Ugar

Vai

Vai

Vai

Vai

Vaii

Vaii

Wancho

Wancho

Wancho

Wancho

Wcho

Wcho

Warang_Citi

Warang_Citi

Warang_Citi

Warang_Citi

Wara

Wara

Yezidi

Yezidi

Yezidi

Yezidi

Yezi

Yezi

Yi

Yi

Yi

Yi

611

Yiii

Yiii

Zanabazar_Square

Zanabazar_Square

Zanabazar_Square

Zanabazar_Square

Zanb

Zanb

With parameter 

direction

.

The production 

AtomEscape

 

::

 

DecimalEscape

 evaluates as follows:

1.  Evaluate 

DecimalEscape

 to obtain an 

integer

 

n

.

2. 

Assert

n

 

 

NcapturingParens

.

3.  Return ! 

BackreferenceMatcher

(

n

direction

).

The production 

AtomEscape

 

::

 

CharacterEscape

 evaluates as follows:

1.  Evaluate 

CharacterEscape

 to obtain a character 

ch

.

2.  Let 

A

 be a one-element CharSet containing the character 

ch

.

3.  Return ! 

CharacterSetMatcher

(

A

false

direction

).

The production 

AtomEscape

 

::

 

CharacterClassEscape

 evaluates as follows:

1.  Evaluate 

CharacterClassEscape

 to obtain a CharSet 

A

.

2.  Return ! 

CharacterSetMatcher

(

A

false

direction

).

NOTE

The production 

AtomEscape

 

::

 

k

 

GroupName

 evaluates as follows:

1.  Search the enclosing 

Pattern

 for an instance of a 

GroupSpecifier

 containing a 

RegExpIdentifierName

 which has a

CapturingGroupName

 equal to the 

CapturingGroupName

 of the 

RegExpIdentifierName

 contained in 

GroupName

.

2. 

Assert

: A unique such 

GroupSpecifier

 is found.

3.  Let 

parenIndex

 be the number of left-capturing parentheses in the entire regular expression that occur to the left

of the located 

GroupSpecifier

. This is the total number of 

Atom

 

::

 

(

 

GroupSpecifier

 

Disjunction

 

)

 Parse Nodes

prior to or enclosing the located 

GroupSpecifier

, including its immediately enclosing 

Atom

.

4.  Return ! 

BackreferenceMatcher

(

parenIndex

direction

).

The abstract operation BackreferenceMatcher takes arguments 

n

 (a positive 

integer

) and 

direction

 (1 or -1). It performs

the following steps when called:

1. 

Assert

n

 

 1.

2.  Return a new Matcher with parameters (

x

c

) that captures 

n

 and 

direction

 and performs the following steps

An escape sequence of the form 

\\

 followed by a non-zero decimal number 

n

 matches the result

of the 

n

th

 set of capturing parentheses (

22.2.2.1

). It is an error if the regular expression has fewer

than 

n

 capturing parentheses. If the regular expression has 

n

 or more capturing parentheses but

the 

n

th

 one is 

undefined

 because it has not captured anything, then the backreference always

succeeds.

22.2.2.9  AtomEscape

22.2.2.9.1  BackreferenceMatcher ( 

n

direction

 )

612

when called:

a. 

Assert

x

 is a State.

b. 

Assert

c

 is a Continuation.

c.  Let 

cap

 be 

x

's 

captures

 

List

.

d.  Let 

s

 be 

cap

[

n

].

e.  If 

s

 is 

undefined

, return 

c

(

x

).

f.  Let 

e

 be 

x

's 

endIndex

.

g.  Let 

len

 be the number of elements in 

s

.

h.  Let 

f

 be 

e

 + 

direction

 

×

 

len

.

i.  If 

f

 < 0 or 

f

 > 

InputLength

, return 

failure

.

j.  Let 

g

 be 

min

(

e

f

).

k.  If there exists an 

integer

 

i

 between 0 (inclusive) and 

len

 (exclusive) such that 

Canonicalize

(

s

[

i

]) is not the

same character value as 

Canonicalize

(

Input

[

g

 + 

i

]), return 

failure

.

l.  Let 

y

 be the State (

f

cap

).

m.  Return 

c

(

y

).

The 

CharacterEscape

 productions evaluate as follows:

CharacterEscape

 

::

ControlEscape

c

 

ControlLetter

0

 [lookahead 

 

DecimalDigit

]

HexEscapeSequence
RegExpUnicodeEscapeSequence
IdentityEscape

1.  Let 

cv

 be the 

CharacterValue

 of this 

CharacterEscape

.

2.  Return the character whose character value is 

cv

.

The 

DecimalEscape

 productions evaluate as follows:

DecimalEscape

 

::

 

NonZeroDigit

 

DecimalDigits

opt

1.  Return the 

CapturingGroupNumber

 of this 

DecimalEscape

.

NOTE

The production 

CharacterClassEscape

 

::

 

d

 evaluates as follows:

1.  Return the ten-element CharSet containing the characters 

00

 through 

99

 inclusive.

If 

\\

 is followed by a decimal number 

n

 whose first digit is not 

00

, then the escape sequence is

considered to be a backreference. It is an error if 

n

 is greater than the total number of left-

capturing parentheses in the entire regular expression.

22.2.2.10  CharacterEscape

22.2.2.11  DecimalEscape

22.2.2.12  CharacterClassEscape

613

The production 

CharacterClassEscape

 

::

 

D

 evaluates as follows:

1.  Return the CharSet containing all characters not in the CharSet returned by 

CharacterClassEscape

 

::

 

d

 .

The production 

CharacterClassEscape

 

::

 

s

 evaluates as follows:

1.  Return the CharSet containing all characters corresponding to a code point on the right-hand side of the 

WhiteSpace

 or 

LineTerminator

 productions.

The production 

CharacterClassEscape

 

::

 

S

 evaluates as follows:

1.  Return the CharSet containing all characters not in the CharSet returned by 

CharacterClassEscape

 

::

 

s

 .

The production 

CharacterClassEscape

 

::

 

w

 evaluates as follows:

1.  Return 

WordCharacters

.

The production 

CharacterClassEscape

 

::

 

W

 evaluates as follows:

1.  Return the CharSet containing all characters not in the CharSet returned by 

CharacterClassEscape

 

::

 

w

 .

The production 

CharacterClassEscape

 

::

 

p{

 

UnicodePropertyValueExpression

 

}

 evaluates as follows:

1.  Return the CharSet containing all Unicode code points included in the CharSet returned by 

UnicodePropertyValueExpression

.

The production 

CharacterClassEscape

 

::

 

P{

 

UnicodePropertyValueExpression

 

}

 evaluates as follows:

1.  Return the CharSet containing all Unicode code points not included in the CharSet returned by 

UnicodePropertyValueExpression

.

The production 

UnicodePropertyValueExpression

 

::

 

UnicodePropertyName

 

=

 

UnicodePropertyValue

 evaluates as follows:

1.  Let 

ps

 be 

SourceText

 of 

UnicodePropertyName

.

2.  Let 

p

 be ! 

UnicodeMatchProperty

(

ps

).

3. 

Assert

p

 is a Unicode 

property name

 or property alias listed in the “

Property name

 and aliases” column of

Table 56

.

4.  Let 

vs

 be 

SourceText

 of 

UnicodePropertyValue

.

5.  Let 

v

 be ! 

UnicodeMatchPropertyValue

(

p

vs

).

6.  Return the CharSet containing all Unicode code points whose character database definition includes the

property 

p

 with value 

v

.

The production 

UnicodePropertyValueExpression

 

::

 

LoneUnicodePropertyNameOrValue

 evaluates as follows:

1.  Let 

s

 be 

SourceText

 of 

LoneUnicodePropertyNameOrValue

.

2.  If ! 

UnicodeMatchPropertyValue

(

General_Category

General_Category

s

) is identical to a 

List

 of Unicode code points that is

the name of a Unicode general category or general category alias listed in the “Property value and aliases”
column of 

Table 58

, then

a.  Return the CharSet containing all Unicode code points whose character database definition includes the

property “General_Category” with value 

s

.

3.  Let 

p

 be ! 

UnicodeMatchProperty

(

s

).

4. 

Assert

p

 is a binary Unicode property or binary property alias listed in the “

Property name

 and aliases”

column of 

Table 57

.

614

5.  Return the CharSet containing all Unicode code points whose character database definition includes the

property 

p

 with value “True”.

The production 

CharacterClass

 

::

 

[

 

ClassRanges

 

]

 evaluates as follows:

1.  Evaluate 

ClassRanges

 to obtain a CharSet 

A

.

2.  Return the two results 

A

 and 

false

.

The production 

CharacterClass

 

::

 

[

 

^

 

ClassRanges

 

]

 evaluates as follows:

1.  Evaluate 

ClassRanges

 to obtain a CharSet 

A

.

2.  Return the two results 

A

 and 

true

.

The production 

ClassRanges

 

::

  [empty]  evaluates as follows:

1.  Return the empty CharSet.

The production 

ClassRanges

 

::

 

NonemptyClassRanges

 evaluates as follows:

1.  Return the CharSet that is the result of evaluating 

NonemptyClassRanges

.

The production 

NonemptyClassRanges

 

::

 

ClassAtom

 evaluates as follows:

1.  Return the CharSet that is the result of evaluating 

ClassAtom

.

The production 

NonemptyClassRanges

 

::

 

ClassAtom

 

NonemptyClassRangesNoDash

 evaluates as follows:

1.  Evaluate 

ClassAtom

 to obtain a CharSet 

A

.

2.  Evaluate 

NonemptyClassRangesNoDash

 to obtain a CharSet 

B

.

3.  Return the union of CharSets 

A

 and 

B

.

The production 

NonemptyClassRanges

 

::

 

ClassAtom

 

-

 

ClassAtom

 

ClassRanges

 evaluates as follows:

1.  Evaluate the first 

ClassAtom

 to obtain a CharSet 

A

.

2.  Evaluate the second 

ClassAtom

 to obtain a CharSet 

B

.

3.  Evaluate 

ClassRanges

 to obtain a CharSet 

C

.

4.  Let 

D

 be ! 

CharacterRange

(

A

B

).

5.  Return the union of 

D

 and 

C

.

The abstract operation CharacterRange takes arguments 

A

 (a CharSet) and 

B

 (a CharSet). It performs the following

steps when called:

1. 

Assert

A

 and 

B

 each contain exactly one character.

2.  Let 

a

 be the one character in CharSet 

A

.

22.2.2.13  CharacterClass

22.2.2.14  ClassRanges

22.2.2.15  NonemptyClassRanges

22.2.2.15.1  CharacterRange ( 

A

B

 )

615

3.  Let 

b

 be the one character in CharSet 

B

.

4.  Let 

i

 be the character value of character 

a

.

5.  Let 

j

 be the character value of character 

b

.

6. 

Assert

i

 

 

j

.

7.  Return the CharSet containing all characters with a character value greater than or equal to 

i

 and less than or

equal to 

j

.

The production 

NonemptyClassRangesNoDash

 

::

 

ClassAtom

 evaluates as follows:

1.  Return the CharSet that is the result of evaluating 

ClassAtom

.

The production 

NonemptyClassRangesNoDash

 

::

 

ClassAtomNoDash

 

NonemptyClassRangesNoDash

 evaluates as

follows:

1.  Evaluate 

ClassAtomNoDash

 to obtain a CharSet 

A

.

2.  Evaluate 

NonemptyClassRangesNoDash

 to obtain a CharSet 

B

.

3.  Return the union of CharSets 

A

 and 

B

.

The production 

NonemptyClassRangesNoDash

 

::

 

ClassAtomNoDash

 

-

 

ClassAtom

 

ClassRanges

 evaluates as follows:

1.  Evaluate 

ClassAtomNoDash

 to obtain a CharSet 

A

.

2.  Evaluate 

ClassAtom

 to obtain a CharSet 

B

.

3.  Evaluate 

ClassRanges

 to obtain a CharSet 

C

.

4.  Let 

D

 be ! 

CharacterRange

(

A

B

).

5.  Return the union of 

D

 and 

C

.

NOTE 1

NOTE 2

NOTE 3

The production 

ClassAtom

 

::

 

-

 evaluates as follows:

ClassRanges

 can expand into a single 

ClassAtom

 and/or ranges of two 

ClassAtom

 separated by

dashes. In the latter case the 

ClassRanges

 includes all characters between the first 

ClassAtom

 and

the second 

ClassAtom

, inclusive; an error occurs if either 

ClassAtom

 does not represent a single

character (for example, if one is \w) or if the first 

ClassAtom

's character value is greater than the

second 

ClassAtom

's character value.

Even if the pattern ignores case, the case of the two ends of a range is significant in determining
which characters belong to the range. Thus, for example, the pattern 

/[E-F]/i

/[E-F]/i

 matches only

the letters 

EE

FF

ee

, and 

ff

, while the pattern 

/[E-f]/i

/[E-f]/i

 matches all upper and lower-case letters

in the Unicode Basic Latin block as well as the symbols 

[[

\\

]]

^^

__

, and 

``

.

--

 character can be treated literally or it can denote a range. It is treated literally if it is the first

or last character of 

ClassRanges

, the beginning or end limit of a range specification, or

immediately follows a range specification.

22.2.2.16  NonemptyClassRangesNoDash

22.2.2.17  ClassAtom

616

1.  Return the CharSet containing the single character 

--

 U+002D (HYPHEN-MINUS).

The production 

ClassAtom

 

::

 

ClassAtomNoDash

 evaluates as follows:

1.  Return the CharSet that is the result of evaluating 

ClassAtomNoDash

.

The production 

ClassAtomNoDash

 

::

 

SourceCharacter

 but not one of 

\

 or 

]

 or 

-

 evaluates as follows:

1.  Return the CharSet containing the character matched by 

SourceCharacter

.

The production 

ClassAtomNoDash

 

::

 

\

 

ClassEscape

 evaluates as follows:

1.  Return the CharSet that is the result of evaluating 

ClassEscape

.

The 

ClassEscape

 productions evaluate as follows:

ClassEscape

 

::

 

b

ClassEscape

 

::

 

-

ClassEscape

 

::

 

CharacterEscape

1.  Let 

cv

 be the 

CharacterValue

 of this 

ClassEscape

.

2.  Let 

c

 be the character whose character value is 

cv

.

3.  Return the CharSet containing the single character 

c

.

ClassEscape

 

::

 

CharacterClassEscape

1.  Return the CharSet that is the result of evaluating 

CharacterClassEscape

.

NOTE

The RegExp 

constructor

:

is 

%RegExp%

.

is the initial value of the 

"RegExp"

 property of the 

global object

.

creates and initializes a new RegExp object when called as a function rather than as a 

constructor

. Thus the

function call 

RegExp(…)

RegExp(…)

 is equivalent to the object creation expression 

new RegExp(…)

new RegExp(…)

 with the same

arguments.
is designed to be subclassable. It may be used as the value of an 

extends

extends

 clause of a class definition. Subclass

constructors that intend to inherit the specified RegExp behaviour must include a 

super

super

 call to the RegExp

constructor

 to create and initialize subclass instances with the necessary internal slots.

ClassAtom

 can use any of the escape sequences that are allowed in the rest of the regular

expression except for 

\b

\b

\B

\B

, and backreferences. Inside a 

CharacterClass

\b

\b

 means the

backspace character, while 

\B

\B

 and backreferences raise errors. Using a backreference inside a 

ClassAtom

 causes an error.

22.2.2.18  ClassAtomNoDash

22.2.2.19  ClassEscape

22.2.3  The RegExp Constructor

617

The following steps are taken:

1.  Let 

patternIsRegExp

 be ? 

IsRegExp

(

pattern

).

2.  If NewTarget is 

undefined

, then

a.  Let 

newTarget

 be the 

active function object

.

b.  If 

patternIsRegExp

 is 

true

 and 

flags

 is 

undefined

, then

i.  Let 

patternConstructor

 be ? 

Get

(

pattern

"constructor"

).

ii.  If 

SameValue

(

newTarget

patternConstructor

) is 

true

, return 

pattern

.

3.  Else, let 

newTarget

 be NewTarget.

4.  If 

Type

(

pattern

) is Object and 

pattern

 has a [[RegExpMatcher]] internal slot, then

a.  Let 

P

 be 

pattern

.[[OriginalSource]].

b.  If 

flags

 is 

undefined

, let 

F

 be 

pattern

.[[OriginalFlags]].

c.  Else, let 

F

 be 

flags

.

5.  Else if 

patternIsRegExp

 is 

true

, then

a.  Let 

P

 be ? 

Get

(

pattern

"source"

).

b.  If 

flags

 is 

undefined

, then

i.  Let 

F

 be ? 

Get

(

pattern

"flags"

).

c.  Else, let 

F

 be 

flags

.

6.  Else,

a.  Let 

P

 be 

pattern

.

b.  Let 

F

 be 

flags

.

7.  Let 

O

 be ? 

RegExpAlloc

(

newTarget

).

8.  Return ? 

RegExpInitialize

(

O

P

F

).

NOTE

The abstract operation RegExpAlloc takes argument 

newTarget

. It performs the following steps when called:

1.  Let 

obj

 be ? 

OrdinaryCreateFromConstructor

(

newTarget

"%RegExp.prototype%"

, « [[RegExpMatcher]],

[[OriginalSource]], [[OriginalFlags]] »).

2.  Perform ! 

DefinePropertyOrThrow

(

obj

"lastIndex"

, PropertyDescriptor { [[Writable]]: 

true

, [[Enumerable]]:

false

, [[Configurable]]: 

false

 }).

3.  Return 

obj

.

The abstract operation RegExpInitialize takes arguments 

obj

pattern

, and 

flags

. It performs the following steps when

called:

If pattern is supplied using a 

StringLiteral

, the usual escape sequence substitutions are performed

before the String is processed by RegExp. If pattern must contain an escape sequence to be
recognized by RegExp, any U+005C (REVERSE SOLIDUS) code points must be escaped within
the 

StringLiteral

 to prevent them being removed when the contents of the 

StringLiteral

 are

formed.

22.2.3.1  RegExp ( 

pattern

flags

 )

22.2.3.2  Abstract Operations for the RegExp Constructor

22.2.3.2.1  RegExpAlloc ( 

newTarget

 )

22.2.3.2.2  RegExpInitialize ( 

obj

pattern

flags

 )

618

1.  If 

pattern

 is 

undefined

, let 

P

 be the empty String.

2.  Else, let 

P

 be ? 

ToString

(

pattern

).

3.  If 

flags

 is 

undefined

, let 

F

 be the empty String.

4.  Else, let 

F

 be ? 

ToString

(

flags

).

5.  If 

F

 contains any code unit other than 

"g"

"i"

"m"

"s"

"u"

, or 

"y"

 or if it contains the same code unit more than

once, throw a 

SyntaxError

 exception.

6.  If 

F

 contains 

"u"

, let 

u

 be 

true

; else let 

u

 be 

false

.

7.  If 

u

 is 

true

, then

a.  Let 

patternText

 be ! 

StringToCodePoints

(

P

).

b.  Let 

patternCharacters

 be a 

List

 whose elements are the code points of 

patternText

.

8.  Else,

a.  Let 

patternText

 be the result of interpreting each of 

P

's 16-bit elements as a Unicode BMP code point.

UTF-16 decoding is not applied to the elements.

b.  Let 

patternCharacters

 be a 

List

 whose elements are the code unit elements of 

P

.

9.  Let 

parseResult

 be 

ParsePattern

(

patternText

u

).

10.  If 

parseResult

 is a non-empty 

List

 of 

SyntaxError

 objects, throw a 

SyntaxError

 exception.

11. 

Assert

parseResult

 is a 

Parse Node

 for 

Pattern

.

12.  Set 

obj

.[[OriginalSource]] to 

P

.

13.  Set 

obj

.[[OriginalFlags]] to 

F

.

14.  Set 

obj

.[[RegExpMatcher]] to the 

Abstract Closure

 that evaluates 

parseResult

 by applying the semantics

provided in 

22.2.2

 using 

patternCharacters

 as the pattern's 

List

 of 

SourceCharacter

 values and 

F

 as the flag

parameters.

15.  Perform ? 

Set

(

obj

"lastIndex"

+0

𝔽

true

).

16.  Return 

obj

.

The abstract operation ParsePattern takes arguments 

patternText

 (a sequence of Unicode code points) and 

u

 (a

Boolean). It performs the following steps when called:

1.  If 

u

 is 

true

, then

a.  Let 

parseResult

 be 

ParseText

(

patternText

Pattern

[+U, +N]

).

2.  Else,

a.  Let 

parseResult

 be 

ParseText

(

patternText

Pattern

[~U, ~N]

).

b.  If 

parseResult

 is a 

Parse Node

 and 

parseResult

 contains a 

GroupName

, then

i.  Set 

parseResult

 to 

ParseText

(

patternText

Pattern

[~U, +N]

).

3.  Return 

parseResult

.

The abstract operation RegExpCreate takes arguments 

P

 and 

F

. It performs the following steps when called:

1.  Let 

obj

 be ? 

RegExpAlloc

(

%RegExp%

).

2.  Return ? 

RegExpInitialize

(

obj

P

F

).

The abstract operation EscapeRegExpPattern takes arguments 

P

 and 

F

. It performs the following steps when called:

22.2.3.2.3  Static Semantics: ParsePattern ( 

patternText

u

 )

22.2.3.2.4  RegExpCreate ( 

P

F

 )

22.2.3.2.5  EscapeRegExpPattern ( 

P

F

 )

619

1.  Let 

S

 be a String in the form of a 

Pattern

[~U]

 (

Pattern

[+U]

 if 

F

 contains 

"u"

) equivalent to 

P

 interpreted as UTF-

16 encoded Unicode code points (

6.1.4

), in which certain code points are escaped as described below. 

S

 may or

may not be identical to 

P

; however, the 

Abstract Closure

 that would result from evaluating 

S

 as a 

Pattern

[~U]

 (

Pattern

[+U]

 if 

F

 contains 

"u"

) must behave identically to the 

Abstract Closure

 given by the constructed object's

[[RegExpMatcher]] internal slot. Multiple calls to this abstract operation using the same values for 

P

 and 

F

must produce identical results.

2.  The code points 

//

 or any 

LineTerminator

 occurring in the pattern shall be escaped in 

S

 as necessary to ensure

that the 

string-concatenation

 of 

"/"

S

"/"

, and 

F

 can be parsed (in an appropriate lexical context) as a 

RegularExpressionLiteral

 that behaves identically to the constructed regular expression. For example, if 

P

 is 

"/"

,

then 

S

 could be 

"\/"

 or 

"\u002F"

, among other possibilities, but not 

"/"

, because 

///

///

 followed by 

F

 would be

parsed as a 

SingleLineComment

 rather than a 

RegularExpressionLiteral

. If 

P

 is the empty String, this specification

can be met by letting 

S

 be 

"(?:)"

.

3.  Return 

S

.

The RegExp 

constructor

:

has a [[Prototype]] internal slot whose value is 

%Function.prototype%

.

has the following properties:

The initial value of 

RegExp.prototype

RegExp.prototype

 is the 

RegExp prototype object

.

This property has the attributes { [[Writable]]: 

false

, [[Enumerable]]: 

false

, [[Configurable]]: 

false

 }.

RegExp[@@species]

RegExp[@@species]

 is an 

accessor property

 whose set accessor function is 

undefined

. Its get accessor function

performs the following steps:

1.  Return the 

this

 value.

The value of the 

"name"

 property of this function is 

"get [Symbol.species]"

.

NOTE

The 

RegExp prototype object

:

is 

%RegExp.prototype%

.

is an 

ordinary object

.

is not a RegExp instance and does not have a [[RegExpMatcher]] internal slot or any of the other internal slots
of RegExp instance objects.

RegExp prototype methods normally use their 

this

 value's 

constructor

 to create a derived object.

However, a subclass 

constructor

 may over-ride that default behaviour by redefining its

@@species

 property.

22.2.4  Properties of the RegExp Constructor

22.2.4.1  RegExp.prototype

22.2.4.2  get RegExp [ @@species ]

22.2.5  Properties of the RegExp Prototype Object

620

 

 

 

 

 

 

 

Content      ..     29      30      31      32     ..