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

 

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

 

Search            copyright infringement  

 

 

 

 

 

 

 

 

 

 

 

Content      ..     26      27      28      29     ..

 

 

 

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

 

 

5.  Let 

env

 be 

NewModuleEnvironment

(

realm

.[[GlobalEnv]]).

6.  Set 

module

.[[Environment]] to 

env

.

7.  For each 

ImportEntry Record

 

in

 of 

module

.[[ImportEntries]], do

a.  Let 

importedModule

 be ! 

HostResolveImportedModule

(

module

in

.[[ModuleRequest]]).

b.  NOTE: The above call cannot fail because imported module requests are a subset of 

module

.

[[RequestedModules]], and these have been resolved earlier in this algorithm.

c.  If 

in

.[[ImportName]] is 

"*"

, then

i.  Let 

namespace

 be ? 

GetModuleNamespace

(

importedModule

).

ii.  Perform ! 

env

.CreateImmutableBinding(

in

.[[LocalName]], 

true

).

iii.  Call 

env

.InitializeBinding(

in

.[[LocalName]], 

namespace

).

d.  Else,

i.  Let 

resolution

 be ? 

importedModule

.ResolveExport(

in

.[[ImportName]]).

ii.  If 

resolution

 is 

null

 or 

"ambiguous"

, throw a 

SyntaxError

 exception.

iii.  If 

resolution

.[[BindingName]] is 

"*namespace*"

, then

1.  Let 

namespace

 be ? 

GetModuleNamespace

(

resolution

.[[Module]]).

2.  Perform ! 

env

.CreateImmutableBinding(

in

.[[LocalName]], 

true

).

3.  Call 

env

.InitializeBinding(

in

.[[LocalName]], 

namespace

).

iv.  Else,

1.  Call 

env

.CreateImportBinding(

in

.[[LocalName]], 

resolution

.[[Module]], 

resolution

.

[[BindingName]]).

8.  Let 

moduleContext

 be a new ECMAScript code 

execution context

.

9.  Set the Function of 

moduleContext

 to 

null

.

10. 

Assert

module

.[[Realm]] is not 

undefined

.

11.  Set the 

Realm

 of 

moduleContext

 to 

module

.[[Realm]].

12.  Set the ScriptOrModule of 

moduleContext

 to 

module

.

13.  Set the VariableEnvironment of 

moduleContext

 to 

module

.[[Environment]].

14.  Set the LexicalEnvironment of 

moduleContext

 to 

module

.[[Environment]].

15.  Set 

module

.[[Context]] to 

moduleContext

.

16.  Push 

moduleContext

 onto the 

execution context stack

moduleContext

 is now the 

running execution context

.

17.  Let 

code

 be 

module

.[[ECMAScriptCode]].

18.  Let 

varDeclarations

 be the 

VarScopedDeclarations

 of 

code

.

19.  Let 

declaredVarNames

 be a new empty 

List

.

20.  For each element 

d

 of 

varDeclarations

, do

a.  For each element 

dn

 of the 

BoundNames

 of 

d

, do

i.  If 

dn

 is not an element of 

declaredVarNames

, then

1.  Perform ! 

env

.CreateMutableBinding(

dn

false

).

2.  Call 

env

.InitializeBinding(

dn

undefined

).

3.  Append 

dn

 to 

declaredVarNames

.

21.  Let 

lexDeclarations

 be the 

LexicallyScopedDeclarations

 of 

code

.

22.  For each element 

d

 of 

lexDeclarations

, do

a.  For each element 

dn

 of the 

BoundNames

 of 

d

, do

i.  If 

IsConstantDeclaration

 of 

d

 is 

true

, then

1.  Perform ! 

env

.CreateImmutableBinding(

dn

true

).

ii.  Else,

1.  Perform ! 

env

.CreateMutableBinding(

dn

false

).

iii.  If 

d

 is a 

FunctionDeclaration

, a 

GeneratorDeclaration

, an 

AsyncFunctionDeclaration

, or an 

AsyncGeneratorDeclaration

, then

1.  Let 

fo

 be 

InstantiateFunctionObject

 of 

d

 with argument 

env

.

448

2.  Call 

env

.InitializeBinding(

dn

fo

).

23.  Remove 

moduleContext

 from the 

execution context stack

.

24.  Return 

NormalCompletion

(

empty

).

The ExecuteModule concrete method of a 

Source Text Module Record

 

module

 takes no arguments. It performs the

following steps when called:

1.  Suspend the currently 

running execution context

.

2.  Let 

moduleContext

 be 

module

.[[Context]].

3.  Push 

moduleContext

 onto the 

execution context stack

moduleContext

 is now the 

running execution context

.

4.  Let 

result

 be the result of evaluating 

module

.[[ECMAScriptCode]].

5.  Suspend 

moduleContext

 and remove it from the 

execution context stack

.

6.  Resume the context that is now on the top of the 

execution context stack

 as the 

running execution context

.

7.  Return 

Completion

(

result

).

The 

host-defined

 abstract operation HostResolveImportedModule takes arguments 

referencingScriptOrModule

 (a 

Script

Record

 or 

Module Record

 or 

null

) and 

