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

 

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

 

Search            copyright infringement  

 

 

 

 

 

 

 

 

 

 

 

Content      ..     49      50      51      52     ..

 

 

 

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

 

 

NOTE 1

When the 

codePointAt

codePointAt

 method is called with one argument 

pos

, the following steps are taken:

1.  Let 

O

 be ? 

RequireObjectCoercible

(

this

 value).

2.  Let 

S

 be ? 

ToString

(

O

).

3.  Let 

position

 be ? 

ToIntegerOrInfinity

(

pos

).

4.  Let 

size

 be the length of 

S

.

5.  If 

position

 < 0 or 

position

 

 

size

, return 

undefined

.

6.  Let 

cp

 be ! 

CodePointAt

(

S

position

).

7.  Return 

cp

.[[CodePoint]]).

NOTE 2

NOTE 1

When the 

concat

concat

 method is called with zero or more arguments, the following steps are taken:

1.  Let 

O

 be ? 

RequireObjectCoercible

(

this

 value).

2.  Let 

S

 be ? 

ToString

(

O

).

3.  Let 

R

 be 

S

.

4.  For each element 

next

 of 

args

, do

a.  Let 

nextString

 be ? 

ToString

(

next

).

b.  Set 

R

 to the 

string-concatenation

 of 

R

 and 

nextString

.

5.  Return 

R

.

The 

"length"

 property of the 

concat

concat

 method is 

1

𝔽

.

NOTE 2

The initial value of 

String.prototype.constructor

String.prototype.constructor

 is 

%String%

.

Returns a non-negative 

integral Number

 less than or equal to 

0x10FFFF

𝔽

 that is the code point

value of the UTF-16 encoded code point (

6.1.4

) starting at the string element at index 

pos

 within

the String resulting from converting this object to a String. If there is no element at that index, the
result is 

undefined

. If a valid UTF-16 

surrogate pair

 does not begin at 

pos

, the result is the code

unit at 

pos

.

The 

codePointAt

codePointAt

 function is intentionally generic; it does not require that its 

this

 value be a

String object. Therefore it can be transferred to other kinds of objects for use as a method.

When the 

concat

concat

 method is called it returns the String value consisting of the code units of the

this

 value (converted to a String) followed by the code units of each of the arguments converted

to a String. The result is a String value, not a String object.

The 

concat

concat

 function is intentionally generic; it does not require that its 

this

 value be a String

object. Therefore it can be transferred to other kinds of objects for use as a method.

22.1.3.4  String.prototype.concat ( ...

args

 )

22.1.3.5  String.prototype.constructor

22.1.3.6  String.prototype.endsWith ( 

searchString

 [ , 

endPosition

 ] )

557

The following steps are taken:

1.  Let 

O

 be ? 

RequireObjectCoercible

(

this

 value).

2.  Let 

S

 be ? 

ToString

(

O

).

3.  Let 

isRegExp

 be ? 

IsRegExp

(

searchString

).

4.  If 

isRegExp

 is 

true

, throw a 

TypeError

 exception.

5.  Let 

searchStr

 be ? 

ToString

(

searchString

).

6.  Let 

len

 be the length of 

S

.

7.  If 

endPosition

 is 

undefined

, let 

pos

 be 

len

; else let 

pos

 be ? 

ToIntegerOrInfinity

(

endPosition

).

8.  Let 

end

 be the result of 

clamping

 

pos

 between 0 and 

len

.

9.  Let 

searchLength

 be the length of 

searchStr

.

10.  If 

searchLength

 = 0, return 

true

.

11.  Let 

start

 be 

end

 - 

searchLength

.

12.  If 

start

 < 0, return 

false

.

13.  Let 

substring

 be the 

substring

 of 

S

 from 

start

 to 

end

.

14.  Return ! 

SameValueNonNumeric

(

substring

searchStr

).

NOTE 1

NOTE 2

NOTE 3

The 

includes

includes

 method takes two arguments, 

searchString

 and 

position

, and performs the following steps:

1.  Let 

O

 be ? 

RequireObjectCoercible

(

this

 value).

2.  Let 

S

 be ? 

ToString

(

O

).

3.  Let 

isRegExp

 be ? 

IsRegExp

(

searchString

).

4.  If 

isRegExp

 is 

true

, throw a 

TypeError

 exception.

5.  Let 

searchStr

 be ? 

ToString

(

searchString

).

6.  Let 

pos

 be ? 

ToIntegerOrInfinity

(

position

).

7. 

Assert

: If 

position

 is 

undefined

, then 

pos

 is 0.

8.  Let 

len

 be the length of 

S

.

9.  Let 

start

 be the result of 

clamping

 

pos

 between 0 and 

len

.

10.  Let 

index

 be ! 

StringIndexOf

(

S

searchStr

start

).

11.  If 

index

 is not -1, return 

true

.

12.  Return 

false

.

Returns 

true

 if the sequence of code units of 

searchString

 converted to a String is the same as the

corresponding code units of this object (converted to a String) starting at 

endPosition

 -

length(this). Otherwise returns 

false

.

Throwing an exception if the first argument is a RegExp is specified in order to allow future
editions to define extensions that allow such argument values.

The 

endsWith

endsWith

 function is intentionally generic; it does not require that its 

this

 value be a String

object. Therefore, it can be transferred to other kinds of objects for use as a method.

22.1.3.7  String.prototype.includes ( 

searchString

 [ , 

position

 ] )

558

NOTE 1

NOTE 2

NOTE 3

NOTE 1

The 

