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

 

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

 

Search            copyright infringement  

 

 

 

 

 

 

 

 

 

 

 

Content      ..     21      22      23      24     ..

 

 

 

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

 

 

5.  Return 

true

.

The [[OwnPropertyKeys]] internal method of a 

module namespace exotic object

 

O

 takes no arguments. It performs the

following steps when called:

1.  Let 

exports

 be a copy of 

O

.[[Exports]].

2.  Let 

symbolKeys

 be ! 

OrdinaryOwnPropertyKeys

(

O

).

3.  Append all the entries of 

symbolKeys

 to the end of 

exports

.

4.  Return 

exports

.

The abstract operation ModuleNamespaceCreate takes arguments 

module

 and 

exports

. It is used to specify the creation

of new module namespace exotic objects. It performs the following steps when called:

1. 

Assert

module

 is a 

Module Record

.

2. 

Assert

module

.[[Namespace]] is 

undefined

.

3. 

Assert

exports

 is a 

List

 of String values.

4.  Let 

internalSlotsList

 be the internal slots listed in 

Table 31

.

5.  Let 

M

 be ! 

MakeBasicObject

(

internalSlotsList

).

6.  Set 

M

's essential internal methods to the definitions specified in 

10.4.6

.

7.  Set 

M

.[[Prototype]] to 

null

.

8.  Set 

M

.[[Module]] to 

module

.

9.  Let 

sortedExports

 be a 

List

 whose elements are the elements of 

exports

 ordered as if an Array of the same values

had been sorted using %Array.prototype.sort% using 

undefined

 as 

comparefn

.

10.  Set 

M

.[[Exports]] to 

sortedExports

.

11.  Create own properties of 

M

 corresponding to the definitions in 

28.3

.

12.  Set 

module

.[[Namespace]] to 

M

.

13.  Return 

M

.

An 

immutable prototype exotic object

 is an 

exotic object

 that has a [[Prototype]] internal slot that will not change once

it is initialized.

An object is an 

immutable prototype exotic object

 if its [[SetPrototypeOf]] internal method uses the following

implementation. (Its other essential internal methods may use any implementation, depending on the specific

immutable prototype exotic object

 in question.)

NOTE

Unlike other exotic objects, there is not a dedicated creation abstract operation provided for
immutable prototype exotic objects. This is because they are only used by 

%Object.prototype%

and by 

host

 environments, and in 

host

 environments, the relevant objects are potentially exotic in

other ways and thus need their own dedicated creation operation.

10.4.6.10  [[OwnPropertyKeys]] ( )

10.4.6.11  ModuleNamespaceCreate ( 

module

exports

 )

10.4.7  Immutable Prototype Exotic Objects

10.4.7.1  [[SetPrototypeOf]] ( 

V

 )

259

The [[SetPrototypeOf]] internal method of an 

immutable prototype exotic object

 

O

 takes argument 

V

 (an Object or

null

). It performs the following steps when called:

1.  Return ? 

SetImmutablePrototype

(

O

V

).

The abstract operation SetImmutablePrototype takes arguments 

O

 and 

V

. It performs the following steps when called:

1. 

Assert

: Either 

Type

(

V

) is Object or 

Type

(

V

) is Null.

2.  Let 

current

 be ? 

O

.[[GetPrototypeOf]]().

3.  If 

SameValue

(

V

current

) is 

true

, return 

true

.

4.  Return 

false

.

A proxy object is an 

exotic object

 whose essential internal methods are partially implemented using ECMAScript code.

Every proxy object has an internal slot called [[ProxyHandler]]. The value of [[ProxyHandler]] is an object, called the
proxy's 

handler object

, or 

null

. Methods (see 

Table 32

) of a handler object may be used to augment the implementation

for one or more of the proxy object's internal methods. Every proxy object also has an internal slot called
[[ProxyTarget]] whose value is either an object or the 

null

 value. This object is called the proxy's 

target object

.

An object is a 

Proxy exotic object

 if its essential internal methods (including [[Call]] and [[Construct]], if applicable) use

the definitions in this section. These internal methods are installed in 

ProxyCreate

.

10.4.7.2  SetImmutablePrototype ( 

O

V

 )

10.5  Proxy Object Internal Methods and Internal Slots

260

Table 32: Proxy Handler Methods

Internal Method

Handler Method

[[GetPrototypeOf]]

getPrototypeOf

getPrototypeOf

[[SetPrototypeOf]]

setPrototypeOf

setPrototypeOf

[[IsExtensible]]

isExtensible

isExtensible

[[PreventExtensions]]

preventExtensions

preventExtensions

[[GetOwnProperty]]

getOwnPropertyDescriptor

getOwnPropertyDescriptor

[[DefineOwnProperty]]

defineProperty

defineProperty

[[HasProperty]]

has

has

[[Get]]

get

get

[[Set]]

set

set

[[Delete]]

deleteProperty

deleteProperty

[[OwnPropertyKeys]]

ownKeys

ownKeys

[[Call]]

apply

apply

[[Construct]]

construct

construct

When a handler method is called to provide the implementation of a proxy object internal method, the handler
method is passed the proxy's target object as a parameter. A proxy's handler object does not necessarily have a method
corresponding to every essential internal method. Invoking an internal method on the proxy results in the invocation
of the corresponding internal method on the proxy's target object if the handler object does not have a method
corresponding to the internal trap.

The [[ProxyHandler]] and [[ProxyTarget]] internal slots of a proxy object are always initialized when the object is
created and typically may not be modified. Some proxy objects are created in a manner that permits them to be
subsequently 