specifier

 (a 

ModuleSpecifier

 String). It provides the concrete 

Module Record

subclass instance that corresponds to 

specifier

 occurring within the context of the script or module represented by

referencingScriptOrModule

referencingScriptOrModule

 may be 

null

 if the resolution is being performed in the context of

an 

import()

import()

 expression and there is no 

active script or module

 at that time.

NOTE

The implementation of HostResolveImportedModule must conform to the following requirements:

The normal return value must be an instance of a concrete subclass of 

Module Record

.

If a 

Module Record

 corresponding to the pair 

referencingScriptOrModule

specifier

 does not exist or cannot be

created, an exception must be thrown.
Each time this operation is called with a specific 

referencingScriptOrModule

specifier

 pair as arguments it must

return the same 

Module Record

 instance if it completes normally.

Multiple different 

referencingScriptOrModule

specifier

 pairs may map to the same 

Module Record

 instance. The actual

mapping semantic is 

host-defined

 but typically a normalization process is applied to 

specifier

 as part of the mapping

process. A typical normalization process would include actions such as alphabetic case folding and expansion of
relative and abbreviated path specifiers.

An example of when 

referencingScriptOrModule

 can be 

null

 is in a web browser 

host

. There, if a

user clicks on a control given by

there will be no 

active script or module

 at the time the 

import()

import()

 expression runs. More

generally, this can happen in any situation where the 

host

 pushes execution contexts with 

null

ScriptOrModule components onto the 

execution context stack

.

<

button

 

type

=

"button"

 

onclick

=

"import('./foo.mjs')"

>Click me</

button

>

16.2.1.6.5  ExecuteModule ( ) Concrete Method

16.2.1.7  HostResolveImportedModule ( 

referencingScriptOrModule

specifier

 )

16.2.1.8  HostImportModuleDynamically ( 

referencingScriptOrModule

specifier

promiseCapability

 )

449

The 

host-defined

 abstract operation HostImportModuleDynamically takes arguments 

referencingScriptOrModule

 (a

Script Record

 or 

Module Record

 or 

null

), 

specifier

 (a 

ModuleSpecifier

 String), and 

promiseCapability

 (a 

PromiseCapability

Record

). It performs any necessary setup work in order to make available the module corresponding to 

specifier

occurring within the context of the script or module represented by 

referencingScriptOrModule

.

referencingScriptOrModule

 may be 

null

 if there is no 

active script or module

 when the 

import()

import()

 expression occurs. It

then performs 

FinishDynamicImport

 to finish the dynamic import process.

The implementation of HostImportModuleDynamically must conform to the following requirements:

The abstract operation must always complete normally with 

undefined

. Success or failure must instead be

signaled as discussed below.
The 

host environment

 must conform to one of the two following sets of requirements:

Success path

At some future time, the 

host environment

 must perform

FinishDynamicImport

(

referencingScriptOrModule

specifier

promiseCapability

,

NormalCompletion

(

undefined

)).

Any subsequent call to 

HostResolveImportedModule

 after 

FinishDynamicImport

 has completed,

given the arguments 

referencingScriptOrModule

 and 

specifier

, must complete normally.

The completion value of any subsequent call to 

HostResolveImportedModule

 after

FinishDynamicImport

 has completed, given the arguments 

referencingScriptOrModule

 and

specifier

, must be a module which has already been evaluated, i.e. whose Evaluate concrete

method has already been called and returned a normal completion.

Failure path

At some future time, the 

host environment

 must perform

FinishDynamicImport

(

referencingScriptOrModule

specifier

promiseCapability

, an 

abrupt

completion

), with the 

abrupt completion

 representing the cause of failure.

If the 

host environment

 takes the success path once for a given 

referencingScriptOrModule

specifier

 pair, it must

always do so for subsequent calls.
The operation must not call 

promiseCapability

.[[Resolve]] or 

promiseCapability

.[[Reject]], but instead must treat

promiseCapability

 as an opaque identifying value to be passed through to 

FinishDynamicImport

.

The actual process performed is 

host-defined

, but typically consists of performing whatever I/O operations are

necessary to allow 

HostResolveImportedModule

 to synchronously retrieve the appropriate 

Module Record

, and then

calling its Evaluate concrete method. This might require performing similar normalization as

HostResolveImportedModule

 does.

The abstract operation FinishDynamicImport takes arguments 

referencingScriptOrModule

specifier

promiseCapability

 (a

PromiseCapability Record

), and 

completion

. FinishDynamicImport completes the process of a dynamic import

originally started by an 

import()

import()

 call, resolving or rejecting the promise returned by that call as appropriate

according to 

completion

. It is performed by 

host

 environments as part of 

HostImportModuleDynamically

. It performs

the following steps when called:

1.  If 

completion

 is an 

abrupt completion

, perform ! 

Call

(

promiseCapability

.[[Reject]], 

undefined

, « 

completion

.

[[Value]] »).

2.  Else,

a. 

Assert

completion

 is a normal completion and 

completion

.[[Value]] is 

undefined

.

16.2.1.9  FinishDynamicImport ( 

referencingScriptOrModule

specifier

promiseCapability

completion

 )

