Skip to content

Commit f7c16f8

Browse files
authored
Draft spec text (#10)
Threw together some very simple draft spec text, which should be enough for a Stage 2 if there is interest.
1 parent ec7d57e commit f7c16f8

File tree

3 files changed

+24
-181
lines changed

3 files changed

+24
-181
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
Champions: [@styfle](https://github.com/styfle)
44

5+
Author(s): [@styfle](https://github.com/styfle), Guy Bedford
6+
57
Status: Stage 0.
68

79
Please leave any feedback in the [issues](https://github.com/styfle/proposal-import-bytes/issues), thanks!

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"private": true,
33
"scripts": {
44
"start": "npm run build-loose -- --watch",
5-
"build": "npm run build-loose -- --strict",
5+
"build": "npm run build-loose",
66
"build-loose": "node -e 'fs.mkdirSync(\"build\", { recursive: true })' && ecmarkup --load-biblio @tc39/ecma262-biblio --verbose spec.emu build/index.html --lint-spec"
77
},
88
"license": "MIT",

spec.emu

Lines changed: 21 additions & 180 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
<pre class="metadata">
77
title: Proposal Import Bytes
88
stage: 0
9-
contributors: Steven
9+
contributors: Steven, Guy Bedford
1010
</pre>
1111
<emu-intro id="intro">
1212
<h1>Proposal Import Bytes</h1>
1313
<p>See <a href="https://github.com/styfle/proposal-import-bytes/blob/main/README.md">the explainer</a> for information.</p>
1414
<emu-note type="editor">
15-
<p>This proposal is buit on top of the <a href="https://github.com/tc39/proposal-import-attributes">Import Attributes</a> proposal.</p>
15+
<p>This proposal is buit on top of the <a href="https://github.com/tc39/proposal-json-modules">JSON Modules</a> and <a href="https://github.com/tc39/proposal-immutable-arraybuffer">Immutable Array Buffer</a> proposals.</p>
1616
</emu-note>
1717
</emu-intro>
1818

@@ -56,9 +56,13 @@ contributors: Steven
5656
</ul>
5757
<p>then it must perform FinishLoadingImportedModule(_referrer_, _moduleRequest_, _payload_, _result_) with the same _result_ each time.</p>
5858
</li>
59-
<li>
60-
<p><ins>If _moduleRequest_.[[Attributes]] has an entry _entry_ such that _entry_.[[Key]] is *"type"* and _entry_.[[Value]] is *"json"*, the host environment must perform FinishLoadingImportedModule(_referrer_, _moduleRequest_, _payload_, _result_), where _result_ is either the Completion Record returned by an invokation of ParseJSONModule or a throw completion.</ins></p>
61-
</li>
59+
<li><p><del>If _moduleRequest_.[[Attributes]] has an entry _entry_ such that _entry_.[[Key]] is *"type"* and _entry_.[[Value]] is *"json"*, the host environment must perform FinishLoadingImportedModule(_referrer_, _moduleRequest_, _payload_, _result_), where _result_ is either the Completion Record returned by an invokation of ParseJSONModule or a throw completion.</del></p></li>
60+
<li><p><ins>If _moduleRequest_.[[Attributes]] has an entry _entry_ such that _entry_.[[Key]] is *"type"*, then</ins></p></li>
61+
<ol>
62+
<li><p><ins>Let _type_ be _entry_.[[Value]].</ins></p></li>
63+
<li><p><ins>If _type_ is *"json"*, the host environment must perform FinishLoadingImportedModule(_referrer_, _moduleRequest_, _payload_, _result_), where _result_ is either the Completion Record returned by an invokation of ParseJSONModule or a throw completion.</ins></p></li>
64+
<li><p><ins>If _type_ is *"buffer"*, the host environment must perform FinishLoadingImportedModule(_referrer_, _moduleRequest_, _payload_, _result_), where _result_ is either the Completion Record returned by an invokation of CreateBufferModule or a throw completion.</ins></p></li>
65+
</ol>
6266
<li>
6367
The operation must treat _payload_ as an opaque value to be passed through to FinishLoadingImportedModule.
6468
</li>
@@ -67,11 +71,11 @@ contributors: Steven
6771
<p>The actual process performed is host-defined, but typically consists of performing whatever I/O operations are necessary to load the appropriate Module Record. Multiple different (_referrer_, _moduleRequest_.[[Specifer]], _moduleRequest_.[[Attributes]]) triples may map to the same Module Record instance. The actual mapping semantics 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 expansion of relative and abbreviated path specifiers.</p>
6872

6973
<emu-note>
70-
<p><ins>The above text implies that hosts *must* support JSON modules imported with `type: "json"` (if it completes normally), but it doesn't prohibit hosts from supporting JSON modules imported with no type specified. Some environments (for example, web browsers) plan to require `with { type: "json" }`, and environments which want to restrict themselves to a compatible subset would do so as well.</ins></p>
74+
<p>The above text implies that hosts *must* support JSON modules <ins>and buffer modules</ins> imported with `type: "json"` <ins>and `type: "buffer"` respectively </ins>(if it completes normally), but it doesn't prohibit hosts from supporting JSON modules imported with no type specified. Some environments (for example, web browsers) plan to require `with { type: "json" }`, and environments which want to restrict themselves to a compatible subset would do so as well.</p>
7175
</emu-note>
7276

7377
<emu-note>
74-
<p><ins>All of the import statements in the module graph that address the same JSON module may evaluate to the same mutable object.</ins></p>
78+
<p>All of the import statements in the module graph that address the same JSON <ins>or buffer </ins>module may evaluate to the same mutable object.</p>
7579
</emu-note>
7680
</emu-clause>
7781

@@ -80,7 +84,7 @@ contributors: Steven
8084

8185
<p>A <dfn variants="Synthetic Module Records">Synthetic Module Record</dfn> 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.</p>
8286

83-
<emu-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.</emu-note>
87+
<emu-note>A Synthetic Module Record could be used for defining a variety of module types: for example, built-in modules, or JSON modules, <ins>or buffer modules, </ins>or CSS modules.</emu-note>
8488

8589
<p>In addition to the fields defined in <emu-xref href="#table-module-record-fields"></emu-xref> Synthetic Module Records have the additional fields listed in <emu-xref href="#table-synthetic-module-record-fields"></emu-xref>. Each of these fields is initially set in CreateSyntheticModule.</p>
8690

@@ -106,186 +110,23 @@ contributors: Steven
106110
</table>
107111
</emu-table>
108112

109-
<emu-clause id="sec-createsyntheticmodule" type="abstract operation">
110-
<h1>
111-
CreateSyntheticModule (
112-
_exportNames_: a List of Strings without duplicates,
113-
_evaluationSteps_: an Abstract Closure,
114-
_realm_: a Realm Record,
115-
): a Synthetic Module Record
116-
</h1>
117-
<dl class="header">
118-
<dt>description</dt>
119-
<dd>It creates a Synthetic Module Record based upon the given exported names and evaluation steps.</dd>
120-
</dl>
121-
122-
<emu-alg>
123-
1. Return Synthetic Module Record { [[Realm]]: _realm_, [[Environment]]: ~empty~, [[Namespace]]: ~empty~, [[HostDefined]]: ~empty~, [[ExportNames]]: _exportNames_, [[EvaluationSteps]]: _evaluationSteps_ }.
124-
</emu-alg>
125-
126-
<emu-note type="editor">It seems we could set up the environment either here or in Link(). I've chosen to do so in Link() for symmetry with Cyclic Module Records (and thus Source Text Module Records), but I don't think there's any actual requirement in that regard.</emu-note>
127-
</emu-clause>
128-
129-
<emu-clause id="sec-setsyntheticmoduleexport" type="abstract operation">
113+
<emu-clause id="sec-create-buffer-module" type="abstract operation">
130114
<h1>
131-
SetSyntheticModuleExport (
132-
_module_: a Synthetic Module Record,
133-
_exportName_: a String,
134-
_exportValue_: an ECMAScript Language value
135-
): ~unused~
136-
</h1>
137-
<dl class="header">
138-
<dt>description</dt>
139-
<dd>It can be used to set or change the exported value for a pre-established export of a Synthetic Module Record.</dd>
140-
</dl>
141-
142-
<emu-alg>
143-
1. Let _envRec_ be _module_.[[Environment]].
144-
1. Assert: _envRec_ is not ~empty~.
145-
1. Perform _envRec_.SetMutableBinding(_exportName_, _exportValue_, *true*).
146-
1. Return ~unused~.
147-
</emu-alg>
148-
</emu-clause>
149-
150-
<emu-clause id="sec-smr-concrete-methods">
151-
<h1>Concrete Methods</h1>
152-
153-
<p>The following are the concrete methods for Synthetic Module Record that implement the corresponding Module Record abstract methods.</p>
154-
155-
<emu-note type="editor">I find having this wrapping sub-clause cleaner and suggest we do the same for Source Text Module Records in the main spec.</emu-note>
156-
157-
<emu-clause id="sec-smr-LoadRequestedModules" type="concrete method">
158-
<h1>
159-
LoadRequestedModules (): a Promise
160-
</h1>
161-
<dl class="header">
162-
<dt>for</dt>
163-
<dd>a Synthetic Module Record _module_</dd>
164-
</dl>
165-
166-
<emu-alg>
167-
1. Return ! PromiseResolve(%Promise%, *undefined*).
168-
</emu-alg>
169-
170-
<emu-note>
171-
Synthetic Module Records have no dependencies.
172-
</emu-note>
173-
</emu-clause>
174-
175-
<emu-clause id="sec-smr-getexportednames" type="concrete method">
176-
<h1>
177-
GetExportedNames (): a List of Strings
178-
</h1>
179-
<dl class="header">
180-
<dt>for</dt>
181-
<dd>a Synthetic Module Record _module_</dd>
182-
</dl>
183-
184-
<emu-alg>
185-
1. Return _module_.[[ExportNames]].
186-
</emu-alg>
187-
</emu-clause>
188-
189-
<emu-clause id="sec-smr-resolveexport" type="concrete method">
190-
<h1>
191-
ResolveExport(
192-
_exportName_: a String,
193-
): a ResolvedBinding Record or *null*
194-
</h1>
195-
<dl class="header">
196-
<dt>for</dt>
197-
<dd>a Synthetic Module Record _module_</dd>
198-
</dl>
199-
200-
<emu-alg>
201-
1. If _module_.[[ExportNames]] does not contain _exportName_, return *null*.
202-
1. Return ResolvedBinding Record { [[Module]]: _module_, [[BindingName]]: _exportName_ }.
203-
</emu-alg>
204-
</emu-clause>
205-
206-
<emu-clause id="sec-smr-Link" type="concrete method">
207-
<h1>Link ( ): ~unused~</h1>
208-
<dl class="header">
209-
<dt>for</dt>
210-
<dd>a Synthetic Module Record _module_</dd>
211-
</dl>
212-
213-
<emu-alg>
214-
1. Let _realm_ be _module_.[[Realm]].
215-
1. Let _env_ be NewModuleEnvironment(_realm_.[[GlobalEnv]]).
216-
1. Set _module_.[[Environment]] to _env_.
217-
1. For each String _exportName_ in _module_.[[ExportNames]], do
218-
1. Perform ! _env_.CreateMutableBinding(_exportName_, *false*).
219-
1. Perform ! _env_.InitializeBinding(_exportName_, *undefined*).
220-
1. Return ~unused~.
221-
</emu-alg>
222-
</emu-clause>
223-
224-
<emu-clause id="sec-smr-Evaluate" type="concrete method">
225-
<h1>Evaluate ( ): a Promise</h1>
226-
<dl class="header">
227-
<dt>for</dt>
228-
<dd>a Synthetic Module Record _module_</dd>
229-
</dl>
230-
231-
<emu-alg>
232-
1. Let _moduleContext_ be a new ECMAScript code execution context.
233-
1. Set the Function of _moduleContext_ to *null*.
234-
1. Set the Realm of _moduleContext_ to _module_.[[Realm]].
235-
1. Set the ScriptOrModule of _moduleContext_ to _module_.
236-
1. Set the VariableEnvironment of _moduleContext_ to _module_.[[Environment]].
237-
1. Set the LexicalEnvironment of _moduleContext_ to _module_.[[Environment]].
238-
1. Suspend the currently running execution context.
239-
1. Push _moduleContext_ on to the execution context stack; _moduleContext_ is now the running execution context.
240-
1. Let _steps_ be _module_.[[EvaluationSteps]].
241-
1. Let _result_ be Completion(_steps_(_module_)).
242-
1. Suspend _moduleContext_ and remove it from the execution context stack.
243-
1. Resume the context that is now on the top of the execution context stack as the running execution context.
244-
1. Let _pc_ be ! NewPromiseCapability(%Promise%).
245-
1. IfAbruptRejectPromise(_result_, _pc_).
246-
1. Perform ! _pc_.[[Resolve]](_result_).
247-
1. Return _pc_.[[Promise]].
248-
</emu-alg>
249-
</emu-clause>
250-
</emu-clause>
251-
252-
<emu-clause id="sec-create-default-export-synthetic-module" type="abstract operation">
253-
<h1>
254-
CreateDefaultExportSyntheticModule (
255-
_defaultExport_: an ECMAScript Language value,
256-
): a Synthetic Module Record
257-
</h1>
258-
<dl class="header">
259-
<dt>description</dt>
260-
<dd>It creates a Synthetic Module Record whose default export is _defaultExport_.</dd>
261-
</dl>
262-
<emu-alg>
263-
1. Let _realm_ be the current Realm Record.
264-
1. Let _setDefaultExport_ be a new Abstract Closure with parameters (_module_) that captures _defaultExport_ and performs the following steps when called:
265-
1. Perform SetSyntheticModuleExport(_module_, *"default"*, _defaultExport_).
266-
1. Return CreateSyntheticModule(« *"default"* », _setDefaultExport_, _realm_).
267-
</emu-alg>
268-
</emu-clause>
269-
270-
<emu-clause id="sec-parse-json-module" type="abstract operation">
271-
<h1>
272-
ParseJSONModule (
273-
_source_: a String
274-
): either a normal completion containing a Synthetic Module Record, or a throw completion
115+
<ins>
116+
CreateBufferModule (
117+
_arrayBuffer_: an immutable ArrayBuffer or a SharedArrayBuffer
118+
): a Synthetic Module Record
119+
</ins>
275120
</h1>
276121
<dl class="header">
277122
<dt>description</dt>
278123
<dd></dd>
279124
</dl>
280125

281126
<emu-alg>
282-
1. Let _json_ be ? Call(%JSON.parse%, *undefined*, « _source_ »).
283-
1. Return CreateDefaultExportSyntheticModule(_json_).
127+
1. Assert: IsImmutableBuffer(_arrayBuffer_) is *true*.
128+
1. Return CreateDefaultExportSyntheticModule(_arrayBuffer_).
284129
</emu-alg>
285-
286-
<emu-note type="editor">
287-
TODO: Refactor JSONParse into an abstract algorithm.
288-
</emu-note>
289130
</emu-clause>
290131
</emu-clause>
291-
</emu-clause>
132+
</emu-clause>

0 commit comments

Comments
 (0)