indexOf

indexOf

 method takes two arguments, 

searchString

 and 

position

, and performs the following steps:

1.  Let 

O

 be ? 

RequireObjectCoercible

(

this

 value).

2.  Let 

S

 be ? 

ToString

(

O

).

3.  Let 

searchStr

 be ? 

ToString

(

searchString

).

4.  Let 

pos

 be ? 

ToIntegerOrInfinity

(

position

).

5. 

Assert

: If 

position

 is 

undefined

, then 

pos

 is 0.

6.  Let 

len

 be the length of 

S

.

7.  Let 

start

 be the result of 

clamping

 

pos

 between 0 and 

len

.

8.  Return 

StringIndexOf

(

S

searchStr

start

)).

NOTE 2

NOTE 1

The 

lastIndexOf

lastIndexOf

 method takes two arguments, 

searchString

 and 

position

, and performs the following steps:

1.  Let 

O

 be ? 

RequireObjectCoercible

(

this

 value).

2.  Let 

S

 be ? 

ToString

(

O

).

3.  Let 

searchStr

 be ? 

ToString

(

searchString

).

4.  Let 

numPos

 be ? 

ToNumber

(

position

).

5. 

Assert

: If 

position

 is 

undefined

, then 

numPos

 is 

NaN

.

If 

searchString

 appears as a substring of the result of converting this object to a String, at one or

more indices that are greater than or equal to 

position

, return 

true

; otherwise, returns 

false

. If

position

 is 

undefined

, 0 is assumed, so as to search all of the String.

Throwing an exception if the first argument is a RegExp is specified in order to allow future
editions to define extensions that allow such argument values.

The 

includes

includes

 function is intentionally generic; it does not require that its 

this

 value be a String

object. Therefore, it can be transferred to other kinds of objects for use as a method.

If 

searchString

 appears as a substring of the result of converting this object to a String, at one or

more indices that are greater than or equal to 

position

, then the smallest such index is returned;

otherwise, 

-1

𝔽

 is returned. If 

position

 is 

undefined

+0

𝔽

 is assumed, so as to search all of the String.

The 

indexOf

indexOf

 function is intentionally generic; it does not require that its 

this

 value be a String

object. Therefore, it can be transferred to other kinds of objects for use as a method.

If 

searchString

 appears as a substring of the result of converting this object to a String at one or

more indices that are smaller than or equal to 

position

, then the greatest such index is returned;

otherwise, 

-1

𝔽

 is returned. If 

position

 is 

undefined

, the length of the String value is assumed, so as

to search all of the String.

22.1.3.8  String.prototype.indexOf ( 

searchString

 [ , 

position

 ] )

22.1.3.9  String.prototype.lastIndexOf ( 

searchString

 [ , 

position

 ] )

559

6.  If 

numPos

 is 

NaN

, let 

pos

 be +

; otherwise, let 

pos

 be ! 

ToIntegerOrInfinity

(

numPos

).

7.  Let 

len

 be the length of 

S

.

8.  Let 

start

 be the result of 

clamping

 

pos

 between 0 and 

len

.

9.  Let 

searchLen

 be the length of 

searchStr

.

10.  Let 

k

 be the largest possible non-negative 

integer

 not larger than 

start

 such that 

k

 + 

searchLen

 

 

len

, and for all

non-negative integers 

j

 such that 

j

 < 

searchLen

, the code unit at index 

k

 + 

j

 within 

S

 is the same as the code unit

at index 

j

 within 

searchStr

; but if there is no such 

integer

, let 

k

 be -1.

11.  Return 

k

).

NOTE 2

An ECMAScript implementation that includes the ECMA-402 Internationalization API must implement the

localeCompare

localeCompare

 method as specified in the ECMA-402 specification. If an ECMAScript implementation does not

include the ECMA-402 API the following specification of the 

localeCompare

localeCompare

 method is used.

When the 

localeCompare

localeCompare

 method is called with argument 

that

, it returns a Number other than 

NaN

 that

represents the result of a locale-sensitive String comparison of the 

this

 value (converted to a String) with 

that

(converted to a String). The two Strings are 

S

 and 

That

. The two Strings are compared in an 

implementation-defined

fashion. The result is intended to order String values in the sort order specified by a 

host

 default locale, and will be

negative, zero, or positive, depending on whether 

S

 comes before 

That

 in the sort order, the Strings are equal, or 

S

comes after 

That

 in the sort order, respectively.

Before performing the comparisons, the following steps are performed to prepare the Strings:

1.  Let 

O

 be ? 

RequireObjectCoercible

(

this

 value).

2.  Let 

S

 be ? 

ToString

(

O

).

3.  Let 

That

 be ? 

ToString

(

that

).

The meaning of the optional second and third parameters to this method are defined in the ECMA-402 specification;
implementations that do not include ECMA-402 support must not assign any other interpretation to those parameter
positions.

The 

localeCompare

localeCompare

 method, if considered as a function of two arguments 

this

 and 

that

, is a consistent

comparison function (as defined in 

23.1.3.27

) on the set of all Strings.

The actual return values ar

implementation-defined

 to permit implementers to encode additional information in the

value, but the function is required to define a total ordering on all Strings. This function must treat Strings that are
canonically equivalent according to the Unicode standard as identical and must return 

00

 when comparing Strings that

are considered canonically equivalent.

NOTE 1

The 

lastIndexOf

lastIndexOf

 function is intentionally generic; it does not require that its 

this

 value be a

String object. Therefore, it can be transferred to other kinds of objects for use as a method.

