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

 

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

 

Search            copyright infringement  

 

 

 

 

 

 

 

 

 

 

 

Content      ..     30      31      32      33     ..

 

 

 

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

 

 

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

%Object.prototype%

.

NOTE

The initial value of 

RegExp.prototype.constructor

RegExp.prototype.constructor

 is 

%RegExp%

.

Performs a regular expression match of 

string

 against the regular expression and returns an Array object containing

the results of the match, or 

null

 if 

string

 did not match.

The String 

ToString

(

string

) is searched for an occurrence of the regular expression pattern as follows:

1.  Let 

R

 be the 

this

 value.

2.  Perform ? 

RequireInternalSlot

(

R

, [[RegExpMatcher]]).

3.  Let 

S

 be ? 

ToString

(

string

).

4.  Return ? 

RegExpBuiltinExec

(

R

S

).

The abstract operation RegExpExec takes arguments 

R

 and 

S

. It performs the following steps when called:

1. 

Assert

Type

(

R

) is Object.

2. 

Assert

Type

(

S

) is String.

3.  Let 

exec

 be ? 

Get

(

R

"exec"

).

4.  If 

IsCallable

(

exec

) is 

true

, then

a.  Let 

result

 be ? 

Call

(

exec

R

, « 

S

 »).

b.  If 

Type

(

result

) is neither Object nor Null, throw a 

TypeError

 exception.

c.  Return 

result

.

5.  Perform ? 

RequireInternalSlot

(

R

, [[RegExpMatcher]]).

6.  Return ? 

RegExpBuiltinExec

(

R

S

).

NOTE

The abstract operation RegExpBuiltinExec takes arguments 

R

 and 

S

. It performs the following steps when called:

1. 

Assert

R

 is an initialized RegExp instance.

2. 

Assert

Type

(

S

) is String.

3.  Let 

length

 be the number of code units in 

S

.

4.  Let 

lastIndex

 be 

(? 

ToLength

(? 

Get

(

R

"lastIndex"

))).

The RegExp prototype object does not have a 

"valueOf"

 property of its own; however, it inherits

the 

"valueOf"

 property from the 

Object prototype object

.

If a callable 

"exec"

 property is not found this algorithm falls back to attempting to use the built-in

RegExp matching algorithm. This provides compatible behaviour for code written for prior
editions where most built-in algorithms that use regular expressions did not perform a dynamic
property lookup of 

"exec"

.

22.2.5.1  RegExp.prototype.constructor

22.2.5.2  RegExp.prototype.exec ( 

string

 )

22.2.5.2.1  RegExpExec ( 

R

S

 )

22.2.5.2.2  RegExpBuiltinExec ( 

R

S

 )

621

5.  Let 

flags

 be 

R

.[[OriginalFlags]].

6.  If 

flags

 contains 

"g"

, let 

global

 be 

true

; else let 

global

 be 

false

.

7.  If 

flags

 contains 

"y"

, let 

sticky

 be 

true

; else let 

sticky

 be 

false

.

8.  If 

global

 is 

false

 and 

sticky

 is 

false

, set 

lastIndex

 to 0.

9.  Let 

matcher

 be 

R

.[[RegExpMatcher]].

10.  If 

flags

 contains 

"u"

, let 

fullUnicode

 be 

true

; else let 

fullUnicode

 be 

false

.

11.  Let 

matchSucceeded

 be 

false

.

12.  Repeat, while 

matchSucceeded

 is 

false

,

a.  If 

lastIndex

 > 

length

, then

i.  If 

global

 is 

true

 or 

sticky

 is 

true

, then

1.  Perform ? 

Set

(

R

"lastIndex"

+0

𝔽

true

).

ii.  Return 

null

.

b.  Let 

r

 be 

matcher

(

S

lastIndex

).

c.  If 

r

 is 

failure

, then

i.  If 

sticky

 is 

true

, then

1.  Perform ? 

Set

(

R

"lastIndex"

+0

𝔽

true

).

2.  Return 

null

.

ii.  Set 

lastIndex

 to 

AdvanceStringIndex

(

S

lastIndex

fullUnicode

).

d.  Else,

i. 

Assert

r

 is a State.

ii.  Set 

matchSucceeded

 to 

true

.

13.  Let 

e

 be 

r

's 

endIndex

 value.

14.  If 

fullUnicode

 is 

true

, then

a. 

e

 is an index into the 

Input

 character list, derived from 

S

, matched by 

matcher

. Let 

eUTF

 be the smallest

index into 

S

 that corresponds to the character at element 

e

 of 

Input

. If 

e

 is greater than or equal to the

number of elements in 

Input

, then 

eUTF

 is the number of code units in 

S

.

b.  Set 

e

 to 

eUTF

.

15.  If 

global

 is 

true

 or 

sticky

 is 

true

, then

a.  Perform ? 

Set

(

R

"lastIndex"

(

e

), 

true

).

16.  Let 

n

 be the number of elements in 

r

's 

captures

 

List

. (This is the same value as 

22.2.2.1

's 

NcapturingParens

.)

17. 

Assert

n

 < 2

32

 - 1.

18.  Let 

A

 be ! 

ArrayCreate

(

n

 + 1).

19. 

Assert

: The 

mathematical value

 of 

A

's 

"length"

 property is 

n

 + 1.

20.  Perform ! 

CreateDataPropertyOrThrow

(

A

"index"

(

lastIndex

)).

21.  Perform ! 

CreateDataPropertyOrThrow

(

A

"input"

S

).

22.  Let 

matchedSubstr

 be the 

substring

 of 

S

 from 

lastIndex

 to 

e

.

23.  Perform ! 

CreateDataPropertyOrThrow

