From a195100ab56009213ee5dfe847e1bfda3bd577bf Mon Sep 17 00:00:00 2001 From: Daniel Ehrenberg Date: Sat, 2 Mar 2019 15:16:50 +0100 Subject: [PATCH] Editorial: Rebase on top of Cyclic Module Records --- spec.html | 289 ++++++++++++++++++++++++++++++------------------------ 1 file changed, 162 insertions(+), 127 deletions(-) diff --git a/spec.html b/spec.html index 2096325..52f402b 100644 --- a/spec.html +++ b/spec.html @@ -68,6 +68,80 @@

AsyncBlockStart ( _promiseCapability_, _asyncBody_, _asyncContext_ )

Abstract Module Records

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ Field Name + + Value Type + + Meaning +
+ [[Realm]] + + Realm Record | *undefined* + + The Realm within which this module was created. *undefined* if not yet assigned. +
+ [[Environment]] + + Lexical Environment | *undefined* + + The Lexical Environment containing the top level bindings for this module. This field is set when the module is instantiated. +
+ [[Namespace]] + + Object | *undefined* + + The Module Namespace Object () if one has been created for this module. Otherwise *undefined*. +
+ [[HostDefined]] + + Any, default value is *undefined*. + + Field reserved for use by host environments that need to associate additional information with a module. +
+ [[ExecPromise]] + + Promise | *undefined* + + The evaluation promise for this Abstract Module Record, including any dependency evaluations. +
+
@@ -118,18 +192,12 @@

Abstract Module Records

- -

Source Text Module Records

- -

A Source Text Module Record is used to represent information about a module that was defined from ECMAScript source text () that was parsed using the goal symbol |Module|. Its fields contain digested information about the names that are imported by the module and its concrete methods use this digest to link, instantiate, and evaluate the module.

- -

A Source Text Module Record can exist in a module graph with other subclasses of the abstract Module Record type. However, non-source text Module Records must not participate in dependency cycles with Source Text Module Records.

- -

In addition to the fields, defined in , Source Text Module Records have the additional fields listed in . Each of these fields is initially set in ParseModule.

+ +

Cyclic Module Records

- -
- + +
+ - - - - - - - - - - - - - - - + +
Field Name @@ -143,170 +211,98 @@

Source Text Module Records

- [[ECMAScriptCode]] - - a Parse Node - - The result of parsing the source text of this module using |Module| as the goal symbol. -
- [[RequestedModules]] - - List of String - - A List of all the |ModuleSpecifier| strings used by the module represented by this record to request the importation of a module. The List is source code occurrence ordered. -
- [[ImportEntries]] - - List of ImportEntry Records - - A List of ImportEntry records derived from the code of this module. -
- [[LocalExportEntries]] + [[Status]] - List of ExportEntry Records + String - A List of ExportEntry records derived from the code of this module that correspond to declarations that occur within the module. + Initially `"uninstantiated"`. Transitions to `"instantiating"`, `"instantiated"`, `"evaluating"`, `"evaluated"` (in that order) as the module progresses throughout its lifecycle.
- [[IndirectExportEntries]] + [[EvaluationError]] - List of ExportEntry Records + An abrupt completion | *undefined* - A List of ExportEntry records derived from the code of this module that correspond to reexported imports that occur within the module. + A completion of type ~throw~ representing the exception that occurred during evaluation. *undefined* if no exception occurred or if [[Status]] is not `"evaluated"`.
- [[StarExportEntries]] + [[DFSIndex]] - List of ExportEntry Records + Integer | *undefined* - A List of ExportEntry records derived from the code of this module that correspond to export * declarations that occur within the module. + Auxiliary field used during Instantiate and Evaluate only. + If [[Status]] is `"instantiating"` or `"evaluating"`, this nonnegative number records the point at which the module was first visited during the ongoing depth-first traversal of the dependency graph.
- [[Status]] + [[DFSAncestorIndex]] - String + Integer | *undefined* - Initially `"uninstantiated"`. Transitions to `"instantiating"`, `"instantiated"`, `"evaluating"`, `"evaluated"` (in that order) as the module progresses throughout its lifecycle. + Auxiliary field used during Instantiate and Evaluate only. If [[Status]] is `"instantiating"` or `"evaluating"`, this is either the module's own [[DFSIndex]] or that of an "earlier" module in the same strongly connected component.
- [[EvaluationError]] + [[RequestedModules]] - An abrupt completion | *undefined* + List of String - A completion of type ~throw~ representing the exception that occurred during evaluation. *undefined* if no exception occurred or if [[Status]] is not `"evaluated"`. + A List of all the |ModuleSpecifier| strings used by the module represented by this record to request the importation of a module. The List is source code occurrence ordered.
+
+

In addition to the methods defined in Cyclic Module Records have the additional methods listed in