The 

localeCompare

localeCompare

 method itself is not directly suitable as an argument to

Array.prototype.sort

Array.prototype.sort

 because the latter requires a function of two arguments.

22.1.3.10  String.prototype.localeCompare ( 

that

 [ , 

reserved1

 [ , 

reserved2

 ] ] )

560

NOTE 2

NOTE 3

When the 

match

match

 method is called with argument 

regexp

, the following steps are taken:

1.  Let 

O

 be ? 

RequireObjectCoercible

(

this

 value).

2.  If 

regexp

 is neither 

undefined

 nor 

null

, then

a.  Let 

matcher

 be ? 

GetMethod

(

regexp

@@match

).

b.  If 

matcher

 is not 

undefined

, then

i.  Return ? 

Call

(

matcher

regexp

, « 

O

 »).

3.  Let 

S

 be ? 

ToString

(

O

).

4.  Let 

rx

 be ? 

RegExpCreate

(

regexp

undefined

).

5.  Return ? 

Invoke

(

rx

@@match

, « 

S

 »).

NOTE

Performs a regular expression match of the String representing the 

this

 value against 

regexp

 and returns an iterator.

Each iteration result's value is an Array object containing the results of the match, or 

null

 if the String did not match.

When the 

matchAll

matchAll

 method is called, the following steps are taken:

1.  Let 

O

 be ? 

RequireObjectCoercible

(

this

 value).

2.  If 

regexp

 is neither 

undefined

 nor 

null

, then

a.  Let 

isRegExp

 be ? 

IsRegExp

(

regexp

).

b.  If 

isRegExp

 is 

true

, then

i.  Let 

flags

 be ? 

Get

(

regexp

"flags"

).

ii.  Perform ? 

RequireObjectCoercible

(

flags

).

iii.  If ? 

ToString

(

flags

) does not contain 

"g"

, throw a 

TypeError

 exception.

c.  Let 

matcher

 be ? 

GetMethod

(

regexp

@@matchAll

).

This function is intended to rely on whatever language-sensitive comparison functionality is
available to the ECMAScript environment from the 

host environment

, and to compare according

to the rules of the 

host environment

's current locale. However, regardless of the 

host

 provided

comparison capabilities, this function must treat Strings that are canonically equivalent according
to the Unicode standard as identical. It is recommended that this function should not honour
Unicode compatibility equivalences or decompositions. For a definition and discussion of
canonical equivalence see the Unicode Standard, chapters 2 and 3, as well as Unicode Standard
Annex #15, Unicode Normalization Forms (

https://unicode.org/reports/tr15/

) and Unicode

Technical Note #5, Canonical Equivalence in Applications
(

https://www.unicode.org/notes/tn5/

). Also see Unicode Technical Standard #10, Unicode

Collation Algorithm (

https://unicode.org/reports/tr10/

).

The 

localeCompare

localeCompare

 function is intentionally generic; it does not require that its 

this

 value be

a String object. Therefore, it can be transferred to other kinds of objects for use as a method.

The 

match

match

 function is intentionally generic; it does not require that its 

this

 value be a String

object. Therefore, it can be transferred to other kinds of objects for use as a method.

22.1.3.11  String.prototype.match ( 

regexp

 )

22.1.3.12  String.prototype.matchAll ( 

regexp

 )

561

d.  If 

matcher

 is not 

undefined

, then

i.  Return ? 

Call

(

matcher

regexp

, « 

O

 »).

3.  Let 

S

 be ? 

ToString

(

O

).

4.  Let 

rx

 be ? 

RegExpCreate

(

regexp

"g"

).

5.  Return ? 

Invoke

(

rx

@@matchAll

, « 

S

 »).

NOTE 1

NOTE 2

When the 

normalize

normalize

 method is called with one argument 

form

, the following steps are taken:

1.  Let 

O

 be ? 

RequireObjectCoercible

(

this

 value).

2.  Let 

S

 be ? 

ToString

(

O

).

3.  If 

form

 is 

undefined

, let 

f

 be 

"NFC"

.

4.  Else, let 

f

 be ? 

ToString

(

form

).

5.  If 

f

 is not one of 

"NFC"

"NFD"

"NFKC"

, or 

"NFKD"

, throw a 

RangeError

 exception.

6.  Let 

ns

 be the String value that is the result of normalizing 

S

 into the normalization form named by 

f

 as specified

in 

https://unicode.org/reports/tr15/

.

7.  Return 

ns

.

NOTE

When the 

padEnd

padEnd

 method is called, the following steps are taken:

1.  Let 

O

 be ? 

RequireObjectCoercible

(

this

 value).

2.  Return ? 

StringPad

(

O

maxLength

fillString

end

).

When the 

padStart

padStart

 method is called, the following steps are taken:

1.  Let 

O

 be ? 

RequireObjectCoercible

(

this

 value).

2.  Return ? 

StringPad

(

O

maxLength

fillString

start

).

The abstract operation StringPad takes arguments 

O

maxLength

fillString

, and 

placement

. It performs the following

steps when called:

The 

matchAll

matchAll

 function is intentionally generic, it does not require that its 

this

 value be a String

object. Therefore, it can be transferred to other kinds of objects for use as a method.

Similarly to 

String.prototype.split

String.prototype.split

String.prototype.matchAll

String.prototype.matchAll

 is designed

to typically act without mutating its inputs.

The 

normalize

normalize

 function is intentionally generic; it does not require that its 

this

 value be a

String object. Therefore it can be transferred to other kinds of objects for use as a method.