(

A

"0"

matchedSubstr

).

24.  If 

R

 contains any 

GroupName

, then

a.  Let 

groups

 be ! 

OrdinaryObjectCreate

(

null

).

25.  Else,

a.  Let 

groups

 be 

undefined

.

26.  Perform ! 

CreateDataPropertyOrThrow

(

A

"groups"

groups

).

27.  For each 

integer

 

i

 such that 

i

 

 1 and 

i

 

 

n

, do

a.  Let 

captureI

 be 

i

th

 element of 

r

's 

captures

 

List

.

b.  If 

captureI

 is 

undefined

, let 

capturedValue

 be 

undefined

.

c.  Else if 

fullUnicode

 is 

true

, then

i. 

Assert

captureI

 is a 

List

 of code points.

622

ii.  Let 

capturedValue

 be ! 

CodePointsToString

(

captureI

).

d.  Else,

i. 

Assert

fullUnicode

 is 

false

.

ii. 

Assert

captureI

 is a 

List

 of code units.

iii.  Let 

capturedValue

 be the String value consisting of the code units of 

captureI

.

e.  Perform ! 

CreateDataPropertyOrThrow

(

A

, ! 

ToString

(

i

)), 

capturedValue

).

f.  If the 

i

th

 capture of 

R

 was defined with a 

GroupName

, then

i.  Let 

s

 be the 

CapturingGroupName

 of the corresponding 

RegExpIdentifierName

.

ii.  Perform ! 

CreateDataPropertyOrThrow

(

groups

s

capturedValue

).

28.  Return 

A

.

The abstract operation AdvanceStringIndex takes arguments 

S

 (a String), 

index

 (a non-negative 

integer

), and 

unicode

 (a

Boolean). It performs the following steps when called:

1. 

Assert

index

 

 2

53

 - 1.

2.  If 

unicode

 is 

false

, return 

index

 + 1.

3.  Let 

length

 be the number of code units in 

S

.

4.  If 

index

 + 1 

 

length

, return 

index

 + 1.

5.  Let 

cp

 be ! 

CodePointAt

(

S

index

).

6.  Return 

index

 + 

cp

.[[CodeUnitCount]].

RegExp.prototype.dotAll

RegExp.prototype.dotAll

 is an 

accessor property

 whose set accessor function is 

undefined

. Its get accessor

function performs the following steps:

1.  Let 

R

 be the 

this

 value.

2.  If 

Type

(

R

) is not Object, throw a 

TypeError

 exception.

3.  If 

R

 does not have an [[OriginalFlags]] internal slot, then

a.  If 

SameValue

(

R

%RegExp.prototype%

) is 

true

, return 

undefined

.

b.  Otherwise, throw a 

TypeError

 exception.

4.  Let 

flags

 be 

R

.[[OriginalFlags]].

5.  If 

flags

 contains the code unit 0x0073 (LATIN SMALL LETTER S), return 

true

.

6.  Return 

false

.

RegExp.prototype.flags

RegExp.prototype.flags

 is an 

accessor property

 whose set accessor function is 

undefined

. Its get accessor

function performs the following steps:

1.  Let 

R

 be the 

this

 value.

2.  If 

Type

(

R

) is not Object, throw a 

TypeError

 exception.

3.  Let 

result

 be the empty String.

4.  Let 

global

 be ! 

ToBoolean

(? 

Get

(

R

"global"

)).

5.  If 

global

 is 

true

, append the code unit 0x0067 (LATIN SMALL LETTER G) as the last code unit of 

result

.

6.  Let 

ignoreCase

 be ! 

ToBoolean

(? 

Get

(

R

"ignoreCase"

)).

7.  If 

ignoreCase

 is 

true

, append the code unit 0x0069 (LATIN SMALL LETTER I) as the last code unit of 

result

.

22.2.5.2.3  AdvanceStringIndex ( 

S

index

unicode

 )

22.2.5.3  get RegExp.prototype.dotAll

22.2.5.4  get RegExp.prototype.flags

623

8.  Let 

multiline

 be ! 

ToBoolean

(? 

Get

(

R

"multiline"

)).

9.  If 

multiline

 is 

true

, append the code unit 0x006D (LATIN SMALL LETTER M) as the last code unit of 

result

.

10.  Let 

dotAll

 be ! 

ToBoolean

(? 

Get

(

R

"dotAll"

)).

11.  If 

dotAll

 is 

true

, append the code unit 0x0073 (LATIN SMALL LETTER S) as the last code unit of 

result

.

12.  Let 

unicode

 be ! 

ToBoolean

(? 

Get

(

R

"unicode"

)).

13.  If 

unicode

 is 

true

, append the code unit 0x0075 (LATIN SMALL LETTER U) as the last code unit of 

result

.

14.  Let 

sticky

 be ! 

ToBoolean

(? 

Get

(

R

"sticky"

)).

15.  If 

sticky

 is 

true

, append the code unit 0x0079 (LATIN SMALL LETTER Y) as the last code unit of 

result

.

16.  Return 

result

.

RegExp.prototype.global

RegExp.prototype.global

 is an 

accessor property

 whose set accessor function is 

undefined

. Its get accessor

function performs the following steps:

1.  Let 

R

 be the 

this

 value.

2.  If 

Type

(

R

) is not Object, throw a 

TypeError

 exception.

3.  If 

R

 does not have an [[OriginalFlags]] internal slot, then

a.  If 

SameValue

(

R

%RegExp.prototype%

) is 

true

, return 

undefined

.

b.  Otherwise, throw a 

TypeError

 exception.

4.  Let 

flags

 be 

R

.[[OriginalFlags]].

5.  If 