450

b.  Let 

moduleRecord

 be ! 

HostResolveImportedModule

(

referencingScriptOrModule

specifier

).

c. 

Assert

: Evaluate has already been invoked on 

moduleRecord

 and successfully completed.

d.  Let 

namespace

 be 

GetModuleNamespace

(

moduleRecord

).

e.  If 

namespace

 is an 

abrupt completion

, perform ! 

Call

(

promiseCapability

.[[Reject]], 

undefined

, « 

namespace

.

[[Value]] »).

f.  Else, perform ! 

Call

(

promiseCapability

.[[Resolve]], 

undefined

, « 

namespace

.[[Value]] »).

The abstract operation GetModuleNamespace takes argument 

module

. It retrieves the Module Namespace Object

representing 

module

's exports, lazily creating it the first time it was requested, and storing it in 

module

.[[Namespace]]

for future retrieval. It performs the following steps when called:

1. 

Assert

module

 is an instance of a concrete subclass of 

Module Record

.

2. 

Assert

: If 

module

 is a 

Cyclic Module Record

, then 

module

.[[Status]] is not 

unlinked

.

3.  Let 

namespace

 be 

module

.[[Namespace]].

4.  If 

namespace

 is 

undefined

, then

a.  Let 

exportedNames

 be ? 

module

.GetExportedNames().

b.  Let 

unambiguousNames

 be a new empty 

List

.

c.  For each element 

name

 of 

exportedNames

, do

i.  Let 

resolution

 be ? 

module

.ResolveExport(

name

).

ii.  If 

resolution

 is a 

ResolvedBinding Record

, append 

name

 to 

unambiguousNames

.

d.  Set 

namespace

 to 

ModuleNamespaceCreate

(

module

unambiguousNames

).

5.  Return 

namespace

.

NOTE

Module

 

:

  [empty]

1.  Return 

NormalCompletion

(

undefined

).

ModuleBody

 

:

 

ModuleItemList

1.  Let 

result

 be the result of evaluating 

ModuleItemList

.

2.  If 

result

.[[Type]] is 

normal

 and 

result

.[[Value]] is 

empty

, then

a.  Return 

NormalCompletion

(

undefined

).

3.  Return 

Completion

(

result

).

ModuleItemList

 

:

 

ModuleItemList

 

ModuleItem

1.  Let 

sl

 be the result of evaluating 

ModuleItemList

.

2. 

ReturnIfAbrupt

(

sl

).

3.  Let 

s

 be the result of evaluating 

ModuleItem

.

4.  Return 

Completion

(

UpdateEmpty

(

s

sl

)).

The only way GetModuleNamespace can throw is via one of the triggered

HostResolveImportedModule

 calls. Unresolvable names are simply excluded from the

namespace at this point. They will lead to a real linking error later unless they are all ambiguous
star exports that are not explicitly requested anywhere.

16.2.1.10  GetModuleNamespace ( 

module

 )

16.2.1.11  Runtime Semantics: Evaluation

451

ModuleItem

 

:

 

ImportDeclaration

It is a Syntax Error if the 

BoundNames

 of 

ImportDeclaration

 contains any duplicate entries.

Module

 

:

  [empty]

1.  Return a new empty 

List

.

ModuleItemList

 

:

 

ModuleItemList

 

ModuleItem

1.  Let 

entries

 be 

ImportEntries

 of 

ModuleItemList

.

2.  Append to 

entries

 the elements of the 

ImportEntries

 of 

ModuleItem

.

3.  Return 

entries

.

ModuleItem

 

:

ExportDeclaration
StatementListItem

1.  Return a new empty 

List

.

ImportDeclaration

 

:

 

import

 

ImportClause

 

FromClause

 

;

1.  Let 

module

 be the sole element of 

ModuleRequests

 of 

FromClause

.

2.  Return 

ImportEntriesForModule

 of 

ImportClause

 with argument 

module

.

ImportDeclaration

 

:

 

import

 

ModuleSpecifier

 

;

1.  Return a new empty 

List

.

With parameter 

module

.

ImportClause

 

:

 

ImportedDefaultBinding

 

,

 

NameSpaceImport

1.  Let 

entries

 be 

ImportEntriesForModule

 of 

ImportedDefaultBinding

 with argument 

module

.

2.  Append to 

entries

 the elements of the 

ImportEntriesForModule

 of 

NameSpaceImport

 with argument 

module

.

3.  Return 

entries

.

ImportClause

 

:

 

ImportedDefaultBinding

 

,

 

NamedImports

1.  Let 

entries

 be 

ImportEntriesForModule

 of 

ImportedDefaultBinding

 with argument 

module

.

2.  Append to 

entries

 the elements of the 

ImportEntriesForModule

 of 

NamedImports

 with argument 

module

.

3.  Return 

entries

.

ImportedDefaultBinding

 

:

 

ImportedBinding

1.  Let 

localName

 be the sole element of 

BoundNames

 of 

ImportedBinding

.

2.  Let 

defaultEntry

 be the 

ImportEntry Record

 { [[ModuleRequest]]: 

module

, [[ImportName]]: 

"default"

,

[[LocalName]]: 

localName

 }.