22.1.3.13  String.prototype.normalize ( [ 

form

 ] )

22.1.3.14  String.prototype.padEnd ( 

maxLength

 [ , 

fillString

 ] )

22.1.3.15  String.prototype.padStart ( 

maxLength

 [ , 

fillString

 ] )

22.1.3.15.1  StringPad ( 

O

maxLength

fillString

placement

 )

562

1. 

Assert

placement

 is 

start

 or 

end

.

2.  Let 

S

 be ? 

ToString

(

O

).

3.  Let 

intMaxLength

 be 

(? 

ToLength

(

maxLength

)).

4.  Let 

stringLength

 be the length of 

S

.

5.  If 

intMaxLength

 

 

stringLength

, return 

S

.

6.  If 

fillString

 is 

undefined

, let 

filler

 be the String value consisting solely of the code unit 0x0020 (SPACE).

7.  Else, let 

filler

 be ? 

ToString

(

fillString

).

8.  If 

filler

 is the empty String, return 

S

.

9.  Let 

fillLen

 be 

intMaxLength

 - 

stringLength

.

10.  Let 

truncatedStringFiller

 be the String value consisting of repeated concatenations of 

filler

 truncated to length

fillLen

.

11.  If 

placement

 is 

start

, return the 

string-concatenation

 of 

truncatedStringFiller

 and 

S

.

12.  Else, return the 

string-concatenation

 of 

S

 and 

truncatedStringFiller

.

NOTE 1

NOTE 2

The following steps are taken:

1.  Let 

O

 be ? 

RequireObjectCoercible

(

this

 value).

2.  Let 

S

 be ? 

ToString

(

O

).

3.  Let 

n

 be ? 

ToIntegerOrInfinity

(

count

).

4.  If 

n

 < 0 or 

n

 is +

, throw a 

RangeError

 exception.

5.  If 

n

 is 0, return the empty String.

6.  Return the String value that is made from 

n

 copies of 

S

 appended together.

NOTE 1

NOTE 2

When the 

replace

replace

 method is called with arguments 

searchValue

 and 

replaceValue

, the following steps are taken:

1.  Let 

O

 be ? 

RequireObjectCoercible

(

this

 value).

2.  If 

searchValue

 is neither 

undefined

 nor 

null

, then

a.  Let 

replacer

 be ? 

GetMethod

(

searchValue

@@replace

).

b.  If 

replacer

 is not 

undefined

, then

i.  Return ? 

Call

(

replacer

searchValue

, « 

O

replaceValue

 »).

The argument 

maxLength

 will be clamped such that it can be no smaller than the length of 

S

.

The argument 

fillString

 defaults to 

" "

 (the String value consisting of the code unit 0x0020

SPACE).

This method creates the String value consisting of the code units of the 

this

 value (converted to

String) repeated 

count

 times.

The 

repeat

repeat

 function is intentionally generic; it does not require that its 

this

 value be a String

object. Therefore, it can be transferred to other kinds of objects for use as a method.

22.1.3.16  String.prototype.repeat ( 

count

 )

22.1.3.17  String.prototype.replace ( 

searchValue

replaceValue

 )

563

3.  Let 

string

 be ? 

ToString

(

O

).

4.  Let 

searchString

 be ? 

ToString

(

searchValue

).

5.  Let 

functionalReplace

 be 

IsCallable

(

replaceValue

).

6.  If 

functionalReplace

 is 

false

, then

a.  Set 

replaceValue

 to ? 

ToString

(

replaceValue

).

7.  Let 

searchLength

 be the length of 

searchString

.

8.  Let 

position

 be ! 

StringIndexOf

(

string

searchString

, 0).

9.  If 

position

 is -1, return 

string

.

10.  Let 

preserved

 be the 

substring

 of 

string

 from 0 to 

position

.

11.  If 

functionalReplace

 is 

true

, then

a.  Let 

replacement

 be ? 

ToString

(? 

Call

(

replaceValue

undefined

, « 

searchString

(

position

), 

string

 »)).

12.  Else,

a. 

Assert

Type

(

replaceValue

) is String.

b.  Let 

captures

 be a new empty 

List

.

c.  Let 

replacement

 be ! 

GetSubstitution

(

searchString

string

position

captures

undefined

replaceValue

).

13.  Return the 

string-concatenation

 of 

preserved

replacement

, and the 

substring

 of 

string

 from 

position

 + 

searchLength

.

NOTE

The abstract operation GetSubstitution takes arguments 

matched

str

position

 (a non-negative 

integer

), 

captures

,

namedCaptures

, and 

replacement

. It performs the following steps when called:

1. 

Assert

Type

(

matched

) is String.

2.  Let 

matchLength

 be the number of code units in 

matched

.

3. 

Assert

Type

(

str

) is String.

4.  Let 

stringLength

 be the number of code units in 

str

.

5. 

Assert

position

 

 

stringLength

.

6. 

Assert

captures

 is a possibly empty 

List

 of Strings.

7. 

Assert

Type

(

replacement

) is String.

8.  Let 

tailPos

 be 

position

 + 

matchLength

.

9.  Let 

m

 be the number of elements in 

captures

.

10.  Let 

result

 be the String value derived from 

replacement

 by copying code unit elements from 

replacement

 to 

result

while performing replacements as specified in 

Table 54

. These 

$$

 replacements are done left-to-right, and, once

such a replacement is performed, the new replacement text is not subject to further replacements.

11.  Return 

result

.

The 

replace

replace

 function is intentionally generic; it does not require that its 