flags

 contains the code unit 0x0067 (LATIN SMALL LETTER G), return 

true

.

6.  Return 

false

.

RegExp.prototype.ignoreCase

RegExp.prototype.ignoreCase

 is an 

accessor property

 whose set accessor function is 

undefined

. Its get

accessor function performs the following steps:

1.  Let 

R

 be the 

this

 value.

2.  If 

Type

(

R

) is not Object, throw a 

TypeError

 exception.

3.  If 

R

 does not have an [[OriginalFlags]] internal slot, then

a.  If 

SameValue

(

R

%RegExp.prototype%

) is 

true

, return 

undefined

.

b.  Otherwise, throw a 

TypeError

 exception.

4.  Let 

flags

 be 

R

.[[OriginalFlags]].

5.  If 

flags

 contains the code unit 0x0069 (LATIN SMALL LETTER I), return 

true

.

6.  Return 

false

.

When the 

@@match

@@match

 method is called with argument 

string

, the following steps are taken:

1.  Let 

rx

 be the 

this

 value.

2.  If 

Type

(

rx

) is not Object, throw a 

TypeError

 exception.

3.  Let 

S

 be ? 

ToString

(

string

).

4.  Let 

global

 be ! 

ToBoolean

(? 

Get

(

rx

"global"

)).

5.  If 

global

 is 

false

, then

a.  Return ? 

RegExpExec

(

rx

S

).

6.  Else,

22.2.5.5  get RegExp.prototype.global

22.2.5.6  get RegExp.prototype.ignoreCase

22.2.5.7  RegExp.prototype [ @@match ] ( 

string

 )

624

a. 

Assert

global

 is 

true

.

b.  Let 

fullUnicode

 be ! 

ToBoolean

(? 

Get

(

rx

"unicode"

)).

c.  Perform ? 

Set

(

rx

"lastIndex"

+0

𝔽

true

).

d.  Let 

A

 be ! 

ArrayCreate

(0).

e.  Let 

n

 be 0.

f.  Repeat,

i.  Let 

result

 be ? 

RegExpExec

(

rx

S

).

ii.  If 

result

 is 

null

, then

1.  If 

n

 = 0, return 

null

.

2.  Return 

A

.

iii.  Else,

1.  Let 

matchStr

 be ? 

ToString

(? 

Get

(

result

"0"

)).

2.  Perform ! 

CreateDataPropertyOrThrow

(

A

, ! 

ToString

(

n

)), 

matchStr

).

3.  If 

matchStr

 is the empty String, then

a.  Let 

thisIndex

 be 

(? 

ToLength

(? 

Get

(

rx

"lastIndex"

))).

b.  Let 

nextIndex

 be 

AdvanceStringIndex

(

S

thisIndex

fullUnicode

).

c.  Perform ? 

Set

(

rx

"lastIndex"

nextIndex

), 

true

).

4.  Set 

n

 to 

n

 + 1.

The value of the 

"name"

 property of this function is 

"[Symbol.match]"

.

NOTE

When the 

@@matchAll

@@matchAll

 method is called with argument 

string

, the following steps are taken:

1.  Let 

R

 be the 

this

 value.

2.  If 

Type

(

R

) is not Object, throw a 

TypeError

 exception.

3.  Let 

S

 be ? 

ToString

(

string

).

4.  Let 

C

 be ? 

SpeciesConstructor

(

R

%RegExp%

).

5.  Let 

flags

 be ? 

ToString

(? 

Get

(

R

"flags"

)).

6.  Let 

matcher

 be ? 

Construct

(

C

, « 

R

flags

 »).

7.  Let 

lastIndex

 be ? 

ToLength

(? 

Get

(

R

"lastIndex"

)).

8.  Perform ? 

Set

(

matcher

"lastIndex"

lastIndex

true

).

9.  If 

flags

 contains 

"g"

, let 

global

 be 

true

.

10.  Else, let 

global

 be 

false

.

11.  If 

flags

 contains 

"u"

, let 

fullUnicode

 be 

true

.

12.  Else, let 

fullUnicode

 be 

false

.

13.  Return ! 

CreateRegExpStringIterator

(

matcher

S

global

fullUnicode

).

The value of the 

"name"

 property of this function is 

"[Symbol.matchAll]"

.

The 

@@match

 property is used by the 

IsRegExp

 abstract operation to identify objects that have

the basic behaviour of regular expressions. The absence of a 

@@match

 property or the existence

of such a property whose value does not Boolean coerce to 

true

 indicates that the object is not

intended to be used as a regular expression object.

22.2.5.8  RegExp.prototype [ @@matchAll ] ( 

string

 )

22.2.5.9  get RegExp.prototype.multiline

625

RegExp.prototype.multiline

RegExp.prototype.multiline

 is an 

accessor property

 whose set accessor function is 

undefined

. Its get

accessor function performs the following steps:

1.  Let 

R

 be the 

this

 value.

2.  If 

Type

(

R

) is not Object, throw a 

TypeError

 exception.

3.  If 

R

 does not have an [[OriginalFlags]] internal slot, then

a.  If 

SameValue

(

R

%RegExp.prototype%

) is 

true

, return 

undefined

.

b.  Otherwise, throw a 

TypeError

 exception.

4.  Let 

flags

 be 

R

.[[OriginalFlags]].

5.  If 

flags

 contains the code unit 0x006D (LATIN SMALL LETTER M), return 

true

.

6.  Return 

false

.

When the 

@@replace

@@replace

 method is called with arguments 

string

 and 

replaceValue

, the following steps are taken:

1.  Let 

rx

 be the 

this

 value.

2.  If 

Type

(

rx

) is not Object, throw a 