revoked

. When a proxy is revoked, its [[ProxyHandler]] and [[ProxyTarget]] internal slots are set to 

null

causing subsequent invocations of internal methods on that proxy object to throw a 

TypeError

 exception.

Because proxy objects permit the implementation of internal methods to be provided by arbitrary ECMAScript code,
it is possible to define a proxy object whose handler methods violates the invariants defined in 

6.1.7.3

. Some of the

internal method invariants defined in 

6.1.7.3

 are essential integrity invariants. These invariants are explicitly enforced

by the proxy object internal methods specified in this section. An ECMAScript implementation must be robust in the
presence of all possible invariant violations.

In the following algorithm descriptions, assume 

O

 is an ECMAScript proxy object, 

P

 is a property key value, 

V

 is any

ECMAScript language value

 and 

Desc

 is a 

Property Descriptor

 record.

The [[GetPrototypeOf]] internal method of a 

Proxy exotic object

 

O

 takes no arguments. It performs the following steps

10.5.1  [[GetPrototypeOf]] ( )

261

when called:

1.  Let 

handler

 be 

O

.[[ProxyHandler]].

2.  If 

handler

 is 

null

, throw a 

TypeError

 exception.

3. 

Assert

Type

(

handler

) is Object.

4.  Let 

target

 be 

O

.[[ProxyTarget]].

5.  Let 

trap

 be ? 

GetMethod

(

handler

"getPrototypeOf"

).

6.  If 

trap

 is 

undefined

, then

a.  Return ? 

target

.[[GetPrototypeOf]]().

7.  Let 

handlerProto

 be ? 

Call

(

trap

handler

, « 

target

 »).

8.  If 

Type

(

handlerProto

) is neither Object nor Null, throw a 

TypeError

 exception.

9.  Let 

extensibleTarget

 be ? 

IsExtensible

(

target

).

10.  If 

extensibleTarget

 is 

true

, return 

handlerProto

.

11.  Let 

targetProto

 be ? 

target

.[[GetPrototypeOf]]().

12.  If 

SameValue

(

handlerProto

targetProto

) is 

false

, throw a 

TypeError

 exception.

13.  Return 

handlerProto

.

NOTE

The [[SetPrototypeOf]] internal method of a 

Proxy exotic object

 

O

 takes argument 

V

 (an Object or 

null

). It performs

the following steps when called:

1. 

Assert

: Either 

Type

(

V

) is Object or 

Type

(

V

) is Null.

2.  Let 

handler

 be 

O

.[[ProxyHandler]].

3.  If 

handler

 is 

null

, throw a 

TypeError

 exception.

4. 

Assert

Type

(

handler

) is Object.

5.  Let 

target

 be 

O

.[[ProxyTarget]].

6.  Let 

trap

 be ? 

GetMethod

(

handler

"setPrototypeOf"

).

7.  If 

trap

 is 

undefined

, then

a.  Return ? 

target

.[[SetPrototypeOf]](

V

).

8.  Let 

booleanTrapResult

 be ! 

ToBoolean

(? 

Call

(

trap

handler

, « 

target

V

 »)).

9.  If 

booleanTrapResult

 is 

false

, return 

false

.

10.  Let 

extensibleTarget

 be ? 

IsExtensible

(

target

).

11.  If 

extensibleTarget

 is 

true

, return 

true

.

12.  Let 

targetProto

 be ? 

target

.[[GetPrototypeOf]]().

13.  If 

SameValue

(

V

targetProto

) is 

false

, throw a 

TypeError

 exception.

14.  Return 

true

.

[[GetPrototypeOf]] for proxy objects enforces the following invariants:

The result of [[GetPrototypeOf]] must be either an Object or 

null

.

If the target object is not extensible, [[GetPrototypeOf]] applied to the proxy object must
return the same value as [[GetPrototypeOf]] applied to the proxy object's target object.

10.5.2  [[SetPrototypeOf]] ( 

V

 )

262

NOTE

The [[IsExtensible]] internal method of a 

Proxy exotic object

 

O

 takes no arguments. It performs the following steps

when called:

1.  Let 

handler

 be 

O

.[[ProxyHandler]].

2.  If 

handler

 is 

null

, throw a 

TypeError

 exception.

3. 

Assert

Type

(

handler

) is Object.

4.  Let 

target

 be 

O

.[[ProxyTarget]].

5.  Let 

trap

 be ? 

GetMethod

(

handler

"isExtensible"

).

6.  If 

trap

 is 

undefined

, then

a.  Return ? 

IsExtensible

(

target

).

7.  Let 

booleanTrapResult

 be ! 

ToBoolean

(? 

Call

(

trap

handler

, « 

target

 »)).

8.  Let 

targetResult

 be ? 

IsExtensible

(

target

).

9.  If 

SameValue

(

booleanTrapResult

targetResult

) is 

false

, throw a 

TypeError

 exception.

10.  Return 

booleanTrapResult

.

NOTE

The [[PreventExtensions]] internal method of a 

Proxy exotic object

 

O

 takes no arguments. It performs the following

steps when called:

1.  Let 

handler

 be 

O

.[[ProxyHandler]].

2.  If 

handler

 is 

null

, throw a 

TypeError

 exception.

3. 

Assert

Type

(

handler

) is Object.

4.  Let 

target

 be 

O

.[[ProxyTarget]].

5.  Let 

trap

 be ? 

GetMethod

(

handler

"preventExtensions"

).

6.  If 

trap

 is 

undefined

, then

a.  Return ? 