this

 value be a String

object. Therefore, it can be transferred to other kinds of objects for use as a method.

22.1.3.17.1  GetSubstitution ( 

matched

str

position

captures

namedCaptures

replacement

 )

564

Table 54: Replacement Text Symbol Substitutions

Code

units

Unicode Characters

Replacement text

0x0024,
0x0024

$$

$$

$$

0x0024,
0x0026

$&

$&

matched

0x0024,
0x0060

$`

$`

The replacement is the 

substring

 of 

str

 from 0 to 

position

.

0x0024,
0x0027

$'

$'

If 

tailPos

 

 

stringLength

, the replacement is the empty String. Otherwise the

replacement is the 

substring

 of 

str

 from 

tailPos

.

0x0024,

Where 
0x0031

 N 

0x0039

$n

$n

 where 

nn

 is one of 

1 2 3 4 5

1 2 3 4 5

6 7 8 9

6 7 8 9

 and 

$n

$n

 is not

followed by a decimal
digit

The 

n

th

 element of 

captures

, where 

n

 is a single digit in the range 1 to 9. If 

n

 

m

 and the 

n

th

 element of 

captures

 is 

undefined

, use the empty String instead.

If 

n

 > 

m

, no replacement is done.

0x0024,
N, N 
Where 
0x0030

 N 

0x0039

$nn

$nn

 where 

nn

 is one of 

0 1 2 3 4

0 1 2 3 4

5 6 7 8 9

5 6 7 8 9

The 

nn

th

 element of 

captures

, where 

nn

 is a two-digit decimal number in the

range 01 to 99. If 

nn

 

 

m

 and the 

nn

th

 element of 

captures

 is 

undefined

, use the

empty String instead. If 

nn

 is 00 or 

nn

 > 

m

, no replacement is done.

0x0024,
0x003C

$<

$<

1.  If 

namedCaptures

 is 

undefined

, the replacement text is the String 

"$<"

.

2.  Else,

a. 

Assert

Type

(

namedCaptures

) is Object.

b.  Scan until the next 

>>

 U+003E (GREATER-THAN SIGN).

c.  If none is found, the replacement text is the String 

"$<"

.

d.  Else,

i.  Let 

groupName

 be the enclosed substring.

ii.  Let 

capture

 be ? 

Get

(

namedCaptures

groupName

).

iii.  If 

capture

 is 

undefined

, replace the text through 

>>

 with

the empty String.

iv.  Otherwise, replace the text through 

>>

 with

ToString

(

capture

).

0x0024

$$

 in any context that does

not match any of the
above.

$$

565

When the 

replaceAll

replaceAll

 method is called with arguments 

searchValue

 and 

replaceValue

, the following steps are taken:

1.  Let 

O

 be ? 

RequireObjectCoercible

(

this

 value).

2.  If 

searchValue

 is neither 

undefined

 nor 

null

, then

a.  Let 

isRegExp

 be ? 

IsRegExp

(

searchValue

).

b.  If 

isRegExp

 is 

true

, then

i.  Let 

flags

 be ? 

Get

(

searchValue

"flags"

).

ii.  Perform ? 

RequireObjectCoercible

(

flags

).

iii.  If ? 

ToString

(

flags

) does not contain 

"g"

, throw a 

TypeError

 exception.

c.  Let 

replacer

 be ? 

GetMethod

(

searchValue

@@replace

).

d.  If 

replacer

 is not 

undefined

, then

i.  Return ? 

Call

(

replacer

searchValue

, « 

O

replaceValue

 »).

3.  Let 

string

 be ? 

ToString

(

O

).

4.  Let 

searchString

 be ? 

ToString

(

searchValue

).

5.  Let 

functionalReplace

 be 

IsCallable

(

replaceValue

).

6.  If 

functionalReplace

 is 

false

, then

a.  Set 

replaceValue

 to ? 

ToString

(

replaceValue

).

7.  Let 

searchLength

 be the length of 

searchString

.

8.  Let 

advanceBy

 be 

max

(1, 

searchLength

).

9.  Let 

matchPositions

 be a new empty 

List

.

10.  Let 

position

 be ! 

StringIndexOf

(

string

searchString

, 0).

11.  Repeat, while 

position

 is not -1,

a.  Append 

position

 to the end of 

matchPositions

.

b.  Set 

position

 to ! 

StringIndexOf

(

string

searchString

position

 + 

advanceBy

).

12.  Let 

endOfLastMatch

 be 0.

13.  Let 

result

 be the empty String.

14.  For each element 

p

 of 

matchPositions

, do

a.  Let 

preserved

 be the 

substring

 of 

string

 from 

endOfLastMatch

 to 

p

.

b.  If 

functionalReplace

 is 

true

, then

i.  Let 

replacement

 be ? 

ToString

(? 

Call

(

replaceValue

undefined

, « 

searchString

(

p

), 

string

 »)).

c.  Else,

i. 

Assert

Type

(

replaceValue

) is String.

ii.  Let 

captures

 be a new empty 

List

.

iii.  Let 

replacement

 be ! 

GetSubstitution

(

searchString

string

p

captures

undefined

replaceValue

).

d.  Set 

result

 to the 

string-concatenation

 of 

result

preserved

, and 

replacement

.

e.  Set 

endOfLastMatch

 to 

p

 + 

searchLength

.

15.  If 

endOfLastMatch

 < the length of 

string

, then

a.  Set 

result

 to the 

string-concatenation

 of 

result

 and the 

substring

 of 

string

 from 