TypeError

 exception.

3.  Let 

S

 be ? 

ToString

(

string

).

4.  Let 

lengthS

 be the number of code unit elements in 

S

.

5.  Let 

functionalReplace

 be 

IsCallable

(

replaceValue

).

6.  If 

functionalReplace

 is 

false

, then

a.  Set 

replaceValue

 to ? 

ToString

(

replaceValue

).

7.  Let 

global

 be ! 

ToBoolean

(? 

Get

(

rx

"global"

)).

8.  If 

global

 is 

true

, then

a.  Let 

fullUnicode

 be ! 

ToBoolean

(? 

Get

(

rx

"unicode"

)).

b.  Perform ? 

Set

(

rx

"lastIndex"

+0

𝔽

true

).

9.  Let 

results

 be a new empty 

List

.

10.  Let 

done

 be 

false

.

11.  Repeat, while 

done

 is 

false

,

a.  Let 

result

 be ? 

RegExpExec

(

rx

S

).

b.  If 

result

 is 

null

, set 

done

 to 

true

.

c.  Else,

i.  Append 

result

 to the end of 

results

.

ii.  If 

global

 is 

false

, set 

done

 to 

true

.

iii.  Else,

1.  Let 

matchStr

 be ? 

ToString

(? 

Get

(

result

"0"

)).

2.  If 

matchStr

 is the empty String, then

a.  Let 

thisIndex

 be 

(? 

ToLength

(? 

Get

(

rx

"lastIndex"

))).

b.  Let 

nextIndex

 be 

AdvanceStringIndex

(

S

thisIndex

fullUnicode

).

c.  Perform ? 

Set

(

rx

"lastIndex"

nextIndex

), 

true

).

12.  Let 

accumulatedResult

 be the empty String.

13.  Let 

nextSourcePosition

 be 0.

14.  For each element 

result

 of 

results

, do

a.  Let 

resultLength

 be ? 

LengthOfArrayLike

(

result

).

b.  Let 

nCaptures

 be 

max

(

resultLength

 - 1, 0).

c.  Let 

matched

 be ? 

ToString

(? 

Get

(

result

"0"

)).

d.  Let 

matchLength

 be the number of code units in 

matched

.

22.2.5.10  RegExp.prototype [ @@replace ] ( 

string

replaceValue

 )

626

e.  Let 

position

 be ? 

ToIntegerOrInfinity

(? 

Get

(

result

"index"

)).

f.  Set 

position

 to the result of 

clamping

 

position

 between 0 and 

lengthS

.

g.  Let 

n

 be 1.

h.  Let 

captures

 be a new empty 

List

.

i.  Repeat, while 

n

 

 

nCaptures

,

i.  Let 

capN

 be ? 

Get

(

result

, ! 

ToString

n

))).

ii.  If 

capN

 is not 

undefined

, then

1.  Set 

capN

 to ? 

ToString

(

capN

).

iii.  Append 

capN

 as the last element of 

captures

.

iv.  Set 

n

 to 

n

 + 1.

j.  Let 

namedCaptures

 be ? 

Get

(

result

"groups"

).

k.  If 

functionalReplace

 is 

true

, then

i.  Let 

replacerArgs

 be « 

matched

 ».

ii.  Append in 

List

 order the elements of 

captures

 to the end of the 

List

 

replacerArgs

.

iii.  Append 

(

position

) and 

S

 to 

replacerArgs

.

iv.  If 

namedCaptures

 is not 

undefined

, then

1.  Append 

namedCaptures

 as the last element of 

replacerArgs

.

v.  Let 

replValue

 be ? 

Call

(

replaceValue

undefined

replacerArgs

).

vi.  Let 

replacement

 be ? 

ToString

(

replValue

).

l.  Else,

i.  If 

namedCaptures

 is not 

undefined

, then

1.  Set 

namedCaptures

 to ? 

ToObject

(

namedCaptures

).

ii.  Let 

replacement

 be ? 

GetSubstitution

(

matched

S

position

captures

namedCaptures

replaceValue

).

m.  If 

position

 

 

nextSourcePosition

, then

i.  NOTE: 

position

 should not normally move backwards. If it does, it is an indication of an ill-

behaving RegExp subclass or use of an access triggered side-effect to change the global flag or
other characteristics of 

rx

. In such cases, the corresponding substitution is ignored.

ii.  Set 

accumulatedResult

 to the 

string-concatenation

 of 

accumulatedResult

, the 

substring

 of 

S

 from

nextSourcePosition

 to 

position

, and 

replacement

.

iii.  Set 

nextSourcePosition

 to 

position

 + 

matchLength

.

15.  If 

nextSourcePosition

 

 

lengthS

, return 

accumulatedResult

.

16.  Return the 

string-concatenation

 of 

accumulatedResult

 and the 

substring

 of 

S

 from 

nextSourcePosition

.

The value of the 

"name"

 property of this function is 

"[Symbol.replace]"

.

When the 

@@search

@@search

 method is called with argument 

string

, the following steps are taken:

1.  Let 

rx

 be the 

this

 value.

2.  If 

Type

(

rx

) is not Object, throw a 

TypeError

 exception.

3.  Let 

S

 be ? 

ToString

(

string

).

4.  Let 

previousLastIndex

 be ? 

Get

(

rx

"lastIndex"

).

5.  If 

SameValue

(

previousLastIndex

+0

𝔽

) is 

false

, then

a.  Perform ? 

Set

(

rx

"lastIndex"

+0

𝔽

true

).

6.  Let 

result

 be ? 

RegExpExec

(

rx

S

).

7.  Let 

currentLastIndex

 be ? 

Get

(

rx

"lastIndex"

).