3.  Return a 

List

 whose sole element is 

defaultEntry

.

16.2.2.1  Static Semantics: Early Errors

16.2.2.2  Static Semantics: ImportEntries

16.2.2.3  Static Semantics: ImportEntriesForModule

453

NameSpaceImport

 

:

 

*

 

as

 

ImportedBinding

1.  Let 

localName

 be the 

StringValue

 of 

ImportedBinding

.

2.  Let 

entry

 be the 

ImportEntry Record

 { [[ModuleRequest]]: 

module

, [[ImportName]]: 

"*"

, [[LocalName]]:

localName

 }.

3.  Return a 

List

 whose sole element is 

entry

.

NamedImports

 

:

 

{

 

}

1.  Return a new empty 

List

.

ImportsList

 

:

 

ImportsList

 

,

 

ImportSpecifier

1.  Let 

specs

 be the 

ImportEntriesForModule

 of 

ImportsList

 with argument 

module

.

2.  Append to 

specs

 the elements of the 

ImportEntriesForModule

 of 

ImportSpecifier

 with argument 

module

.

3.  Return 

specs

.

ImportSpecifier

 

:

 

ImportedBinding

1.  Let 

localName

 be the sole element of 

BoundNames

 of 

ImportedBinding

.

2.  Let 

entry

 be the 

ImportEntry Record

 { [[ModuleRequest]]: 

module

, [[ImportName]]: 

localName

, [[LocalName]]:

localName

 }.

3.  Return a 

List

 whose sole element is 

entry

.

ImportSpecifier

 

:

 

IdentifierName

 

as

 

ImportedBinding

1.  Let 

importName

 be the 

StringValue

 of 

IdentifierName

.

2.  Let 

localName

 be the 

StringValue

 of 

ImportedBinding

.

3.  Let 

entry

 be the 

ImportEntry Record

 { [[ModuleRequest]]: 

module

, [[ImportName]]: 

importName

, [[LocalName]]:

localName

 }.

4.  Return a 

List

 whose sole element is 

entry

.

ExportDeclaration

 

:

export

 

ExportFromClause

 

FromClause

 

;

export

 

NamedExports

 

;

export

 

VariableStatement

[~Yield, ~Await]

export

 

Declaration

[~Yield, ~Await]

export

 

default

 

HoistableDeclaration

[~Yield, ~Await, +Default]

export

 

default

 

ClassDeclaration

[~Yield, ~Await, +Default]

export

 

default

 [lookahead 

 { 

function

async

 [no 

LineTerminator

 here]  

function

class

 }]

AssignmentExpression

[+In, ~Yield, ~Await]

 

;

ExportFromClause

 

:

*

*

 

as

 

IdentifierName

NamedExports

16.2.3  Exports

Syntax

454

NamedExports

 

:

{

 

}

{

 

ExportsList

 

}

{

 

ExportsList

 

,

 

}

ExportsList

 

:

ExportSpecifier
ExportsList

 

,

 

ExportSpecifier

ExportSpecifier

 

:

IdentifierName
IdentifierName

 

as

 

IdentifierName

ExportDeclaration

 

:

 

export

 

NamedExports

 

;

For each 

IdentifierName

 

n

 in 

ReferencedBindings

 of 

NamedExports

: It is a Syntax Error if 

StringValue

 of 

n

 is a 

ReservedWord

 or if the 

StringValue

 of 

n

 is one of: 

"implements"

"interface"

"let"

"package"

"private"

,

"protected"

"public"

, or 

"static"

.

NOTE

NOTE

ModuleItemList

 

:

 

ModuleItemList

 

ModuleItem

1.  Let 

names

 be 

ExportedBindings

 of 

ModuleItemList

.

2.  Append to 

names

 the elements of the 

ExportedBindings

 of 

ModuleItem

.

3.  Return 

names

.

ModuleItem

 

:

ImportDeclaration
StatementListItem

1.  Return a new empty 

List

.

ExportDeclaration

 

:

export

 

ExportFromClause

 

FromClause

 

;

1.  Return a new empty 

List

.

ExportDeclaration

 

:

 

export

 

NamedExports

 

;

1.  Return the 

ExportedBindings

 of 

NamedExports

.

The above rule means that each 

ReferencedBindings

 of 

NamedExports

 is treated as an 

IdentifierReference

.

ExportedBindings are the locally bound names that are explicitly associated with a 

Module

's

ExportedNames

.

16.2.3.1  Static Semantics: Early Errors

16.2.3.2  Static Semantics: ExportedBindings

455

ExportDeclaration

 

:

 

export

 

VariableStatement

1.  Return the 

BoundNames

 of 

VariableStatement

.

ExportDeclaration

 

:

 

export

 

Declaration

1.  Return the 

BoundNames

 of 

Declaration

.

ExportDeclaration

 

:

export

 

default

 

HoistableDeclaration

export

 

default

 

ClassDeclaration

export

 

default

 

AssignmentExpression

 

;

1.  Return the 

BoundNames

 of this 

ExportDeclaration

.

NamedExports

 

:

 

{

 

}

1.  Return a new empty 

List

.

ExportsList

 

:

 