endOfLastMatch

.

16.  Return 

result

.

When the 

search

search

 method is called with argument 

regexp

, the following steps are taken:

1.  Let 

O

 be ? 

RequireObjectCoercible

(

this

 value).

2.  If 

regexp

 is neither 

undefined

 nor 

null

, then

a.  Let 

searcher

 be ? 

GetMethod

(

regexp

@@search

).

22.1.3.18  String.prototype.replaceAll ( 

searchValue

replaceValue

 )

22.1.3.19  String.prototype.search ( 

regexp

 )

566

b.  If 

searcher

 is not 

undefined

, then

i.  Return ? 

Call

(

searcher

regexp

, « 

O

 »).

3.  Let 

string

 be ? 

ToString

(

O

).

4.  Let 

rx

 be ? 

RegExpCreate

(

regexp

undefined

).

5.  Return ? 

Invoke

(

rx

@@search

, « 

string

 »).

NOTE

The 

slice

slice

 method takes two arguments, 

start

 and 

end

, and returns a substring of the result of converting this object

to a String, starting from index 

start

 and running to, but not including, index 

end

 (or through the end of the String if

end

 is 

undefined

). If 

start

 is negative, it is treated as 

sourceLength

 + 

start

 where 

sourceLength

 is the length of the String.

If 

end

 is negative, it is treated as 

sourceLength

 + 

end

 where 

sourceLength

 is the length of the String. The result is a String

value, not a String object. The following steps are taken:

1.  Let 

O

 be ? 

RequireObjectCoercible

(

this

 value).

2.  Let 

S

 be ? 

ToString

(

O

).

3.  Let 

len

 be the length of 

S

.

4.  Let 

intStart

 be ? 

ToIntegerOrInfinity

(

start

).

5.  If 

intStart

 is -

, let 

from

 be 0.

6.  Else if 

intStart

 < 0, let 

from

 be 

max

(

len

 + 

intStart

, 0).

7.  Else, let 

from

 be 

min

(

intStart

len

).

8.  If 

end

 is 

undefined

, let 

intEnd

 be 

len

; else let 

intEnd

 be ? 

ToIntegerOrInfinity

(

end

).

9.  If 

intEnd

 is -

, let 

to

 be 0.

10.  Else if 

intEnd

 < 0, let 

to

 be 

max

(

len

 + 

intEnd

, 0).

11.  Else, let 

to

 be 

min

(

intEnd

len

).

12.  If 

from

 

 

to

, return the empty String.

13.  Return the 

substring

 of 

S

 from 

from

 to 

to

.

NOTE

Returns an Array object into which substrings of the result of converting this object to a String have been stored. The
substrings are determined by searching from left to right for occurrences of 

separator

; these occurrences are not part of

any String in the returned array, but serve to divide up the String value. The value of 

separator

 may be a String of any

length or it may be an object, such as a RegExp, that has a 

@@split

 method.

When the 

split

split

 method is called, the following steps are taken:

1.  Let 

O

 be ? 

RequireObjectCoercible

(

this

 value).

2.  If 

separator

 is neither 

undefined

 nor 

null

, then

a.  Let 

splitter

 be ? 

GetMethod

(

separator

@@split

).

b.  If 

splitter

 is not 

undefined

, then

The 

search

search

 function is intentionally generic; it does not require that its 

this

 value be a String

object. Therefore, it can be transferred to other kinds of objects for use as a method.

The 

slice

slice

 function is intentionally generic; it does not require that its 

this

 value be a String

object. Therefore it can be transferred to other kinds of objects for use as a method.

22.1.3.20  String.prototype.slice ( 

start

end

 )

22.1.3.21  String.prototype.split ( 

separator

limit

 )

567

i.  Return ? 

Call

(

splitter

separator

, « 

O

limit

 »).

3.  Let 

S

 be ? 

ToString

(

O

).

4.  Let 

A

 be ! 

ArrayCreate

(0).

5.  Let 

lengthA

 be 0.

6.  If 

limit

 is 

undefined

, let 

lim

 be 2

32

 - 1; else let 

lim

ToUint32

(

limit

)).

7.  Let 

R

 be ? 

ToString

(

separator

).

8.  If 

lim

 = 0, return 

A

.

9.  If 

separator

 is 

undefined

, then

a.  Perform ! 

CreateDataPropertyOrThrow

(

A

"0"

S

).

b.  Return 

A

.

10.  Let 

s

 be the length of 

S

.

11.  If 

s

 = 0, then

a.  If 

R

 is not the empty String, then

i.  Perform ! 

CreateDataPropertyOrThrow

(

A

"0"

S

).

b.  Return 

A

.

12.  Let 

p

 be 0.

13.  Let 

q

 be 

p

.

14.  Repeat, while 

q

 

 

s

,

a.  Let 

e

 be 

SplitMatch

(

S

q

R

).

b.  If 

e

 is 

not-matched

, set 

q

 to 

q

 + 1.

c.  Else,

i. 

Assert

e

 is a non-negative 

integer

 

 

s

.

ii.  If 

e

 = 

p

, set 

q

 to 

q

 + 1.

iii.  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.  Set 

q

 to 

p

.

15.  Let 

T

 be the 

substring

 of 

S

 from 

p

 to 

s

.

16.  Perform ! 

CreateDataPropertyOrThrow

(

A

, ! 

ToString

(

lengthA

)), 

T

).

17.  Return 

A

.

NOTE 1

The value of 

separator

 may be an empty String. In this case, 

separator

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

separator

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

If the 

this

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