8.  If 

SameValue

(

currentLastIndex

previousLastIndex

) is 

false

, then

22.2.5.11  RegExp.prototype [ @@search ] ( 

string

 )

627

a.  Perform ? 

Set

(

rx

"lastIndex"

previousLastIndex

true

).

9.  If 

result

 is 

null

, return 

-1

𝔽

.

10.  Return ? 

Get

(

result

"index"

).

The value of the 

"name"

 property of this function is 

"[Symbol.search]"

.

NOTE

RegExp.prototype.source

RegExp.prototype.source

 is an 

accessor property

 whose set accessor function is 

undefined

. Its get accessor

function performs the following steps:

1.  Let 

R

 be the 

this

 value.

2.  If 

Type

(

R

) is not Object, throw a 

TypeError

 exception.

3.  If 

R

 does not have an [[OriginalSource]] internal slot, then

a.  If 

SameValue

(

R

%RegExp.prototype%

) is 

true

, return 

"(?:)"

.

b.  Otherwise, throw a 

TypeError

 exception.

4. 

Assert

R

 has an [[OriginalFlags]] internal slot.

5.  Let 

src

 be 

R

.[[OriginalSource]].

6.  Let 

flags

 be 

R

.[[OriginalFlags]].

7.  Return 

EscapeRegExpPattern

(

src

flags

).

The 

"lastIndex"

 and 

"global"

 properties of this RegExp object are ignored when performing the

search. The 

"lastIndex"

 property is left unchanged.

22.2.5.12  get RegExp.prototype.source

22.2.5.13  RegExp.prototype [ @@split ] ( 

string

limit

 )

628

NOTE 1

When the 

@@split

@@split

 method is called, the following steps are taken:

1.  Let 

rx

 be the 

this

 value.

2.  If 

Type

(

rx

) is not Object, throw a 

TypeError

 exception.

3.  Let 

S

 be ? 

ToString

(

string

).

4.  Let 

C

 be ? 

SpeciesConstructor

(

rx

%RegExp%

).

5.  Let 

flags

 be ? 

ToString

(? 

Get

(

rx

"flags"

)).

6.  If 

flags

 contains 

"u"

, let 

unicodeMatching

 be 

true

.

7.  Else, let 

unicodeMatching

 be 

false

.

8.  If 

flags

 contains 

"y"

, let 

newFlags

 be 

flags

.

9.  Else, let 

newFlags

 be the 

string-concatenation

 of 

flags

 and 

"y"

.

10.  Let 

splitter

 be ? 

Construct

(

C

, « 

rx

newFlags

 »).

11.  Let 

A

 be ! 

ArrayCreate

(0).

12.  Let 

lengthA

 be 0.

13.  If 

limit

 is 

undefined

, let 

lim

 be 2

32

 - 1; else let 

lim

ToUint32

(

limit

)).

14.  If 

lim

 is 0, return 

A

.

15.  Let 

size

 be the length of 

S

.

Returns an Array object into which substrings of the result of converting 

string

 to a String have

been stored. The substrings are determined by searching from left to right for matches of the 

this

value regular expression; these occurrences are not part of any String in the returned array, but
serve to divide up the String value.

The 

this

 value may be an empty regular expression or a regular expression that can match an

empty String. In this case, the regular expression does not match the empty substring at the
beginning or end of the input String, nor does it match the empty substring at the end of the
previous separator match. (For example, if the regular expression matches the empty String, the
String is split up into individual code unit elements; the length of the result array equals the
length of the String, and each substring contains one code unit.) Only the first match at a given
index of the String is considered, even if backtracking could yield a non-empty substring match
at that index. (For example, 

/a*?/[Symbol.split]("ab")

/a*?/[Symbol.split]("ab")

 evaluates to the array

["a", "b"]

["a", "b"]

, while 

/a*/[Symbol.split]("ab")

/a*/[Symbol.split]("ab")

 evaluates to the array 

["","b"]

["","b"]

.)

If 

string

 is (or converts to) the empty String, the result depends on whether the regular expression

can match the empty String. If it can, the result array contains no elements. Otherwise, the result
array contains one element, which is the empty String.

If the regular expression contains capturing parentheses, then each time 

separator

 is matched the

results (including any 

undefined

 results) of the capturing parentheses are spliced into the output

array. For example,

evaluates to the array

If 

limit

 is not 

undefined

, then the output array is truncated so that it contains no more than 

limit

elements.

/<(\/)?([^<>]+)>/[Symbol.split]("A<

B

>bold</

B

>

and

<

CODE

>coded</

CODE

>")

[

"A"

undefined

"B"

"bold"

"/"

"B"

"and"

undefined

"CODE"

"coded"

629

16.  If 

size

 is 0, then

a.  Let 

z

 be ? 

RegExpExec

(

splitter

S

).

b.  If 

z

 is not 

null

, return 

A

.

c.  Perform ! 

CreateDataPropertyOrThrow

(

A

"0"

S

).

d.  Return 

A

.

17.  Let 

p

 be 0.

18.  Let 

q

 be 

p

.

19.  Repeat, while 

q

 < 

size

,

a.  Perform ? 

Set

(

splitter

"lastIndex"

q

), 

true

).

b.  Let 

z

 be ? 

RegExpExec

(

splitter

S

).

c.  If 

z

 is 

null

, set 

q

 to 

AdvanceStringIndex

(

S

q

unicodeMatching

).

d.  Else,

i.  Let 

e

 be 

(? 

ToLength

(? 

Get

(

splitter

"lastIndex"

))).

ii.  Set 

e

 to 

min

(

e

size

).

iii.  If 

e

 = 

p

, set 

q

 to 

AdvanceStringIndex

(

S

q

unicodeMatching

).

iv.  Else,

1.  Let 

T

 be the 

substring

 of 

S

 from 

p

 to 

q

.

2.  Perform ! 

CreateDataPropertyOrThrow

(

A

, ! 

ToString

(

lengthA

)), 

T

).