+ + + - - - + + - - - -
- [[ExecPromise]] - - Promise | *undefined* - - The evaluation promise for this Abstract Module Record, including any dependency evaluations. - + Method + + Purpose +
- [[DFSIndex]] + InitializeEnvironment() - Integer | *undefined* - - Auxiliary field used during Instantiate and Evaluate only. - If [[Status]] is `"instantiating"` or `"evaluating"`, this non-negative number records the point at which the module was first visited during the ongoing depth-first traversal of the dependency graph. + Initialize the Lexical Environment of the module, including resolving all imported bindings.
- [[DFSAncestorIndex]] - - Integer | *undefined* + ExecuteModule( _promiseCapability_ ) - Auxiliary field used during Instantiate and Evaluate only. If [[Status]] is `"instantiating"` or `"evaluating"`, this is either the module's own [[DFSIndex]] or that of an "earlier" module in the same strongly connected component. + Initialize the execution context of the module and evaluate the module's code within it. Resolve or reject the given Promise capability when module evaluation completes.
-
- - -

ParseModule ( _sourceText_, _realm_, _hostDefined_ )

-

The abstract operation ParseModule with arguments _sourceText_, _realm_, and _hostDefined_ creates a Source Text Module Record based upon the result of parsing _sourceText_ as a |Module|. ParseModule performs the following steps:

- - 1. Assert: _sourceText_ is an ECMAScript source text (see clause ). - 1. Parse _sourceText_ using |Module| as the goal symbol and analyse the parse result for any Early Error conditions. If the parse was successful and no early errors were found, let _body_ be the resulting parse tree. Otherwise, let _body_ be a List of one or more *SyntaxError* or *ReferenceError* objects representing the parsing errors and/or early errors. Parsing and early error detection may be interweaved in an implementation-dependent manner. If more than one parsing error or early error is present, the number and ordering of error objects in the list is implementation-dependent, but at least one must be present. - 1. If _body_ is a List of errors, return _body_. - 1. Let _requestedModules_ be the ModuleRequests of _body_. - 1. Let _importEntries_ be ImportEntries of _body_. - 1. Let _importedBoundNames_ be ImportedLocalNames(_importEntries_). - 1. Let _indirectExportEntries_ be a new empty List. - 1. Let _localExportEntries_ be a new empty List. - 1. Let _starExportEntries_ be a new empty List. - 1. Let _exportEntries_ be ExportEntries of _body_. - 1. For each ExportEntry Record _ee_ in _exportEntries_, do - 1. If _ee_.[[ModuleRequest]] is *null*, then - 1. If _ee_.[[LocalName]] is not an element of _importedBoundNames_, then - 1. Append _ee_ to _localExportEntries_. - 1. Else, - 1. Let _ie_ be the element of _importEntries_ whose [[LocalName]] is the same as _ee_.[[LocalName]]. - 1. If _ie_.[[ImportName]] is `"*"`, then - 1. Assert: This is a re-export of an imported module namespace object. - 1. Append _ee_ to _localExportEntries_. - 1. Else this is a re-export of a single name, - 1. Append the ExportEntry Record { [[ModuleRequest]]: _ie_.[[ModuleRequest]], [[ImportName]]: _ie_.[[ImportName]], [[LocalName]]: *null*, [[ExportName]]: _ee_.[[ExportName]] } to _indirectExportEntries_. - 1. Else if _ee_.[[ImportName]] is `"*"`, then - 1. Append _ee_ to _starExportEntries_. - 1. Else, - 1. Append _ee_ to _indirectExportEntries_. - 1. Return Source Text Module Record { [[Realm]]: _realm_, [[Environment]]: *undefined*, [[Namespace]]: *undefined*, [[ExecPromise]]: *undefined*, [[Status]]: `"uninstantiated"`, [[EvaluationError]]: *undefined*, [[HostDefined]]: _hostDefined_, [[ECMAScriptCode]]: _body_, [[RequestedModules]]: _requestedModules_, [[ImportEntries]]: _importEntries_, [[LocalExportEntries]]: _localExportEntries_, [[IndirectExportEntries]]: _indirectExportEntries_, [[StarExportEntries]]: _starExportEntries_, [[DFSIndex]]: *undefined*, [[DFSAncestorIndex]]: *undefined* }. - - -

An implementation may parse module source text and analyse it for Early Error conditions prior to the evaluation of ParseModule for that module source text. However, the reporting of any errors must be deferred until the point where this specification actually performs ParseModule upon that source text.

-
-
- + + + -

Evaluate( ) Concrete Method

+

Evaluate ( ) Concrete Method

-

The Evaluate concrete method of a Source Text Module Record implements the corresponding Module Record abstract method.

+

The Evaluate concrete method of a Cyclic Module Record implements the corresponding Module Record abstract method.

Evaluate transitions this module's [[Status]] from `"instantiated"` to `"evaluated"`, at which point the [[ExecPromise]] Promise field is populated to a promise resolving on completion of the module execution, including its dependency executions, or the associated execution error..

If execution results in an exception, that exception is recorded in the [[EvaluationError]]rejection of the [[ExecPromise]] field and rethrown by future invocations of Evaluate.

@@ -337,7 +333,7 @@