target

.[[PreventExtensions]]().

7.  Let 

booleanTrapResult

 be ! 

ToBoolean

(? 

Call

(

trap

handler

, « 

target

 »)).

8.  If 

booleanTrapResult

 is 

true

, then

a.  Let 

extensibleTarget

 be ? 

IsExtensible

(

target

).

b.  If 

extensibleTarget

 is 

true

, throw a 

TypeError

 exception.

9.  Return 

booleanTrapResult

.

[[SetPrototypeOf]] for proxy objects enforces the following invariants:

The result of [[SetPrototypeOf]] is a Boolean value.
If the target object is not extensible, the argument value must be the same as the result of
[[GetPrototypeOf]] applied to target object.

[[IsExtensible]] for proxy objects enforces the following invariants:

The result of [[IsExtensible]] is a Boolean value.
[[IsExtensible]] applied to the proxy object must return the same value as [[IsExtensible]]
applied to the proxy object's target object with the same argument.

10.5.3  [[IsExtensible]] ( )

10.5.4  [[PreventExtensions]] ( )

263

NOTE

The [[GetOwnProperty]] internal method of a 

Proxy exotic object

 

O

 takes argument 

P

 (a property key). It performs the

following steps when called:

1. 

Assert

IsPropertyKey

(

P

) is 

true

.

2.  Let 

handler

 be 

O

.[[ProxyHandler]].

3.  If 

handler

 is 

null

, throw a 

TypeError

 exception.

4. 

Assert

Type

(

handler

) is Object.

5.  Let 

target

 be 

O

.[[ProxyTarget]].

6.  Let 

trap

 be ? 

GetMethod

(

handler

"getOwnPropertyDescriptor"

).

7.  If 

trap

 is 

undefined

, then

a.  Return ? 

target

.[[GetOwnProperty]](

P

).

8.  Let 

trapResultObj

 be ? 

Call

(

trap

handler

, « 

target

P

 »).

9.  If 

Type

(

trapResultObj

) is neither Object nor Undefined, throw a 

TypeError

 exception.

10.  Let 

targetDesc

 be ? 

target

.[[GetOwnProperty]](

P

).

11.  If 

trapResultObj

 is 

undefined

, then

a.  If 

targetDesc

 is 

undefined

, return 

undefined

.

b.  If 

targetDesc

.[[Configurable]] is 

false

, throw a 

TypeError

 exception.

c.  Let 

extensibleTarget

 be ? 

IsExtensible

(

target

).

d.  If 

extensibleTarget

 is 

false

, throw a 

TypeError

 exception.

e.  Return 

undefined

.

12.  Let 

extensibleTarget

 be ? 

IsExtensible

(

target

).

13.  Let 

resultDesc

 be ? 

ToPropertyDescriptor

(

trapResultObj

).

14.  Call 

CompletePropertyDescriptor

(

resultDesc

).

15.  Let 

valid

 be 

IsCompatiblePropertyDescriptor

(

extensibleTarget

resultDesc

targetDesc

).

16.  If 

valid

 is 

false

, throw a 

TypeError

 exception.

17.  If 

resultDesc

.[[Configurable]] is 

false

, then

a.  If 

targetDesc

 is 

undefined

 or 

targetDesc

.[[Configurable]] is 

true

, then

i.  Throw a 

TypeError

 exception.

b.  If 

resultDesc

 has a [[Writable]] field and 

resultDesc

.[[Writable]] is 

false

, then

i.  If 

targetDesc

.[[Writable]] is 

true

, throw a 

TypeError

 exception.

18.  Return 

resultDesc

.

[[PreventExtensions]] for proxy objects enforces the following invariants:

The result of [[PreventExtensions]] is a Boolean value.
[[PreventExtensions]] applied to the proxy object only returns 

true

 if [[IsExtensible]]

applied to the proxy object's target object is 

false

.

10.5.5  [[GetOwnProperty]] ( 

P

 )

264

NOTE

The [[DefineOwnProperty]] internal method of a 

Proxy exotic object

 

O

 takes arguments 

P

 (a property key) and 

Desc

 (a

Property Descriptor

). It performs the following steps when called:

1. 

Assert

IsPropertyKey

(

P

) is 

true

.

2.  Let 

handler

 be 

O

.[[ProxyHandler]].

3.  If 

handler

 is 

null

, throw a 

TypeError

 exception.

4. 

Assert

Type

(

handler

) is Object.

5.  Let 

target

 be 

O

.[[ProxyTarget]].

6.  Let 

trap

 be ? 

GetMethod

(

handler

"defineProperty"

).

7.  If 

trap

 is 

undefined

, then

a.  Return ? 

target

.[[DefineOwnProperty]](

P

Desc

).

8.  Let 

descObj

 be 

FromPropertyDescriptor

(

Desc

).

9.  Let 

booleanTrapResult

 be ! 

ToBoolean

(? 

Call

(

trap

handler

, « 

target

P

descObj

 »)).

10.  If 

booleanTrapResult

 is 

false

, return 

false

.

11.  Let 

targetDesc

 be ? 

target

.[[GetOwnProperty]](

P

).

12.  Let 

extensibleTarget

 be ? 

IsExtensible

(

target

).

13.  If 

Desc

 has a [[Configurable]] field and if 

Desc

.[[Configurable]] is 

false

, then

a.  Let 

settingConfigFalse

 be 

true

.

14.  Else, let 

settingConfigFalse

 be 

false

.

15.  If 

targetDesc

 is 

undefined

, then

a.  If 