ExportsList

 

,

 

ExportSpecifier

1.  Let 

names

 be the 

ExportedBindings

 of 

ExportsList

.

2.  Append to 

names

 the elements of the 

ExportedBindings

 of 

ExportSpecifier

.

3.  Return 

names

.

ExportSpecifier

 

:

 

IdentifierName

1.  Return a 

List

 whose sole element is the 

StringValue

 of 

IdentifierName

.

ExportSpecifier

 

:

 

IdentifierName

 

as

 

IdentifierName

1.  Return a 

List

 whose sole element is the 

StringValue

 of the first 

IdentifierName

.

NOTE

ModuleItemList

 

:

 

ModuleItemList

 

ModuleItem

1.  Let 

names

 be 

ExportedNames

 of 

ModuleItemList

.

2.  Append to 

names

 the elements of the 

ExportedNames

 of 

ModuleItem

.

3.  Return 

names

.

ModuleItem

 

:

 

ExportDeclaration

1.  Return the 

ExportedNames

 of 

ExportDeclaration

.

ModuleItem

 

:

ImportDeclaration
StatementListItem

ExportedNames are the externally visible names that a 

Module

 explicitly maps to one of its local

name bindings.

16.2.3.3  Static Semantics: ExportedNames

456

1.  Return a new empty 

List

.

ExportDeclaration

 

:

 

export

 

ExportFromClause

 

FromClause

 

;

1.  Return the 

ExportedNames

 of 

ExportFromClause

.

ExportFromClause

 

:

 

*

1.  Return a new empty 

List

.

ExportFromClause

 

:

 

*

 

as

 

IdentifierName

1.  Return a 

List

 whose sole element is the 

StringValue

 of 

IdentifierName

.

ExportFromClause

 

:

 

NamedExports

1.  Return the 

ExportedNames

 of 

NamedExports

.

ExportDeclaration

 

:

 

export

 

VariableStatement

1.  Return the 

BoundNames

 of 

VariableStatement

.

ExportDeclaration

 

:

 

export

 

Declaration

1.  Return the 

BoundNames

 of 

Declaration

.

ExportDeclaration

 

:

export

 

default

 

HoistableDeclaration

export

 

default

 

ClassDeclaration

export

 

default

 

AssignmentExpression

 

;

1.  Return « 

"default"

 ».

NamedExports

 

:

 

{

 

}

1.  Return a new empty 

List

.

ExportsList

 

:

 

ExportsList

 

,

 

ExportSpecifier

1.  Let 

names

 be the 

ExportedNames

 of 

ExportsList

.

2.  Append to 

names

 the elements of the 

ExportedNames

 of 

ExportSpecifier

.

3.  Return 

names

.

ExportSpecifier

 

:

 

IdentifierName

1.  Return a 

List

 whose sole element is the 

StringValue

 of 

IdentifierName

.

ExportSpecifier

 

:

 

IdentifierName

 

as

 

IdentifierName

1.  Return a 

List

 whose sole element is the 

StringValue

 of the second 

IdentifierName

.

Module

 

:

  [empty]

1.  Return a new empty 

List

.

16.2.3.4  Static Semantics: ExportEntries

457

ModuleItemList

 

:

 

ModuleItemList

 

ModuleItem

1.  Let 

entries

 be 

ExportEntries

 of 

ModuleItemList

.

2.  Append to 

entries

 the elements of the 

ExportEntries

 of 

ModuleItem

.

3.  Return 

entries

.

ModuleItem

 

:

ImportDeclaration
StatementListItem

1.  Return a new empty 

List

.

ExportDeclaration

 

:

 

export

 

ExportFromClause

 

FromClause

 

;

1.  Let 

module

 be the sole element of 

ModuleRequests

 of 

FromClause

.

2.  Return 

ExportEntriesForModule

 of 

ExportFromClause

 with argument 

module

.

ExportDeclaration

 

:

 

export

 

NamedExports

 

;

1.  Return 

ExportEntriesForModule

 of 

NamedExports

 with argument 

null

.

ExportDeclaration

 

:

 

export

 

VariableStatement

1.  Let 

entries

 be a new empty 

List

.

2.  Let 

names

 be the 

BoundNames

 of 

VariableStatement

.

3.  For each element 

name

 of 

names

, do

a.  Append the 

ExportEntry Record

 { [[ModuleRequest]]: 

null

, [[ImportName]]: 

null

, [[LocalName]]: 

name

,

[[ExportName]]: 

name

 } to 

entries

.

4.  Return 

entries

.

ExportDeclaration

 

:

 

export

 

Declaration

1.  Let 

entries

 be a new empty 

List

.

2.  Let 

names

 be the 

BoundNames

 of 

Declaration

.

3.  For each element 

name

 of 

names

, do

a.  Append the 

ExportEntry Record

 { [[ModuleRequest]]: 

null

, [[ImportName]]: 

null

, [[LocalName]]: 

name

,

[[ExportName]]: 

name

 } to 

entries

.

4.  Return 

entries

.

ExportDeclaration

 

:

 

export

 

default

 

HoistableDeclaration

1.  Let 

names

 be 

BoundNames

 of 