3.  Set 

lengthA

 to 

lengthA

 + 1.

4.  If 

lengthA

 = 

lim

, return 

A

.

5.  Set 

p

 to 

e

.

6.  Let 

numberOfCaptures

 be ? 

LengthOfArrayLike

(

z

).

7.  Set 

numberOfCaptures

 to 

max

(

numberOfCaptures

 - 1, 0).

8.  Let 

i

 be 1.

9.  Repeat, while 

i

 

 

numberOfCaptures

,

a.  Let 

nextCapture

 be ? 

Get

(

z

, ! 

ToString

(

i

))).

b.  Perform ! 

CreateDataPropertyOrThrow

(

A

, ! 

ToString

(

lengthA

)), 

nextCapture

).

c.  Set 

i

 to 

i

 + 1.

d.  Set 

lengthA

 to 

lengthA

 + 1.

e.  If 

lengthA

 = 

lim

, return 

A

.

10.  Set 

q

 to 

p

.

20.  Let 

T

 be the 

substring

 of 

S

 from 

p

 to 

size

.

21.  Perform ! 

CreateDataPropertyOrThrow

(

A

, ! 

ToString

(

lengthA

)), 

T

).

22.  Return 

A

.

The value of the 

"name"

 property of this function is 

"[Symbol.split]"

.

NOTE 2

RegExp.prototype.sticky

RegExp.prototype.sticky

 is an 

accessor property

 whose set accessor function is 

undefined

. Its get accessor

function performs the following steps:

1.  Let 

R

 be the 

this

 value.

2.  If 

Type

(

R

) is not Object, throw a 

TypeError

 exception.

3.  If 

R

 does not have an [[OriginalFlags]] internal slot, then

The 

@@split

@@split

 method ignores the value of the 

"global"

 and 

"sticky"

 properties of this RegExp

object.

22.2.5.14  get RegExp.prototype.sticky

630

a.  If 

SameValue

(

R

%RegExp.prototype%

) is 

true

, return 

undefined

.

b.  Otherwise, throw a 

TypeError

 exception.

4.  Let 

flags

 be 

R

.[[OriginalFlags]].

5.  If 

flags

 contains the code unit 0x0079 (LATIN SMALL LETTER Y), return 

true

.

6.  Return 

false

.

The following steps are taken:

1.  Let 

R

 be the 

this

 value.

2.  If 

Type

(

R

) is not Object, throw a 

TypeError

 exception.

3.  Let 

string

 be ? 

ToString

(

S

).

4.  Let 

match

 be ? 

RegExpExec

(

R

string

).

5.  If 

match

 is not 

null

, return 

true

; else return 

false

.

1.  Let 

R

 be the 

this

 value.

2.  If 

Type

(

R

) is not Object, throw a 

TypeError

 exception.

3.  Let 

pattern

 be ? 

ToString

(? 

Get

(

R

"source"

)).

4.  Let 

flags

 be ? 

ToString

(? 

Get

(

R

"flags"

)).

5.  Let 

result

 be the 

string-concatenation

 of 

"/"

pattern

"/"

, and 

flags

.

6.  Return 

result

.

NOTE

RegExp.prototype.unicode

RegExp.prototype.unicode

 is an 

accessor property

 whose set accessor function is 

undefined

. Its get accessor

function performs the following steps:

1.  Let 

R

 be the 

this

 value.

2.  If 

Type

(

R

) is not Object, throw a 

TypeError

 exception.

3.  If 

R

 does not have an [[OriginalFlags]] internal slot, then

a.  If 

SameValue

(

R

%RegExp.prototype%

) is 

true

, return 

undefined

.

b.  Otherwise, throw a 

TypeError

 exception.

4.  Let 

flags

 be 

R

.[[OriginalFlags]].

5.  If 

flags

 contains the code unit 0x0075 (LATIN SMALL LETTER U), return 

true

.

6.  Return 

false

.

RegExp instances are ordinary objects that inherit properties from the 

RegExp prototype object

. RegExp instances

have internal slots [[RegExpMatcher]], [[OriginalSource]], and [[OriginalFlags]]. The value of the [[RegExpMatcher]]
internal slot is an 

Abstract Closure

 representation of the 

Pattern

 of the RegExp object.

The returned String has the form of a 

RegularExpressionLiteral

 that evaluates to another RegExp

object with the same behaviour as this object.

22.2.5.15  RegExp.prototype.test ( 

S

 )

22.2.5.16  RegExp.prototype.toString ( )

22.2.5.17  get RegExp.prototype.unicode

22.2.6  Properties of RegExp Instances

631

NOTE

RegExp instances also have the following property:

The value of the 

"lastIndex"

 property specifies the String index at which to start the next match. It is coerced to an

integral Number

 when used (see 

22.2.5.2.2

). This property shall have the attributes { [[Writable]]: 

true

, [[Enumerable]]:

false

, [[Configurable]]: 

false

 }.

A RegExp String Iterator is an object, that represents a specific iteration over some specific String instance object,
matching against some specific RegExp instance object. There is not a named 

constructor

 for RegExp String Iterator

objects. Instead, RegExp String Iterator objects are created by calling certain methods of RegExp instance objects.

The abstract operation CreateRegExpStringIterator takes arguments 

R

S

global

, and 

fullUnicode

. It performs the

following steps when called:

1. 

Assert

Type

(

S

) is String.