extensibleTarget

 is 

false

, throw a 

TypeError

 exception.

b.  If 

settingConfigFalse

 is 

true

, throw a 

TypeError

 exception.

16.  Else,

a.  If 

IsCompatiblePropertyDescriptor

(

extensibleTarget

Desc

targetDesc

) is 

false

, throw a 

TypeError

exception.

b.  If 

settingConfigFalse

 is 

true

 and 

targetDesc

.[[Configurable]] is 

true

, throw a 

TypeError

 exception.

c.  If 

IsDataDescriptor

(

targetDesc

) is 

true

targetDesc

.[[Configurable]] is 

false

, and 

targetDesc

.[[Writable]] is

true

, then

i.  If 

Desc

 has a [[Writable]] field and 

Desc

.[[Writable]] is 

false

, throw a 

TypeError

 exception.

17.  Return 

true

.

[[GetOwnProperty]] for proxy objects enforces the following invariants:

The result of [[GetOwnProperty]] must be either an Object or 

undefined

.

A property cannot be reported as non-existent, if it exists as a non-configurable own
property of the target object.
A property cannot be reported as non-existent, if the target object is not extensible, unless
it does not exist as an own property of the target object.
A property cannot be reported as existent, if the target object is not extensible, unless it
exists as an own property of the target object.
A property cannot be reported as non-configurable, unless it exists as a non-configurable
own property of the target object.
A property cannot be reported as both non-configurable and non-writable, unless it exists
as a non-configurable, non-writable own property of the target object.

10.5.6  [[DefineOwnProperty]] ( 

P

Desc

 )

265

NOTE

The [[HasProperty]] internal method of a 

Proxy exotic object

 

O

 takes argument 

P

 (a property key). It performs the

following steps when called:

1. 

Assert

IsPropertyKey

(

P

) is 

true

.

2.  Let 

handler

 be 

O

.[[ProxyHandler]].

3.  If 

handler

 is 

null

, throw a 

TypeError

 exception.

4. 

Assert

Type

(

handler

) is Object.

5.  Let 

target

 be 

O

.[[ProxyTarget]].

6.  Let 

trap

 be ? 

GetMethod

(

handler

"has"

).

7.  If 

trap

 is 

undefined

, then

a.  Return ? 

target

.[[HasProperty]](

P

).

8.  Let 

booleanTrapResult

 be ! 

ToBoolean

(? 

Call

(

trap

handler

, « 

target

P

 »)).

9.  If 

booleanTrapResult

 is 

false

, then

a.  Let 

targetDesc

 be ? 

target

.[[GetOwnProperty]](

P

).

b.  If 

targetDesc

 is not 

undefined

, then

i.  If 

targetDesc

.[[Configurable]] is 

false

, throw a 

TypeError

 exception.

ii.  Let 

extensibleTarget

 be ? 

IsExtensible

(

target

).

iii.  If 

extensibleTarget

 is 

false

, throw a 

TypeError

 exception.

10.  Return 

booleanTrapResult

.

NOTE

The [[Get]] internal method of a 

Proxy exotic object

 

O

 takes arguments 

P

 (a property key) and 

Receiver

 (an

[[DefineOwnProperty]] for proxy objects enforces the following invariants:

The result of [[DefineOwnProperty]] is a Boolean value.
A property cannot be added, if the target object is not extensible.
A property cannot be non-configurable, unless there exists a corresponding non-
configurable own property of the target object.
A non-configurable property cannot be non-writable, unless there exists a corresponding
non-configurable, non-writable own property of the target object.
If a property has a corresponding target object property then applying the 

Property

Descriptor

 of the property to the target object using [[DefineOwnProperty]] will not throw

an exception.

[[HasProperty]] for proxy objects enforces the following invariants:

The result of [[HasProperty]] is a Boolean value.
A property cannot be reported as non-existent, if it exists as a non-configurable own
property of the target object.
A property cannot be reported as non-existent, if it exists as an own property of the target
object and the target object is not extensible.

10.5.7  [[HasProperty]] ( 

P

 )

10.5.8  [[Get]] ( 

P

Receiver

 )

266

ECMAScript language value

). It performs the following steps when called:

1. 

Assert

IsPropertyKey

(

P

) is 

true

.

2.  Let 

handler

 be 

O

.[[ProxyHandler]].

3.  If 

handler

 is 

null

, throw a 

TypeError

 exception.

4. 

Assert

Type

(

handler

) is Object.

5.  Let 

target

 be 

O

.[[ProxyTarget]].

6.  Let 

trap

 be ? 

GetMethod

(

handler

"get"

).

7.  If 

trap

 is 

undefined

, then

a.  Return ? 

target

.[[Get]](

P

Receiver

).

8.  Let 

trapResult

 be ? 

Call

(

trap

handler

, « 

target

P

Receiver

 »).

9.  Let 

targetDesc

 be ? 

target

.[[GetOwnProperty]](

P

).

10.  If 

targetDesc

 is not 

undefined

 and 

targetDesc

.[[Configurable]] is 

false

, then

a.  If 

IsDataDescriptor

(

targetDesc

) is 

true

 and 

targetDesc

.[[Writable]] is 

false

, then

i.  If 

SameValue

(

trapResult

targetDesc

.[[Value]]) is 

false

, throw a 

TypeError

 exception.

b.  If 

IsAccessorDescriptor

(

targetDesc

) is 

true

 and 

targetDesc

.[[Get]] is 

undefined

, then

i.  If 

trapResult

 is not 

undefined

, throw a 

TypeError

 exception.