HoistableDeclaration

.

2.  Let 

localName

 be the sole element of 

names

.

3.  Return a 

List

 whose sole element is the 

ExportEntry Record

 { [[ModuleRequest]]: 

null

, [[ImportName]]: 

null

,

[[LocalName]]: 

localName

, [[ExportName]]: 

"default"

 }.

ExportDeclaration

 

:

 

export

 

default

 

ClassDeclaration

1.  Let 

names

 be 

BoundNames

 of 

ClassDeclaration

.

2.  Let 

localName

 be the sole element of 

names

.

3.  Return a 

List

 whose sole element is the 

ExportEntry Record

 { [[ModuleRequest]]: 

null

, [[ImportName]]: 

null

,

[[LocalName]]: 

localName

, [[ExportName]]: 

"default"

 }.

458

ExportDeclaration

 

:

 

export

 

default

 

AssignmentExpression

 

;

1.  Let 

entry

 be the 

ExportEntry Record

 { [[ModuleRequest]]: 

null

, [[ImportName]]: 

null

, [[LocalName]]:

"*default*"

, [[ExportName]]: 

"default"

 }.

2.  Return a 

List

 whose sole element is 

entry

.

NOTE

With parameter 

module

.

ExportFromClause

 

:

 

*

1.  Let 

entry

 be the 

ExportEntry Record

 { [[ModuleRequest]]: 

module

, [[ImportName]]: 

"*"

, [[LocalName]]: 

null

,

[[ExportName]]: 

null

 }.

2.  Return a 

List

 whose sole element is 

entry

.

ExportFromClause

 

:

 

*

 

as

 

IdentifierName

1.  Let 

exportName

 be the 

StringValue

 of 

IdentifierName

.

2.  Let 

entry

 be the 

ExportEntry Record

 { [[ModuleRequest]]: 

module

, [[ImportName]]: 

"*"

, [[LocalName]]: 

null

,

[[ExportName]]: 

exportName

 }.

3.  Return a 

List

 whose sole element is 

entry

.

NamedExports

 

:

 

{

 

}

1.  Return a new empty 

List

.

ExportsList

 

:

 

ExportsList

 

,

 

ExportSpecifier

1.  Let 

specs

 be the 

ExportEntriesForModule

 of 

ExportsList

 with argument 

module

.

2.  Append to 

specs

 the elements of the 

ExportEntriesForModule

 of 

ExportSpecifier

 with argument 

module

.

3.  Return 

specs

.

ExportSpecifier

 

:

 

IdentifierName

1.  Let 

sourceName

 be the 

StringValue

 of 

IdentifierName

.

2.  If 

module

 is 

null

, then

a.  Let 

localName

 be 

sourceName

.

b.  Let 

importName

 be 

null

.

3.  Else,

a.  Let 

localName

 be 

null

.

b.  Let 

importName

 be 

sourceName

.

4.  Return a 

List

 whose sole element is the 

ExportEntry Record

 { [[ModuleRequest]]: 

module

, [[ImportName]]:

importName

, [[LocalName]]: 

localName

, [[ExportName]]: 

sourceName

 }.

ExportSpecifier

 

:

 

IdentifierName

 

as

 

IdentifierName

1.  Let 

sourceName

 be the 

StringValue

 of the first 

IdentifierName

.

"*default*"

 is used within this specification as a synthetic name for anonymous default export

values.

16.2.3.5  Static Semantics: ExportEntriesForModule

459

2.  Let 

exportName

 be the 

StringValue

 of the second 

IdentifierName

.

3.  If 

module

 is 

null

, then

a.  Let 

localName

 be 

sourceName

.

b.  Let 

importName

 be 

null

.

4.  Else,

a.  Let 

localName

 be 

null

.

b.  Let 

importName

 be 

sourceName

.

5.  Return a 

List

 whose sole element is the 

ExportEntry Record

 { [[ModuleRequest]]: 

module

, [[ImportName]]:

importName

, [[LocalName]]: 

localName

, [[ExportName]]: 

exportName

 }.

NamedExports

 

:

 

{

 

}

1.  Return a new empty 

List

.

ExportsList

 

:

 

ExportsList

 

,

 

ExportSpecifier

1.  Let 

names

 be the 

ReferencedBindings

 of 

ExportsList

.

2.  Append to 

names

 the elements of the 

ReferencedBindings

 of 

ExportSpecifier

.

3.  Return 

names

.

ExportSpecifier

 

:

 

IdentifierName

1.  Return a 

List

 whose sole element is the 

IdentifierName

.

ExportSpecifier

 

:

 

IdentifierName

 

as

 

IdentifierName

1.  Return a 

List

 whose sole element is the first 

IdentifierName

.

ExportDeclaration

 

:

export

 

ExportFromClause

 

FromClause

 

;

export

 

NamedExports

 

;

1.  Return 

NormalCompletion

(

empty

).

ExportDeclaration

 

:

 

export

 

VariableStatement

1.  Return the result of evaluating 

VariableStatement

.

ExportDeclaration

 

:

 

export

 

Declaration

1.  Return the result of evaluating 

Declaration

.

ExportDeclaration

 

:

 

export

 