separator

 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 

separator

 is 

undefined

, then the result array contains just one String, which is the 

this

 value

(converted to a String). If 

limit

 is not 

undefined

, then the output array is truncated so that it

contains no more than 

limit

 elements.

568

NOTE 2

The abstract operation SplitMatch takes arguments 

S

 (a String), 

q

 (a non-negative 

integer

), and 

R

 (a String). It returns

either 

not-matched

 or the end index of a match. It performs the following steps when called:

1.  Let 

r

 be the number of code units in 

R

.

2.  Let 

s

 be the number of code units in 

S

.

3.  If 

q

 + 

r

 > 

s

, return 

not-matched

.

4.  If there exists an 

integer

 

i

 between 0 (inclusive) and 

r

 (exclusive) such that the code unit at index 

q

 + 

i

 within 

S

is different from the code unit at index 

i

 within 

R

, return 

not-matched

.

5.  Return 

q

 + 

r

.

The following steps are taken:

1.  Let 

O

 be ? 

RequireObjectCoercible

(

this

 value).

2.  Let 

S

 be ? 

ToString

(

O

).

3.  Let 

isRegExp

 be ? 

IsRegExp

(

searchString

).

4.  If 

isRegExp

 is 

true

, throw a 

TypeError

 exception.

5.  Let 

searchStr

 be ? 

ToString

(

searchString

).

6.  Let 

len

 be the length of 

S

.

7.  If 

position

 is 

undefined

, let 

pos

 be 0; else let 

pos

 be ? 

ToIntegerOrInfinity

(

position

).

8.  Let 

start

 be the result of 

clamping

 

pos

 between 0 and 

len

.

9.  Let 

searchLength

 be the length of 

searchStr

.

10.  If 

searchLength

 = 0, return 

true

.

11.  Let 

end

 be 

start

 + 

searchLength

.

12.  If 

end

 > 

len

, return 

false

.

13.  Let 

substring

 be the 

substring

 of 

S

 from 

start

 to 

end

.

14.  Return ! 

SameValueNonNumeric

(

substring

searchStr

).

NOTE 1

NOTE 2

NOTE 3

The 

split

split

 function is intentionally generic; it does not require that its 

this

 value be a String

object. Therefore, it can be transferred to other kinds of objects for use as a method.

This method returns 

true

 if the sequence of code units of 

searchString

 converted to a String is the

same as the corresponding code units of this object (converted to a String) starting at index

position

. Otherwise returns 

false

.

Throwing an exception if the first argument is a RegExp is specified in order to allow future
editions to define extensions that allow such argument values.

The 

startsWith

startsWith

 function is intentionally generic; it does not require that its 

this

 value be a

String object. Therefore, it can be transferred to other kinds of objects for use as a method.

22.1.3.21.1  SplitMatch ( 

S

q

R

 )

22.1.3.22  String.prototype.startsWith ( 

searchString

 [ , 

position

 ] )

22.1.3.23  String.prototype.substring ( 

start

end

 )

569

The 

substring

substring

 method takes two arguments, 

start

 and 

end

, and returns a substring of the result of converting this

object to a String, starting from index 

start

 and running to, but not including, index 

end

 of the String (or through the

end of the String if 

end

 is 

undefined

). The result is a String value, not a String object.

If either argument is 

NaN

 or negative, it is replaced with zero; if either argument is larger than the length of the

String, it is replaced with the length of the String.

If 

start

 is larger than 

end

, they are swapped.

The following steps are taken:

1.  Let 

O

 be ? 

RequireObjectCoercible

(

this

 value).

2.  Let 

S

 be ? 

ToString

(

O

).

3.  Let 

len

 be the length of 

S

.

4.  Let 

intStart

 be ? 

ToIntegerOrInfinity

(

start

).

5.  If 

end

 is 

undefined

, let 

intEnd

 be 

len

; else let 

intEnd

 be ? 

ToIntegerOrInfinity

(

end

).

6.  Let 

finalStart

 be the result of 

clamping

 

intStart

 between 0 and 

len

.

7.  Let 

finalEnd

 be the result of 

clamping

 

intEnd

 between 0 and 

len

.

8.  Let 

from

 be 

min

(

finalStart

finalEnd

).

9.  Let 

to

 be 

max

(

finalStart

finalEnd

).

10.  Return the 

substring

 of 

S

 from 

from

 to 

to

.

NOTE

An ECMAScript implementation that includes the ECMA-402 Internationalization API must implement the

toLocaleLowerCase

toLocaleLowerCase

 method as specified in the ECMA-402 specification. If an ECMAScript implementation does

not include the ECMA-402 API the following specification of the 

toLocaleLowerCase

toLocaleLowerCase

 method is used.

This function interprets a String value as a sequence of UTF-16 encoded code points, as described in 

6.1.4

.

This function works exactly the same as 

toLowerCase

toLowerCase

 except that its result is intended to yield the correct result

for the 

host environment

's current locale, rather than a locale-independent result. There will only be a difference in the

few cases (such as Turkish) where the rules for that language conflict with the regular Unicode case mappings.

The meaning of the optional parameters to this method are defined in the ECMA-402 specification; implementations
that do not include ECMA-402 support must not use those parameter positions for anything else.

NOTE

An ECMAScript implementation that includes the ECMA-402 Internationalization API must implement the

toLocaleUpperCase

toLocaleUpperCase

 method as specified in the ECMA-402 specification. If an ECMAScript implementation does

The 

substring

substring

 function is intentionally generic; it does not require that its 