11.  Return 

trapResult

.

NOTE

The [[Set]] internal method of a 

Proxy exotic object

 

O

 takes arguments 

P

 (a property key), 

V

 (an 

ECMAScript language

value

), and 

Receiver

 (an 

ECMAScript language value

). It performs the following steps when called:

1. 

Assert

IsPropertyKey

(

P

) is 

true

.

2.  Let 

handler

 be 

O

.[[ProxyHandler]].

3.  If 

handler

 is 

null

, throw a 

TypeError

 exception.

4. 

Assert

Type

(

handler

) is Object.

5.  Let 

target

 be 

O

.[[ProxyTarget]].

6.  Let 

trap

 be ? 

GetMethod

(

handler

"set"

).

7.  If 

trap

 is 

undefined

, then

a.  Return ? 

target

.[[Set]](

P

V

Receiver

).

8.  Let 

booleanTrapResult

 be ! 

ToBoolean

(? 

Call

(

trap

handler

, « 

target

P

V

Receiver

 »)).

9.  If 

booleanTrapResult

 is 

false

, return 

false

.

10.  Let 

targetDesc

 be ? 

target

.[[GetOwnProperty]](

P

).

11.  If 

targetDesc

 is not 

undefined

 and 

targetDesc

.[[Configurable]] is 

false

, then

a.  If 

IsDataDescriptor

(

targetDesc

) is 

true

 and 

targetDesc

.[[Writable]] is 

false

, then

i.  If 

SameValue

(

V

targetDesc

.[[Value]]) is 

false

, throw a 

TypeError

 exception.

[[Get]] for proxy objects enforces the following invariants:

The value reported for a property must be the same as the value of the corresponding
target object property if the target object property is a non-writable, non-configurable own

data property

.

The value reported for a property must be 

undefined

 if the corresponding target object

property is a non-configurable own 

accessor property

 that has 

undefined

 as its [[Get]]

attribute.

10.5.9  [[Set]] ( 

P

V

Receiver

 )

267

b.  If 

IsAccessorDescriptor

(

targetDesc

) is 

true

, then

i.  If 

targetDesc

.[[Set]] is 

undefined

, throw a 

TypeError

 exception.

12.  Return 

true

.

NOTE

The [[Delete]] internal method of a 

Proxy exotic object

 

O

 takes argument 

P

 (a property key). It performs the following

steps when called:

1. 

Assert

IsPropertyKey

(

P

) is 

true

.

2.  Let 

handler

 be 

O

.[[ProxyHandler]].

3.  If 

handler

 is 

null

, throw a 

TypeError

 exception.

4. 

Assert

Type

(

handler

) is Object.

5.  Let 

target

 be 

O

.[[ProxyTarget]].

6.  Let 

trap

 be ? 

GetMethod

(

handler

"deleteProperty"

).

7.  If 

trap

 is 

undefined

, then

a.  Return ? 

target

.[[Delete]](

P

).

8.  Let 

booleanTrapResult

 be ! 

ToBoolean

(? 

Call

(

trap

handler

, « 

target

P

 »)).

9.  If 

booleanTrapResult

 is 

false

, return 

false

.

10.  Let 

targetDesc

 be ? 

target

.[[GetOwnProperty]](

P

).

11.  If 

targetDesc

 is 

undefined

, return 

true

.

12.  If 

targetDesc

.[[Configurable]] is 

false

, throw a 

TypeError

 exception.

13.  Let 

extensibleTarget

 be ? 

IsExtensible

(

target

).

14.  If 

extensibleTarget

 is 

false

, throw a 

TypeError

 exception.

15.  Return 

true

.

NOTE

The [[OwnPropertyKeys]] internal method of a 

Proxy exotic object

 

O

 takes no arguments. It performs the following

[[Set]] for proxy objects enforces the following invariants:

The result of [[Set]] is a Boolean value.
Cannot change the value of a property to be different from the value of the corresponding
target object property if the corresponding target object property is a non-writable, non-
configurable own 

data property

.

Cannot set the value of a property if the corresponding target object property is a non-
configurable own 

accessor property

 that has 

undefined

 as its [[Set]] attribute.

[[Delete]] for proxy objects enforces the following invariants:

The result of [[Delete]] is a Boolean value.
A property cannot be reported as deleted, if it exists as a non-configurable own property
of the target object.
A property cannot be reported as deleted, if it exists as an own property of the target
object and the target object is non-extensible.

10.5.10  [[Delete]] ( 

P

 )

10.5.11  [[OwnPropertyKeys]] ( )

268

steps when called:

1.  Let 

handler

 be 

O

.[[ProxyHandler]].

2.  If 

handler

 is 

null

, throw a 

TypeError

 exception.

3. 

Assert

Type

(

handler

) is Object.

4.  Let 

target

 be 

O

.[[ProxyTarget]].

5.  Let 

trap

 be ? 

GetMethod

(

handler

"ownKeys"

).

6.  If 

trap

 is 

undefined

, then

a.  Return ? 

target

.[[OwnPropertyKeys]]().

7.  Let 

trapResultArray

 be ? 

Call

(

trap

handler

, « 

target

 »).

8.  Let 

trapResult

 be ? 

CreateListFromArrayLike

(

trapResultArray

, « String, Symbol »).

9.  If 

trapResult

 contains any duplicate entries, throw a 

TypeError

 exception.

10.  Let 

extensibleTarget

 be ? 

IsExtensible

(

target

).

11.  Let 

targetKeys

 be ? 

target

.[[OwnPropertyKeys]]().