default

 

HoistableDeclaration

1.  Return the result of evaluating 

HoistableDeclaration

.

ExportDeclaration

 

:

 

export

 

default

 

ClassDeclaration

1.  Let 

value

 be ? 

BindingClassDeclarationEvaluation

 of 

ClassDeclaration

.

2.  Let 

className

 be the sole element of 

BoundNames

 of 

ClassDeclaration

.

16.2.3.6  Static Semantics: ReferencedBindings

16.2.3.7  Runtime Semantics: Evaluation

460

3.  If 

className

 is 

"*default*"

, then

a.  Let 

env

 be the 

running execution context

's LexicalEnvironment.

b.  Perform ? 

InitializeBoundName

(

"*default*"

value

env

).

4.  Return 

NormalCompletion

(

empty

).

ExportDeclaration

 

:

 

export

 

default

 

AssignmentExpression

 

;

1.  If 

IsAnonymousFunctionDefinition

(

AssignmentExpression

) is 

true

, then

a.  Let 

value

 be ? 

NamedEvaluation

 of 

AssignmentExpression

 with argument 

"default"

.

2.  Else,

a.  Let 

rhs

 be the result of evaluating 

AssignmentExpression

.

b.  Let 

value

 be ? 

GetValue

(

rhs

).

3.  Let 

env

 be the 

running execution context

's LexicalEnvironment.

4.  Perform ? 

InitializeBoundName

(

"*default*"

value

env

).

5.  Return 

NormalCompletion

(

empty

).

An implementation must report most errors at the time the relevant ECMAScript language construct is evaluated. An

early error

 is an error that can be detected and reported prior to the evaluation of any construct in the 

Script

 containing

the error. The presence of an 

early error

 prevents the evaluation of the construct. An implementation must report early

errors in a 

Script

 as part of parsing that 

Script

 in 

ParseScript

. Early errors in a 

Module

 are reported at the point when

the 

Module

 would be evaluated and the 

Module

 is never initialized. Early errors in 

eval

 code are reported at the time

eval

eval

 is called and prevent evaluation of the 

eval

 code. All errors that are not early errors are runtime errors.

An implementation must report as an 

early error

 any occurrence of a condition that is listed in a “Static Semantics:

Early Errors” subclause of this specification.

An implementation shall not treat other kinds of errors as early errors even if the compiler can prove that a construct
cannot execute without error under any circumstances. An implementation may issue an early warning in such a case,
but it should not report the error until the relevant construct is actually executed.

An implementation shall report all errors as specified, except for the following:

Except as restricted in 

17.1

, a 

host

 or implementation may extend 

Script

 syntax, 

Module

 syntax, and regular

expression pattern or flag syntax. To permit this, all operations (such as calling 

eval

eval

, using a regular

expression literal, or using the Function or RegExp 

constructor

) that are allowed to throw 

SyntaxError

 are

permitted to exhibit 

host-defined

 behaviour instead of throwing 

SyntaxError

 when they encounter a 

host-

defined

 extension to the script syntax or regular expression pattern or flag syntax.

Except as restricted in 

17.1

, a 

host

 or implementation may provide additional types, values, objects, properties,

and functions beyond those described in this specification. This may cause constructs (such as looking up a
variable in the global scope) to have 

host-defined

 behaviour instead of throwing an error (such as

ReferenceError

).

An implementation must not extend this specification in the following ways:

17  Error Handling and Language Extensions

17.1  Forbidden Extensions

461

ECMAScript function objects defined using syntactic constructors in 

strict mode code

 must not be created with

own properties named 

"caller"

 or 

"arguments"

. Such own properties also must not be created for function

objects defined using an 

ArrowFunction

MethodDefinition

GeneratorDeclaration

GeneratorExpression

AsyncGeneratorDeclaration

AsyncGeneratorExpression

ClassDeclaration

ClassExpression

AsyncFunctionDeclaration

,

AsyncFunctionExpression

, or 

AsyncArrowFunction

 regardless of whether the definition is contained in 

strict

mode code

. Built-in functions, strict functions created using the Function 

constructor

, generator functions

created using the Generator 

constructor

, async functions created using the AsyncFunction 

constructor

, and

functions created using the 

bind

bind

 method also must not be created with such own properties.

If an implementation extends any 

function object

 with an own property named 

"caller"

 the value of that

property, as observed using [[Get]] or [[GetOwnProperty]], must not be a 

strict function

 object. If it is an

accessor property

, the function that is the value of the property's [[Get]] attribute must never return a 

strict

function

 when called.

Neither mapped nor unmapped arguments objects may be created with an own property named 

"caller"

.

The behaviour of built-in methods which are specified in ECMA-402, such as those named

toLocaleString

toLocaleString

, must not be extended except as specified in ECMA-402.

The RegExp pattern grammars in 

22.2.1

 and 

B.1.4

 must not be extended to recognize any of the source

characters A-Z or a-z as 

IdentityEscape

[+U]

 when the 

[U]

 grammar parameter is present.

The Syntactic Grammar must not be extended in any manner that allows the token 

::

 to immediately follow

source text that matches the 

BindingIdentifier

 nonterminal symbol.

