From 5c7afbea9cab28f6afe35fb65b4cd8f02349d927 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Thu, 9 May 2019 13:07:23 +0200 Subject: [PATCH 1/2] Define Synthetic Module Records Based on text written by Domenic at . --- index.bs | 176 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 176 insertions(+) diff --git a/index.bs b/index.bs index 5aba1f92..f2ca1e0a 100644 --- a/index.bs +++ b/index.bs @@ -34,6 +34,7 @@ spec: url; type: interface; text: URL spec: dom; type: interface; text: Document spec: ecma-262; type: dfn; for: /; text: internal method spec: ecma-262; type: dfn; for: /; text: internal slot +spec: ecma-262; type: dfn; for: /; text:realm
@@ -125,6 +126,10 @@ urlPrefix: https://tc39.github.io/ecma262/; spec: ECMA-262
         text: CreateSetIterator; url: sec-createsetiterator
         text: DefinePropertyOrThrow; url: sec-definepropertyorthrow
         text: DetachArrayBuffer; url: sec-detacharraybuffer
+        for: Environment Record; url: table-15
+            text: SetMutableBinding
+            text: CreateMutableBinding
+            text: InitializeBinding
         text: Get; url: sec-get-o-p
         text: GetFunctionRealm; url: sec-getfunctionrealm
         text: GetIterator; url: sec-getiterator
@@ -138,6 +143,7 @@ urlPrefix: https://tc39.github.io/ecma262/; spec: ECMA-262
         text: IsSharedArrayBuffer; url: sec-issharedarraybuffer
         text: IteratorStep; url: sec-iteratorstep
         text: IteratorValue; url: sec-iteratorvalue
+        text: NewModuleEnvironment; url: sec-newmoduleenvironment
         text: NormalCompletion; url: sec-normalcompletion
         text: ObjectCreate; url: sec-objectcreate
         text: OrdinaryDefineOwnProperty; url: sec-ordinarydefineownproperty
@@ -181,15 +187,27 @@ urlPrefix: https://tc39.github.io/ecma262/; spec: ECMA-262
         text: constructor; url: constructor
         text: conventions; for: ECMAScript; url: sec-algorithm-conventions
         text: current Realm; url: current-realm
+        text: ECMAScript code execution context; url: sec-execution-contexts
+        for: ECMAScript code execution context; url: table-23
+            text: LexicalEnvironment
+            text: VariableEnvironment
         text: element; for: ECMAScript String; url: sec-ecmascript-language-types-string-type
         text: enumerable; url: sec-property-attributes
+        text: EnvironmentRecord; for: Lexical Environment; url: sec-lexical-environments
         text: equally close values; url: sec-ecmascript-language-types-number-type
         text: error objects; for: ECMAScript; url: sec-error-objects
+        for: Execution context; url: table-22
+            text: Function
+            text: Realm
+            text: ScriptOrModule
+        text: execution context stack; url: execution-context-stack
         text: function object; url: function-object
         text: immutable prototype exotic object; url: sec-immutable-prototype-exotic-objects
         url: sec-object-internal-methods-and-internal-slots
             text: internal method
             text: internal slot
+        text: Module Record; url: sec-abstract-module-records
+        text: Module Record Fields; url: table-36
         text: Number type; url: sec-ecmascript-language-types-number-type
         text: Object; for: ECMAScript; url: sec-object-type
         for: ordinary object; url: sec-ordinary-object-internal-methods-and-internal-slots
@@ -198,6 +216,8 @@ urlPrefix: https://tc39.github.io/ecma262/; spec: ECMA-262
         text: own property; url: sec-own-property
         text: Property Descriptor; url: sec-property-descriptor-specification-type
         text: realm; url: realm
+        text: ResolvedBinding Record; url: resolvedbinding-record
+        text: running execution context; url: running-execution-context
 
@@ -13244,6 +13264,162 @@ the exact steps to take if an exception was thrown, or by explicitly
 
 
 
+

Synthetic module records