12. 

Assert

targetKeys

 is a 

List

 whose elements are only String and Symbol values.

13. 

Assert

targetKeys

 contains no duplicate entries.

14.  Let 

targetConfigurableKeys

 be a new empty 

List

.

15.  Let 

targetNonconfigurableKeys

 be a new empty 

List

.

16.  For each element 

key

 of 

targetKeys

, do

a.  Let 

desc

 be ? 

target

.[[GetOwnProperty]](

key

).

b.  If 

desc

 is not 

undefined

 and 

desc

.[[Configurable]] is 

false

, then

i.  Append 

key

 as an element of 

targetNonconfigurableKeys

.

c.  Else,

i.  Append 

key

 as an element of 

targetConfigurableKeys

.

17.  If 

extensibleTarget

 is 

true

 and 

targetNonconfigurableKeys

 is empty, then

a.  Return 

trapResult

.

18.  Let 

uncheckedResultKeys

 be a 

List

 whose elements are the elements of 

trapResult

.

19.  For each element 

key

 of 

targetNonconfigurableKeys

, do

a.  If 

key

 is not an element of 

uncheckedResultKeys

, throw a 

TypeError

 exception.

b.  Remove 

key

 from 

uncheckedResultKeys

.

20.  If 

extensibleTarget

 is 

true

, return 

trapResult

.

21.  For each element 

key

 of 

targetConfigurableKeys

, do

a.  If 

key

 is not an element of 

uncheckedResultKeys

, throw a 

TypeError

 exception.

b.  Remove 

key

 from 

uncheckedResultKeys

.

22.  If 

uncheckedResultKeys

 is not empty, throw a 

TypeError

 exception.

23.  Return 

trapResult

.

NOTE

[[OwnPropertyKeys]] for proxy objects enforces the following invariants:

The result of [[OwnPropertyKeys]] is a 

List

.

The returned 

List

 contains no duplicate entries.

The Type of each result 

List

 element is either String or Symbol.

The result 

List

 must contain the keys of all non-configurable own properties of the target

object.
If the target object is not extensible, then the result 

List

 must contain all the keys of the

own properties of the target object and no other values.

269

The [[Call]] internal method of a 

Proxy exotic object

 

O

 takes arguments 

thisArgument

 (an 

ECMAScript language value

)

and 

argumentsList

 (a 

List

 of ECMAScript language values). It performs the following steps when called:

1.  Let 

handler

 be 

O

.[[ProxyHandler]].

2.  If 

handler

 is 

null

, throw a 

TypeError

 exception.

3. 

Assert

Type

(

handler

) is Object.

4.  Let 

target

 be 

O

.[[ProxyTarget]].

5.  Let 

trap

 be ? 

GetMethod

(

handler

"apply"

).

6.  If 

trap

 is 

undefined

, then

a.  Return ? 

Call

(

target

thisArgument

argumentsList

).

7.  Let 

argArray

 be ! 

CreateArrayFromList

(

argumentsList

).

8.  Return ? 

Call

(

trap

handler

, « 

target

thisArgument

argArray

 »).

NOTE

The [[Construct]] internal method of a 

Proxy exotic object

 

O

 takes arguments 

argumentsList

 (a 

List

 of ECMAScript

language values) and 

newTarget

 (a 

constructor

). It performs the following steps when called:

1.  Let 

handler

 be 

O

.[[ProxyHandler]].

2.  If 

handler

 is 

null

, throw a 

TypeError

 exception.

3. 

Assert

Type

(

handler

) is Object.

4.  Let 

target

 be 

O

.[[ProxyTarget]].

5. 

Assert

IsConstructor

(

target

) is 

true

.

6.  Let 

trap

 be ? 

GetMethod

(

handler

"construct"

).

7.  If 

trap

 is 

undefined

, then

a.  Return ? 

Construct

(

target

argumentsList

newTarget

).

8.  Let 

argArray

 be ! 

CreateArrayFromList

(

argumentsList

).

9.  Let 

newObj

 be ? 

Call

(

trap

handler

, « 

target

argArray

newTarget

 »).

10.  If 

Type

(

newObj

) is not Object, throw a 

TypeError

 exception.

11.  Return 

newObj

.

NOTE 1

NOTE 2

The abstract operation ProxyCreate takes arguments 

target

 and 

handler

. It is used to specify the creation of new Proxy

Proxy exotic object

 only has a [[Call]] internal method if the initial value of its [[ProxyTarget]]

internal slot is an object that has a [[Call]] internal method.

Proxy exotic object

 only has a [[Construct]] internal method if the initial value of its

[[ProxyTarget]] internal slot is an object that has a [[Construct]] internal method.

[[Construct]] for proxy objects enforces the following invariants:

The result of [[Construct]] must be an Object.

10.5.12  [[Call]] ( 

thisArgument

argumentsList

 )

10.5.13  [[Construct]] ( 

argumentsList

newTarget

 )

10.5.14  ProxyCreate ( 

target

handler

 )

270

exotic objects. It performs the following steps when called:

1.  If 

Type

(

target

) is not Object, throw a 

TypeError

 exception.

2.  If 

Type

(

handler

) is not Object, throw a 

TypeError

 exception.

3.  Let 

P

 be ! 

MakeBasicObject

(« [[ProxyHandler]], [[ProxyTarget]] »).

4.  Set 

P

's essential internal methods, except for [[Call]] and [[Construct]], to the definitions specified in 

10.5

.

5.  If 

IsCallable

(

target

) is 

true

, then

a.  Set 

P