2. 

Assert

Type

(

global

) is Boolean.

3. 

Assert

Type

(

fullUnicode

) is Boolean.

4.  Let 

closure

 be a new 

Abstract Closure

 with no parameters that captures 

R

S

global

, and 

fullUnicode

 and

performs the following steps when called:

a.  Repeat,

i.  Let 

match

 be ? 

RegExpExec

(

R

S

).

ii.  If 

match

 is 

null

, return 

undefined

.

iii.  If 

global

 is 

false

, then

1.  Perform ? 

Yield

(

match

).

2.  Return 

undefined

.

iv.  Let 

matchStr

 be ? 

ToString

(? 

Get

(

match

"0"

)).

v.  If 

matchStr

 is the empty String, then

1.  Let 

thisIndex

 be 

(? 

ToLength

(? 

Get

(

R

"lastIndex"

))).

2.  Let 

nextIndex

 be ! 

AdvanceStringIndex

(

S

thisIndex

fullUnicode

).

3.  Perform ? 

Set

(

R

"lastIndex"

(

nextIndex

), 

true

).

vi.  Perform ? 

Yield

(

match

).

5.  Return ! 

CreateIteratorFromClosure

(

closure

"%RegExpStringIteratorPrototype%"

,

%RegExpStringIteratorPrototype%

).

The 

%RegExpStringIteratorPrototype%

 object:

has properties that are inherited by all RegExp String Iterator Objects.

Prior to ECMAScript 2015, RegExp instances were specified as having the own data properties

"source"

"global"

"ignoreCase"

, and 

"multiline"

. Those properties are now specified as accessor

properties of 

RegExp.prototype

RegExp.prototype

.

22.2.6.1  lastIndex

22.2.7  RegExp String Iterator Objects

22.2.7.1  CreateRegExpStringIterator ( 

R

S

global

fullUnicode

 )

22.2.7.2  The %RegExpStringIteratorPrototype% Object

632

is an 

ordinary object

.

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

%IteratorPrototype%

.

has the following properties:

1.  Return ? 

GeneratorResume

(

this

 value, 

empty

"%RegExpStringIteratorPrototype%"

).

The initial value of the 

@@toStringTag

 property is the String value 

"RegExp String Iterator"

.

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

false

, [[Enumerable]]: 

false

, [[Configurable]]: 

true

 }.

Array objects are exotic objects that give special treatment to a certain class of property names. See 

10.4.2

 for a

definition of this special treatment.

The Array 

constructor

:

is 

%Array%

.

is the initial value of the 

"Array"

 property of the 

global object

.

creates and initializes a new 

Array exotic object

 when called as a 

constructor

.

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

constructor

. Thus the

function call 

Array(…)

Array(…)

 is equivalent to the object creation expression 

new Array(…)

new Array(…)

 with the same

arguments.
is a function whose behaviour differs based upon the number and types of its 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 exotic Array behaviour must include a 

super

super

 call to the Array

constructor

 to initialize subclass instances that are Array exotic objects. However, most of the

Array.prototype

Array.prototype

 methods are generic methods that are not dependent upon their 

this

 value being an

Array exotic object

.

has a 

"length"

 property whose value is 

1

𝔽

.

When the 

Array

Array

 function is called, the following steps are taken:

1.  If NewTarget is 

undefined

, let 

newTarget

 be the 

active function object

; else let 

newTarget

 be NewTarget.

2.  Let 

proto

 be ? 

GetPrototypeFromConstructor

(

newTarget

"%Array.prototype%"

).

3.  Let 

numberOfArgs

 be the number of elements in 

values

.

22.2.7.2.1  %RegExpStringIteratorPrototype%.next ( )

22.2.7.2.2  %RegExpStringIteratorPrototype% [ @@toStringTag ]

23  Indexed Collections

23.1  Array Objects

23.1.1  The Array Constructor

23.1.1.1  Array ( ...

values

 )

633

4.  If 

numberOfArgs

 = 0, then

a.  Return ! 

ArrayCreate

(0, 

proto

).

5.  Else if 

numberOfArgs

 = 1, then

a.  Let 

len

 be 

values

[0].

b.  Let 

array

 be ! 

ArrayCreate

(0, 

proto

).

c.  If 

Type

(

len

) is not Number, then

i.  Perform ! 

CreateDataPropertyOrThrow

(

array

"0"

len

).

ii.  Let 

intLen

 be 

1

𝔽

.

d.  Else,

i.  Let 

intLen

 be ! 

ToUint32

(

len

).

ii.  If 

intLen

 is not the same value as 

len

, throw a 

RangeError

 exception.

e.  Perform ! 

Set

(

array

"length"

intLen

true

).

f.  Return 

array

.

6.  Else,

a. 

Assert

numberOfArgs

 

 2.

b.  Let 

array

 be ? 

ArrayCreate

(

numberOfArgs

proto

).

c.  Let 

k

 be 0.

d.  Repeat, while 

k

 < 

numberOfArgs

,

i.  Let 

Pk

 be ! 

ToString

(

(

k

)).

ii.  Let 

itemK

 be 

values

[

k

].

iii.  Perform ! 

CreateDataPropertyOrThrow

(

array

Pk

itemK

).

iv.  Set 

k

 to 

k

 + 1.

e. 

Assert

: The 

mathematical value

 of 

array

's 

"length"

 property is 

numberOfArgs

.

f.  Return 

array

.

The Array 

constructor

:

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

%Function.prototype%

.

has the following properties:

When the 

from

from

 method is called with argument 

items

 and optional arguments 

mapfn

 and 

thisArg

, the following steps

are taken:

1.  Let 

C

 be the 

this

 value.