Evaluate( ) Concrete Method

InnerModuleEvaluation( _module_, _stack_, _index_ )

-

The InnerModuleEvaluation abstract operation is used by Evaluate to perform the actual evaluation process for the Source Text Module Record _module_, as well as recursively on all other modules in the dependency graph. The _stack_ and _index_ parameters, as well as _module_'s [[DFSIndex]] and [[DFSAncestoreIndex]] fields, are used the same way as in InnerModuleInstantiation.

+

The InnerModuleEvaluation abstract operation is used by Evaluate to perform the actual evaluation process for the Cyclic Module Record _module_, as well as recursively on all other modules in the dependency graph. The _stack_ and _index_ parameters, as well as _module_'s [[DFSIndex]] and [[DFSAncestoreIndex]] fields, are used the same way as in InnerModuleInstantiation.

This abstract operation performs the following steps:

@@ -403,7 +399,7 @@

ExecuteModuleWhenImportsReady( _module_, _promises_, _capability_ )ExecuteModuleWhenImportsReady( _module_, _promises_, _capability_ ) + - -

ModuleExecution( _module_, _capability_)

+ +

Source Text Module Records

-

The ModuleExecution abstract operation is used by InnerModuleEvaluation to initialize the execution context of the module and evaluate the module's code within it.

+ +

ParseModule ( _sourceText_, _realm_, _hostDefined_ )

+

The abstract operation ParseModule with arguments _sourceText_, _realm_, and _hostDefined_ creates a Source Text Module Record based upon the result of parsing _sourceText_ as a |Module|. ParseModule performs the following steps:

+ + 1. Assert: _sourceText_ is an ECMAScript source text (see clause ). + 1. Parse _sourceText_ using |Module| as the goal symbol and analyse the parse result for any Early Error conditions. If the parse was successful and no early errors were found, let _body_ be the resulting parse tree. Otherwise, let _body_ be a List of one or more *SyntaxError* or *ReferenceError* objects representing the parsing errors and/or early errors. Parsing and early error detection may be interweaved in an implementation-dependent manner. If more than one parsing error or early error is present, the number and ordering of error objects in the list is implementation-dependent, but at least one must be present. + 1. If _body_ is a List of errors, return _body_. + 1. Let _requestedModules_ be the ModuleRequests of _body_. + 1. Let _importEntries_ be ImportEntries of _body_. + 1. Let _importedBoundNames_ be ImportedLocalNames(_importEntries_). + 1. Let _indirectExportEntries_ be a new empty List. + 1. Let _localExportEntries_ be a new empty List. + 1. Let _starExportEntries_ be a new empty List. + 1. Let _exportEntries_ be ExportEntries of _body_. + 1. For each ExportEntry Record _ee_ in _exportEntries_, do + 1. If _ee_.[[ModuleRequest]] is *null*, then + 1. If _ee_.[[LocalName]] is not an element of _importedBoundNames_, then + 1. Append _ee_ to _localExportEntries_. + 1. Else, + 1. Let _ie_ be the element of _importEntries_ whose [[LocalName]] is the same as _ee_.[[LocalName]]. + 1. If _ie_.[[ImportName]] is `"*"`, then + 1. Assert: This is a re-export of an imported module namespace object. + 1. Append _ee_ to _localExportEntries_. + 1. Else this is a re-export of a single name, + 1. Append the ExportEntry Record { [[ModuleRequest]]: _ie_.[[ModuleRequest]], [[ImportName]]: _ie_.[[ImportName]], [[LocalName]]: *null*, [[ExportName]]: _ee_.[[ExportName]] } to _indirectExportEntries_. + 1. Else if _ee_.[[ImportName]] is `"*"`, then + 1. Append _ee_ to _starExportEntries_. + 1. Else, + 1. Append _ee_ to _indirectExportEntries_. + 1. Return Source Text Module Record { [[Realm]]: _realm_, [[Environment]]: *undefined*, [[Namespace]]: *undefined*, [[ExecPromise]]: *undefined*, [[Status]]: `"uninstantiated"`, [[EvaluationError]]: *undefined*, [[HostDefined]]: _hostDefined_, [[ECMAScriptCode]]: _body_, [[RequestedModules]]: _requestedModules_, [[ImportEntries]]: _importEntries_, [[LocalExportEntries]]: _localExportEntries_, [[IndirectExportEntries]]: _indirectExportEntries_, [[StarExportEntries]]: _starExportEntries_, [[DFSIndex]]: *undefined*, [[DFSAncestorIndex]]: *undefined* }. + + +

An implementation may parse module source text and analyse it for Early Error conditions prior to the evaluation of ParseModule for that module source text. However, the reporting of any errors must be deferred until the point where this specification actually performs ParseModule upon that source text.

+
+
-

This abstract operation performs the following steps:

+ + +

ExecuteModule ( _capability_)

+ +

The ExecuteModule concrete method of a Source Text Module Record implements the corresponding Cyclic Module Record abstract method.

1. Let _moduleCxt_ be a new ECMAScript code execution context.