this

 value be a

String object. Therefore, it can be transferred to other kinds of objects for use as a method.

The 

toLocaleLowerCase

toLocaleLowerCase

 function is intentionally generic; it does not require that its 

this

value be a String object. Therefore, it can be transferred to other kinds of objects for use as a
method.

22.1.3.24  String.prototype.toLocaleLowerCase ( [ 

reserved1

 [ , 

reserved2

 ] ] )

22.1.3.25  String.prototype.toLocaleUpperCase ( [ 

reserved1

 [ , 

reserved2

 ] ] )

570

not include the ECMA-402 API the following specification of the 

toLocaleUpperCase

toLocaleUpperCase

 method is used.

This function interprets a String value as a sequence of UTF-16 encoded code points, as described in 

6.1.4

.

This function works exactly the same as 

toUpperCase

toUpperCase

 except that its result is intended to yield the correct result

for the 

host environment

's current locale, rather than a locale-independent result. There will only be a difference in the

few cases (such as Turkish) where the rules for that language conflict with the regular Unicode case mappings.

The meaning of the optional parameters to this method are defined in the ECMA-402 specification; implementations
that do not include ECMA-402 support must not use those parameter positions for anything else.

NOTE

This function interprets a String value as a sequence of UTF-16 encoded code points, as described in 

6.1.4

. The

following steps are taken:

1.  Let 

O

 be ? 

RequireObjectCoercible

(

this

 value).

2.  Let 

S

 be ? 

ToString

(

O

).

3.  Let 

sText

 be ! 

StringToCodePoints

(

S

).

4.  Let 

lowerText

 be the result of toLowercase(

sText

), according to the Unicode Default Case Conversion algorithm.

5.  Let 

L

 be ! 

CodePointsToString

(

lowerText

).

6.  Return 

L

.

The result must be derived according to the locale-insensitive case mappings in the Unicode Character Database (this
explicitly includes not only the UnicodeData.txt file, but also all locale-insensitive mappings in the SpecialCasings.txt
file that accompanies it).

NOTE 1

NOTE 2

When the 

toString

toString

 method is called, the following steps are taken:

1.  Return ? 

thisStringValue

(

this

 value).

The 

toLocaleUpperCase

toLocaleUpperCase

 function is intentionally generic; it does not require that its 

this

value be a String object. Therefore, it can be transferred to other kinds of objects for use as a
method.

The case mapping of some code points may produce multiple code points. In this case the result
String may not be the same length as the source String. Because both 

toUpperCase

toUpperCase

 and

toLowerCase

toLowerCase

 have context-sensitive behaviour, the functions are not symmetrical. In other

words, 

s.toUpperCase().toLowerCase()

s.toUpperCase().toLowerCase()

 is not necessarily equal to

s.toLowerCase()

s.toLowerCase()

.

The 

toLowerCase

toLowerCase

 function is intentionally generic; it does not require that its 

this

 value be a

String object. Therefore, it can be transferred to other kinds of objects for use as a method.

22.1.3.26  String.prototype.toLowerCase ( )

22.1.3.27  String.prototype.toString ( )

571

NOTE

This function interprets a String value as a sequence of UTF-16 encoded code points, as described in 

6.1.4

.

This function behaves in exactly the same way as 

String.prototype.toLowerCase

String.prototype.toLowerCase

, except that the String is

mapped using the toUppercase algorithm of the Unicode Default Case Conversion.

NOTE

This function interprets a String value as a sequence of UTF-16 encoded code points, as described in 

6.1.4

.

The following steps are taken:

1.  Let 

S

 be the 

this

 value.

2.  Return ? 

TrimString

(

S

start+end

).

NOTE

The abstract operation TrimString takes arguments 

string

 and 

where

. It interprets 

string

 as a sequence of UTF-16

encoded code points, as described in 

6.1.4

. It performs the following steps when called:

1.  Let 

str

 be ? 

RequireObjectCoercible

(

string

).

2.  Let 

S

 be ? 

ToString

(

str

).

3.  If 

where

 is 

start

, let 

T

 be the String value that is a copy of 

S

 with leading white space removed.

4.  Else if 

where

 is 

end

, let 

T

 be the String value that is a copy of 

S

 with trailing white space removed.

5.  Else,

a. 

Assert

where

 is 

start+end

.

b.  Let 

T

 be the String value that is a copy of 

S

 with both leading and trailing white space removed.

6.  Return 

T

.

The definition of white space is the union of 

WhiteSpace

 and 

LineTerminator

. When determining whether a Unicode

code point is in Unicode general category “Space_Separator” (“Zs”), code unit sequences are interpreted as UTF-16
encoded code point sequences as specified in 

6.1.4

.

This function interprets a String value as a sequence of UTF-16 encoded code points, as described in 

6.1.4

.

For a String object, the 

toString

toString

 method happens to return the same thing as the 

valueOf

valueOf

method.

The 

toUpperCase

toUpperCase

 function is intentionally generic; it does not require that its 

this

 value be a

String object. Therefore, it can be transferred to other kinds of objects for use as a method.

The 

trim

trim

 function is intentionally generic; it does not require that its 

this

 value be a String

object. Therefore, it can be transferred to other kinds of objects for use as a method.

22.1.3.28  String.prototype.toUpperCase ( )

22.1.3.29  String.prototype.trim ( )

22.1.3.29.1  TrimString ( 

string

where

 )

22.1.3.30  String.prototype.trimEnd ( )

572

 

 

 

 

 

 

 

Content      ..     49      50      51      52     ..