2.  If 

mapfn

 is 

undefined

, let 

mapping

 be 

false

.

3.  Else,

a.  If 

IsCallable

(

mapfn

) is 

false

, throw a 

TypeError

 exception.

b.  Let 

mapping

 be 

true

.

4.  Let 

usingIterator

 be ? 

GetMethod

(

items

@@iterator

).

5.  If 

usingIterator

 is not 

undefined

, then

a.  If 

IsConstructor

(

C

) is 

true

, then

i.  Let 

A

 be ? 

Construct

(

C

).

b.  Else,

i.  Let 

A

 be ! 

ArrayCreate

(0).

23.1.2  Properties of the Array Constructor

23.1.2.1  Array.from ( 

items

 [ , 

mapfn

 [ , 

thisArg

 ] ] )

634

c.  Let 

iteratorRecord

 be ? 

GetIterator

(

items

sync

usingIterator

).

d.  Let 

k

 be 0.

e.  Repeat,

i.  If 

k

 

 2

53

 - 1, then

1.  Let 

error

 be 

ThrowCompletion

(a newly created 

TypeError

 object).

2.  Return ? 

IteratorClose

(

iteratorRecord

error

).

ii.  Let 

Pk

 be ! 

ToString

(

(

k

)).

iii.  Let 

next

 be ? 

IteratorStep

(

iteratorRecord

).

iv.  If 

next

 is 

false

, then

1.  Perform ? 

Set

(

A

"length"

(

k

), 

true

).

2.  Return 

A

.

v.  Let 

nextValue

 be ? 

IteratorValue

(

next

).

vi.  If 

mapping

 is 

true

, then

1.  Let 

mappedValue

 be 

Call

(

mapfn

thisArg

, « 

nextValue

(

k

) »).

2.  If 

mappedValue

 is an 

abrupt completion

, return ? 

IteratorClose

(

iteratorRecord

mappedValue

).

3.  Set 

mappedValue

 to 

mappedValue

.[[Value]].

vii.  Else, let 

mappedValue

 be 

nextValue

.

viii.  Let 

defineStatus

 be 

CreateDataPropertyOrThrow

(

A

Pk

mappedValue

).

ix.  If 

defineStatus

 is an 

abrupt completion

, return ? 

IteratorClose

(

iteratorRecord

defineStatus

).

x.  Set 

k

 to 

k

 + 1.

6.  NOTE: 

items

 is not an Iterable so assume it is an 

array-like object

.

7.  Let 

arrayLike

 be ! 

ToObject

(

items

).

8.  Let 

len

 be ? 

LengthOfArrayLike

(

arrayLike

).

9.  If 

IsConstructor

(

C

) is 

true

, then

a.  Let 

A

 be ? 

Construct

(

C

, « 

(

len

) »).

10.  Else,

a.  Let 

A

 be ? 

ArrayCreate

(

len

).

11.  Let 

k

 be 0.

12.  Repeat, while 

k

 < 

len

,

a.  Let 

Pk

 be ! 

ToString

(

(

k

)).

b.  Let 

kValue

 be ? 

Get

(

arrayLike

Pk

).

c.  If 

mapping

 is 

true

, then

i.  Let 

mappedValue

 be ? 

Call

(

mapfn

thisArg

, « 

kValue

(

k

) »).

d.  Else, let 

mappedValue

 be 

kValue

.

e.  Perform ? 

CreateDataPropertyOrThrow

(

A

Pk

mappedValue

).

f.  Set 

k

 to 

k

 + 1.

13.  Perform ? 

Set

(

A

"length"

(

len

), 

true

).

14.  Return 

A

.

NOTE

The 

isArray

isArray

 function takes one argument 

arg

, and performs the following steps:

The 

from

from

 function is an intentionally generic factory method; it does not require that its 

this

value be the Array 

constructor

. Therefore it can be transferred to or inherited by any other

constructors that may be called with a single numeric argument.

23.1.2.2  Array.isArray ( 

arg

 )

635

1.  Return ? 

IsArray

(

arg

).

When the 

of

of

 method is called with any number of arguments, the following steps are taken:

1.  Let 

len

 be the number of elements in 

items

.

2.  Let 

lenNumber

len

).

3.  Let 

C

 be the 

this

 value.

4.  If 

IsConstructor

(

C

) is 

true

, then

a.  Let 

A

 be ? 

Construct

(

C

, « 

lenNumber

 »).

5.  Else,

a.  Let 

A

 be ? 

ArrayCreate

(

len

).

6.  Let 

k

 be 0.

7.  Repeat, while 

k

 < 

len

,

a.  Let 

kValue

 be 

items

[

k

].

b.  Let 

Pk

 be ! 

ToString

(

(

k

)).

c.  Perform ? 

CreateDataPropertyOrThrow

(

A

Pk

kValue

).

d.  Set 

k

 to 

k

 + 1.

8.  Perform ? 

Set

(

A

"length"

lenNumber

true

).

9.  Return 

A

.

NOTE

The value of 

Array.prototype

Array.prototype

 is the 

Array prototype object

.

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

false

, [[Enumerable]]: 

false

, [[Configurable]]: 

false

 }.

Array[@@species]

Array[@@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 

of

of

 function is an intentionally generic factory method; it does not require that its 

this

 value

be the Array 

constructor

. Therefore it can be transferred to or inherited by other constructors that

may be called with a single numeric argument.

Array 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.

23.1.2.3  Array.of ( ...

items

 )

23.1.2.4  Array.prototype

23.1.2.5  get Array [ @@species ]

23.1.3  Properties of the Array Prototype Object

636

 

 

 

 

 

 

 

Content      ..     30      31      32      33     ..