+ +A Synthetic Module Record is used to represent information about a module that is +defined by specifications. +Its exports are derived from a pair of lists, of string keys and of ECMAScript values. +The set of exported names is static, and determined at creation time (as an argument to +[$CreateSyntheticModule$]), while the set of exported values can be changed over time using +[$SetSyntheticModuleExport$]. +It has no imports or dependencies. + +Note: A [=Synthetic Module Record=] could be used for defining a variety of module types: for +example, built-in modules, or JSON modules, or CSS modules. + +In addition to the [=Module Record Fields=], Synthetic Module Records have the additional fields +listed below. +Each of these fields is initially set in [$CreateSyntheticModule$]. + + + + + + + + +
Additional Fields of Synthetic Module Records
Field Name + Value Type + Meaning +
\[[ExportNames]] + List of String + A List of all names that are exported. +
\[[EvaluationSteps]] + An abstract operation + An abstract operation that will be performed upon evaluation of the module, taking the + [=Synthetic Module Record=] as its sole argument. + These will usually set up the exported values, by using [$SetSyntheticModuleExport$]. + They must not modify \[[ExportNames]]. + They may return an abrupt completion. +
+ +

CreateSyntheticModule

+ +
+The abstract operation CreateSyntheticModule(|exportNames|, |evaluationSteps|, |realm|, |hostDefined|) creates a [=Synthetic Module Record=] based upon +the given exported names and evaluation steps. +It performs the following steps: + + 1. Return [=Synthetic Module Record=] { + \[[Realm]]: |realm|, + \[[Environment]]: undefined, + \[[Namespace]]: undefined, + \[[HostDefined]]: |hostDefined|, + \[[ExportNames]]: |exportNames|, + \[[EvaluationSteps]]: |evaluationSteps| + }. +
+ +Note: It seems we could set up the environment either here or in Instantiate(). +It is done in Instantiate() for symmetry with Source Text Module Records, but there doesn't seem to +be any actual requirement in that regard. + +

SetSyntheticModuleExport

+ +
+The abstract operation SetSyntheticModuleExport(|module|, |exportName|, +|exportValue|) can be used to set or change the exported value for a pre-established export of a +Synthetic Module Record. +It performs the following steps: + + 1. Let |envRec| be |module|.\[[Environment]]'s [=Lexical Environment/EnvironmentRecord=]. + 1. Perform |envRec|.[$Environment Record/SetMutableBinding$](|exportName|, |exportValue|, + true). +
+ +

Concrete Methods

+ +The following are the concrete methods for [=Synthetic Module Record=] that implement the +corresponding [=Module Record=] abstract methods. + +
GetExportedNames
+ +
+The GetExportedNames(exportStarSet) concrete method of a [=Synthetic Module Record=] implements the +corresponding [=Module Record=] abstract method. + +It performs the following steps: + + 1. Let |module| be this [=Synthetic Module Record=]. + 1. Return |module|.\[[ExportNames]]. +
+ +
ResolveExport
+ +
+The ResolveExport(|exportName|, resolveSet) concrete method of a [=Synthetic Module Record=] implements the +corresponding [=Module Record=] abstract method. + +It performs the following steps: + + 1. Let |module| be this [=Synthetic Module Record=]. + 1. If |module|.\[[ExportNames]] does not contain |exportName|, return null. + 1. Return [=ResolvedBinding Record=] { \[[Module]]: |module|, \[[BindingName]]: |exportName| }. +
+ +
Instantiate
+ +
+The Instantiate() concrete method of a +[=Synthetic Module Record=] implements the corresponding [=Module Record=] abstract method. + +It performs the following steps: + + 1. Let |module| be this [=Synthetic Module Record=]. + 1. Let |realm| be |module|.\[[Realm]]. + 1. Assert: |realm| is not undefined. + 1. Let |env| be [$NewModuleEnvironment$](|realm|.\[[GlobalEnv]]). + 1. Set |module|.\[[Environment]] to |env|. + 1. Let |envRec| be |env|'s [=Lexical Environment/EnvironmentRecord=]. + 1. For each |exportName| in |module|.\[[ExportNames]], + 1. Perform [=!=] |envRec|.[$Environment Record/CreateMutableBinding$](|exportName|, + false). + 1. Perform [=!=] |envRec|.[$Environment Record/InitializeBinding$](|exportName|, + undefined). + 1. Return undefined. +
+ +
Evaluate
+ +
+The Evaluate() concrete method of a +[=Synthetic Module Record=] implements the corresponding [=Module Record=] abstract method. + +It performs the following steps: + + 1. Let |module| be this [=Synthetic Module Record=]. + 1. Let |moduleCxt| be a new [=ECMAScript code execution context=]. + 1. Set the [=Execution context/Function=] of |moduleCxt| to null. + 1. Assert: |module|.\[[Realm]] is not undefined. + 1. Set the [=Execution context/Realm=] of |moduleCxt| to |module|.\[[Realm]]. + 1. Set the [=Execution context/ScriptOrModule=] of |moduleCxt| to |module|. + 1. Set the [=ECMAScript code execution context/VariableEnvironment=] of |moduleCxt| to + |module|.\[[Environment]]. + 1. Set the [=ECMAScript code execution context/LexicalEnvironment=] of |moduleCxt| to + |module|.\[[Environment]]. + 1. Suspend the currently [=running execution context=]. + 1. Push |moduleCxt| on to the [=execution context stack=]; |moduleCxt| is now the + [=running execution context=]. + 1. Let |completion| be the result of performing |module|.\[[EvaluationSteps]](|module|). + 1. Suspend |moduleCxt| and remove it from the [=execution context stack=]. + 1. Resume the context that is now on the top of the [=execution context stack=] as the + [=running execution context=]. + 1. Return [$Completion$](|completion|). +
+ +