.[[Call]] as specified in 

10.5.12

.

b.  If 

IsConstructor

(

target

) is 

true

, then

i.  Set 

P

.[[Construct]] as specified in 

10.5.13

.

6.  Set 

P

.[[ProxyTarget]] to 

target

.

7.  Set 

P

.[[ProxyHandler]] to 

handler

.

8.  Return 

P

.

SourceCharacter

 

::

any Unicode code point

ECMAScript code is expressed using Unicode. ECMAScript source text is a sequence of code points. All Unicode code
point values from U+0000 to U+10FFFF, including surrogate code points, may occur in source text where permitted by
the ECMAScript grammars. The actual encodings used to store and interchange ECMAScript source text is not
relevant to this specification. Regardless of the external source text encoding, a conforming ECMAScript
implementation processes the source text as if it was an equivalent sequence of 

SourceCharacter

 values, each 

SourceCharacter

 being a Unicode code point. Conforming ECMAScript implementations are not required to perform

any normalization of source text, or behave as though they were performing normalization of source text.

The components of a combining character sequence are treated as individual Unicode code points even though a user
might think of the whole sequence as a single character.

11  ECMAScript Language: Source Code

11.1  Source Text

Syntax

271

NOTE

The abstract operation UTF16EncodeCodePoint takes argument 

cp

 (a Unicode code point). It performs the following

steps when called:

1. 

Assert

: 0 

 

cp

 

 0x10FFFF.

2.  If 

cp

 

 0xFFFF, return the String value consisting of the code unit whose value is 

cp

.

3.  Let 

cu1

 be the code unit whose value is 

floor

((

cp

 - 0x10000) / 0x400) + 0xD800.

4.  Let 

cu2

 be the code unit whose value is ((

cp

 - 0x10000) 

modulo

 0x400) + 0xDC00.

5.  Return the 

string-concatenation

 of 

cu1

 and 

cu2

.

The abstract operation CodePointsToString takes argument 

text

 (a sequence of Unicode code points). It converts 

text

into a String value, as described in 

6.1.4

. It performs the following steps when called:

1.  Let 

result

 be the empty String.

2.  For each code point 

cp

 of 

text

, do

a.  Set 

result

 to the 

string-concatenation

 of 

result

 and ! 

UTF16EncodeCodePoint

(

cp

).

3.  Return 

result

.

The abstract operation UTF16SurrogatePairToCodePoint takes arguments 

lead

 (a code unit) and 

trail

 (a code unit). Two

code units that form a UTF-16 

surrogate pair

 are converted to a code point. It performs the following steps when

called:

1. 

Assert

lead

 is a 

leading surrogate

 and 

trail

 is a 

trailing surrogate

.

2.  Let 

cp

 be (

lead

 - 0xD800) 

×

 0x400 + (

trail

 - 0xDC00) + 0x10000.

In string literals, regular expression literals, template literals and identifiers, any Unicode code
point may also be expressed using Unicode escape sequences that explicitly express a code
point's numeric value. Within a comment, such an escape sequence is effectively ignored as part
of the comment.

ECMAScript differs from the Java programming language in the behaviour of Unicode escape
sequences. In a Java program, if the Unicode escape sequence 

\u000A

\u000A

, for example, occurs

within a single-line comment, it is interpreted as a line terminator (Unicode code point U+000A is
LINE FEED (LF)) and therefore the next code point is not part of the comment. Similarly, if the
Unicode escape sequence 

\u000A

\u000A

 occurs within a string literal in a Java program, it is likewise

interpreted as a line terminator, which is not allowed within a string literal—one must write 

\n

\n

instead of 

\u000A

\u000A

 to cause a LINE FEED (LF) to be part of the String value of a string literal. In

an ECMAScript program, a Unicode escape sequence occurring within a comment is never
interpreted and therefore cannot contribute to termination of the comment. Similarly, a Unicode
escape sequence occurring within a string literal in an ECMAScript program always contributes
to the literal and is never interpreted as a line terminator or as a code point that might terminate
the string literal.

11.1.1  Static Semantics: UTF16EncodeCodePoint ( 

cp

 )

11.1.2  Static Semantics: CodePointsToString ( 

text

 )

11.1.3  Static Semantics: UTF16SurrogatePairToCodePoint ( 

lead

trail

 )

272

3.  Return the code point 

cp

.

The abstract operation CodePointAt takes arguments 

string

 (a String) and 

position

 (a non-negative 

integer

). It

interprets 

string

 as a sequence of UTF-16 encoded code points, as described in 

6.1.4

, and reads from it a single code

point starting with the code unit at index 

position

. It performs the following steps when called:

1.  Let 

size

 be the length of 

string

.

2. 

Assert

position

 

 0 and 

position

 < 

size

.

3.  Let 

first

 be the code unit at index 

position

 within 

string

.

4.  Let 

cp

 be the code point whose numeric value is that of 

first

.

5.  If 

first

 is not a 

leading surrogate

 or 

trailing surrogate

, then

a.  Return the 

Record

 { [[CodePoint]]: 

cp

, [[CodeUnitCount]]: 1, [[IsUnpairedSurrogate]]: 

false

 }.

6.  If 

first

 is a 

trailing surrogate

 or 

position

 + 1 = 

size

, then

a.  Return the 

Record

 { [[CodePoint]]: 

cp

, [[CodeUnitCount]]: 1, [[IsUnpairedSurrogate]]: 

true

 }.

7.  Let 

second

 be the code unit at index 

position

 + 1 within 

string

.

8.  If 

second

 is not a 