When processing 

strict mode code

, the syntax of 

NumericLiteral

 must not be extended to include 

LegacyOctalIntegerLiteral

 and the syntax of 

DecimalIntegerLiteral

 must not be extended to include 

NonOctalDecimalIntegerLiteral

 as described in 

B.1.1

.

TemplateCharacter

 must not be extended to include 

LegacyOctalEscapeSequence

 or 

NonOctalDecimalEscapeSequence

as defined in 

B.1.2

.

When processing 

strict mode code

, the extensions defined in 

B.3.2

B.3.3

B.3.4

, and 

B.3.6

 must not be

supported.
When parsing for the 

Module

 

goal symbol

, the lexical grammar extensions defined in 

B.1.3

 must not be

supported.

ImportCall

 must not be extended.

There are certain built-in objects available whenever an ECMAScript 

Script

 or 

Module

 begins execution. One, the

global object

, is part of the global environment of the executing program. Others are accessible as initial properties of

the 

global object

 or indirectly as properties of accessible built-in objects.

Unless specified otherwise, a built-in object that is callable as a function is a built-in 

function object

 with the

characteristics described in 

10.3

. Unless specified otherwise, the [[Extensible]] internal slot of a built-in object initially

has the value 

true

. Every built-in 

function object

 has a [[Realm]] internal slot whose value is the 

Realm Record

 of the

realm

 for which the object was initially created.

Many built-in objects are functions: they can be invoked with arguments. Some of them furthermore are constructors:
they are functions intended for use with the 

new

new

 operator. For each built-in function, this specification describes the

arguments required by that function and the properties of that 

function object

. For each built-in 

constructor

, this

specification furthermore describes properties of the prototype object of that 

constructor

 and properties of specific

object instances returned by a 

new

new

 expression that invokes that 

constructor

.

18  ECMAScript Standard Built-in Objects

462

Unless otherwise specified in the description of a particular function, if a built-in function or 

constructor

 is given

fewer arguments than the function is specified to require, the function or 

constructor

 shall behave exactly as if it had

been given sufficient additional arguments, each such argument being the 

undefined

 value. Such missing arguments

are considered to be “not present” and may be identified in that manner by specification algorithms. In the description
of a particular function, the terms “

this

 value” and “NewTarget” have the meanings given in 

10.3

.

Unless otherwise specified in the description of a particular function, if a built-in function or 

constructor

 described is

given more arguments than the function is specified to allow, the extra arguments are evaluated by the call and then
ignored by the function. However, an implementation may define implementation specific behaviour relating to such
arguments as long as the behaviour is not the throwing of a 

TypeError

 exception that is predicated simply on the

presence of an extra argument.

NOTE 1

Unless otherwise specified every built-in function and every built-in 

constructor

 has the 

Function prototype object

,

which is the initial value of the expression 

Function.prototype

Function.prototype

 (

20.2.3

), as the value of its [[Prototype]] internal

slot.

Unless otherwise specified every built-in prototype object has the 

Object prototype object

, which is the initial value of

the expression 

Object.prototype

Object.prototype

 (

20.1.3

), as the value of its [[Prototype]] internal slot, except the 

Object

prototype object

 itself.

Built-in function objects that are not identified as constructors do not implement the [[Construct]] internal method
unless otherwise specified in the description of a particular function.

Each built-in function defined in this specification is created by calling the 

CreateBuiltinFunction

 abstract operation

(

10.3.3

). The values of the 

length

 and 

name

 parameters are the initial values of the 

"length"

 and 

"name"

 properties as

discussed below. The values of the 

prefix

 parameter are similarly discussed below.

Every built-in 

function object

, including constructors, has a 

"length"

 property whose value is a non-negative 

integral

Number

. Unless otherwise specified, this value is equal to the number of required parameters shown in the subclause

headings for the function description. Optional parameters and rest parameters are not included in the parameter
count.

NOTE 2

Unless otherwise specified, the 

"length"

 property of a built-in 

function object

 has the attributes { [[Writable]]: 

false

,

[[Enumerable]]: 

false

, [[Configurable]]: 

true

 }.

Every built-in 

function object

, including constructors, has a 

"name"

 property whose value is a String. Unless

otherwise specified, this value is the name that is given to the function in this specification. Functions that are
identified as anonymous functions use the empty String as the value of the 

"name"

 property. For functions that are

specified as properties of objects, the name value is the 

property name

 string used to access the function. Functions

that are specified as get or set accessor functions of built-in properties have 

"get"

 or 

"set"

 (respectively) passed to the

prefix

 parameter when calling 

CreateBuiltinFunction

.

Implementations that add additional capabilities to the set of built-in functions are encouraged to
do so by adding new functions rather than adding new parameters to existing functions.

For example, the 

function object

 that is the initial value of the 

"map"

 property of the 

Array

prototype object

 is described under the subclause heading «Array.prototype.map (callbackFn [ ,

thisArg])» which shows the two named arguments callbackFn and thisArg, the latter being
optional; therefore the value of the 

"length"

 property of that 

function object

 is 

1

𝔽

.

463

 

 

 

 

 

 

 

Content      ..     26      27      28      29     ..