Common definitions

This section specifies some common definitions that all From 2e6b8d0900820aaef2a911cb8f7ae1531f5a1712 Mon Sep 17 00:00:00 2001 From: Domenic Denicola Date: Thu, 9 May 2019 11:18:16 -0400 Subject: [PATCH 2/2] Nit and Bikeshed warning fixes --- index.bs | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/index.bs b/index.bs index f2ca1e0a..5d9ad982 100644 --- a/index.bs +++ b/index.bs @@ -215,6 +215,7 @@ urlPrefix: https://tc39.github.io/ecma262/; spec: ECMA-262 text: internal slot text: own property; url: sec-own-property text: Property Descriptor; url: sec-property-descriptor-specification-type + text: Source Text Module Record; url: sourctextmodule-record text: realm; url: realm text: ResolvedBinding Record; url: resolvedbinding-record text: running execution context; url: running-execution-context @@ -224,6 +225,10 @@ urlPrefix: https://tc39.github.io/ecma262/; spec: ECMA-262 { "GEOMETRY": { "aliasOf": "GEOMETRY-1" + }, + "JSSTDLIB": { + "href": "https://github.com/tc39/proposal-javascript-standard-library/", + "title": "Standard Library Proposal" } }
@@ -13268,7 +13273,6 @@ the exact steps to take if an exception was thrown, or by explicitly A Synthetic Module Record is used to represent information about a module that is defined by specifications. -Its exports are derived from a pair of lists, of string keys and of ECMAScript values. The set of exported names is static, and determined at creation time (as an argument to [$CreateSyntheticModule$]), while the set of exported values can be changed over time using [$SetSyntheticModuleExport$]. @@ -13277,6 +13281,10 @@ It has no imports or dependencies. Note: A [=Synthetic Module Record=] could be used for defining a variety of module types: for example, built-in modules, or JSON modules, or CSS modules. +Note: [=Synthetic Module Records=] are being developed in concert with the authors of the +JavaScript Standard Library proposal, and might eventually move to the ECMAScript +specification. [[JSSTDLIB]] [[ECMA-262]]. + In addition to the [=Module Record Fields=], Synthetic Module Records have the additional fields listed below. Each of these fields is initially set in [$CreateSyntheticModule$]. @@ -13303,7 +13311,7 @@ Each of these fields is initially set in [$CreateSyntheticModule$]. They may return an abrupt completion. -

CreateSyntheticModule

+

CreateSyntheticModule

The abstract operation CreateSyntheticModule(|exportNames|, |evaluationSteps|, |realm|, |hostDefined|) creates a [=Synthetic Module Record=] based upon @@ -13320,11 +13328,11 @@ It performs the following steps: }.
-Note: It seems we could set up the environment either here or in Instantiate(). -It is done in Instantiate() for symmetry with Source Text Module Records, but there doesn't seem to -be any actual requirement in that regard. +Note: we could set up \[[Environment]] either here or in [$Synthetic Module Record/Instantiate$](). +It is done in [$Synthetic Module Record/Instantiate$]() for symmetry with [=Source Text Module Records=], +but there is no observable difference. -

SetSyntheticModuleExport

+

SetSyntheticModuleExport

The abstract operation SetSyntheticModuleExport(|module|, |exportName|, @@ -13342,7 +13350,7 @@ It performs the following steps: The following are the concrete methods for [=Synthetic Module Record=] that implement the corresponding [=Module Record=] abstract methods. -
GetExportedNames
+
GetExportedNames
The GetExportedNames( -
ResolveExport
+
ResolveExport
The ResolveExport(|exportName|, -
Instantiate
+
Instantiate
The Instantiate() concrete method of a @@ -13391,7 +13399,7 @@ It performs the following steps: 1. Return undefined.
-
Evaluate
+
Evaluate
The Evaluate() concrete method of a