trailing surrogate

, then

a.  Return the 

Record

 { [[CodePoint]]: 

cp

, [[CodeUnitCount]]: 1, [[IsUnpairedSurrogate]]: 

true

 }.

9.  Set 

cp

 to ! 

UTF16SurrogatePairToCodePoint

(

first

second

).

10.  Return the 

Record

 { [[CodePoint]]: 

cp

, [[CodeUnitCount]]: 2, [[IsUnpairedSurrogate]]: 

false

 }.

The abstract operation StringToCodePoints takes argument 

string

 (a String). It returns the sequence of Unicode code

points that results from interpreting 

string

 as UTF-16 encoded Unicode text as described in 

6.1.4

. It performs the

following steps when called:

1.  Let 

codePoints

 be a new empty 

List

.

2.  Let 

size

 be the length of 

string

.

3.  Let 

position

 be 0.

4.  Repeat, while 

position

 < 

size

,

a.  Let 

cp

 be ! 

CodePointAt

(

string

position

).

b.  Append 

cp

.[[CodePoint]] to 

codePoints

.

c.  Set 

position

 to 

position

 + 

cp

.[[CodeUnitCount]].

5.  Return 

codePoints

.

The abstract operation ParseText takes arguments 

sourceText

 (a sequence of Unicode code points) and 

goalSymbol

 (a

nonterminal in one of the ECMAScript grammars). It performs the following steps when called:

1.  Attempt to parse 

sourceText

 using 

goalSymbol

 as the 

goal symbol

, and analyse the parse result for any 

early

error

 conditions. Parsing and 

early error

 detection may be interleaved in an 

implementation-defined

 manner.

2.  If the parse succeeded and no early errors were found, return the 

Parse Node

 (an instance of 

goalSymbol

) at the

root of the parse tree resulting from the parse.

3.  Otherwise, return a 

List

 of one or more 

SyntaxError

 objects representing the parsing errors and/or early errors.

If more than one parsing error or 

early error

 is present, the number and ordering of error objects in the list is

11.1.4  Static Semantics: CodePointAt ( 

string

position

 )

11.1.5  Static Semantics: StringToCodePoints ( 

string

 )

11.1.6  Static Semantics: ParseText ( 

sourceText

goalSymbol

 )

273

implementation-defined

, but at least one must be present.

NOTE 1

NOTE 2

There are four types of ECMAScript code:

Global code

 is source text that is treated as an ECMAScript 

Script

. The global code of a particular 

Script

 does not

include any source text that is parsed as part of a 

FunctionDeclaration

FunctionExpression

GeneratorDeclaration

GeneratorExpression

AsyncFunctionDeclaration

AsyncFunctionExpression

AsyncGeneratorDeclaration

AsyncGeneratorExpression

MethodDefinition

ArrowFunction

AsyncArrowFunction

ClassDeclaration

, or 

ClassExpression

.

Eval code

 is the source text supplied to the built-in 

eval

eval

 function. More precisely, if the parameter to the built-

in 

eval

eval

 function is a String, it is treated as an ECMAScript 

Script

. The eval code for a particular invocation of

eval

eval

 is the global code portion of that 

Script

.

Function code

 is source text that is parsed to supply the value of the [[ECMAScriptCode]] and

[[FormalParameters]] internal slots (see 

10.2

) of an ECMAScript 

function object

. The function code of a

particular ECMAScript function does not include any source text that is parsed as the function code of a nested

FunctionDeclaration

FunctionExpression

GeneratorDeclaration

GeneratorExpression

AsyncFunctionDeclaration

AsyncFunctionExpression

AsyncGeneratorDeclaration

AsyncGeneratorExpression

MethodDefinition

ArrowFunction

AsyncArrowFunction

ClassDeclaration

, or 

ClassExpression

.

In addition, if the source text referred to above is parsed as:

the 

FormalParameters

 and 

FunctionBody

 of a 

FunctionDeclaration

 or 

FunctionExpression

,

the 

FormalParameters

 and 

GeneratorBody

 of a 

GeneratorDeclaration

 or 

GeneratorExpression

,

the 

FormalParameters

 and 

AsyncFunctionBody

 of an 

AsyncFunctionDeclaration

 or 

AsyncFunctionExpression

,

or
the 

FormalParameters

 and 

AsyncGeneratorBody

 of an 

AsyncGeneratorDeclaration

 or 

AsyncGeneratorExpression

,

then the source text matching the 

BindingIdentifier

 (if any) of that declaration or expression is also included in

the function code of the corresponding function.

Module code

 is source text that is code that is provided as a 

ModuleBody

. It is the code that is directly evaluated

when a module is initialized. The module code of a particular module does not include any source text that is
parsed as part of a nested 

FunctionDeclaration

FunctionExpression

GeneratorDeclaration

GeneratorExpression

AsyncFunctionDeclaration

AsyncFunctionExpression

AsyncGeneratorDeclaration

AsyncGeneratorExpression

MethodDefinition

ArrowFunction

AsyncArrowFunction

ClassDeclaration

, or 

ClassExpression

.

Consider a text that has an 

early error

 at a particular point, and also a syntax error at a later

point. An implementation that does a parse pass followed by an early errors pass might report
the syntax error and not proceed to the early errors pass. An implementation that interleaves the
two activities might report the 

early error

 and not proceed to find the syntax error. A third

implementation might report both errors. All of these behaviours are conformant.

See also clause 

17

.

11.2  Types of Source Code

274

 

 

 

 

 

 

 

Content      ..     21      22      23      24     ..