Skip to content

Commit 699ce94

Browse files
littledanMs2ger
authored andcommitted
[jsapi] Normative: Always queue a task during asynchronous instantiation
JSC will have to do asynchronous compilation work during some instantiations. To be consistent, this PR always queues a task to complete instantiation, except through the synchronous Instance(module) API, to ensure consistency across platforms. This patch also cleans up the specification in various surrounding ways: - Include notes about APIs whose use is discouraged/may be limited Closes #741 See also webpack/webpack#6433
1 parent a11e588 commit 699ce94

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

document/js-api/index.bs

+15-12
Original file line numberDiff line numberDiff line change
@@ -474,13 +474,15 @@ The verification of WebAssembly type requirements is deferred to the
474474
1. Let |module| be |moduleObject|.\[[Module]].
475475
1. [=Read the imports=] of |module| with imports |importObject|, and let |imports| be the result.
476476
If this operation throws an exception, catch it, [=reject=] |promise| with the exception, and return |promise|.
477-
1. [=Queue a task=] to perform the following steps:
478-
1. [=Instantiate the core of a WebAssembly module=] |module| with |imports|, and let |instance| be the result.
479-
If this throws an exception, catch it, [=reject=] |promise| with the exception, and terminate these substeps.
480-
1. Let |instanceObject| be a [=/new=] {{Instance}}.
481-
1. [=initialize an instance object|Initialize=] |instanceObject| from |module| and |instance|.
482-
If this throws an exception, catch it, [=reject=] |promise| with the exception, and terminate these substeps.
483-
1. [=Resolve=] |promise| with |instanceObject|.
477+
1. Run the following steps [=in parallel=]:
478+
1. [=Queue a task=] to perform the following steps:
479+
Note: Implementation-specific work may be performed here.
480+
1. [=Instantiate the core of a WebAssembly module=] |module| with |imports|, and let |instance| be the result.
481+
If this throws an exception, catch it, [=reject=] |promise| with the exception, and terminate these substeps.
482+
1. Let |instanceObject| be a [=/new=] {{Instance}}.
483+
1. [=initialize an instance object|Initialize=] |instanceObject| from |module| and |instance|.
484+
If this throws an exception, catch it, [=reject=] |promise| with the exception, and terminate these substeps.
485+
1. [=Resolve=] |promise| with |instanceObject|.
484486
1. Return |promise|.
485487
</div>
486488

@@ -499,14 +501,15 @@ The verification of WebAssembly type requirements is deferred to the
499501

500502
1. Let |promise| be [=a new promise=].
501503
1. [=Upon fulfillment=] of |promiseOfModule| with value |module|:
502-
1. [=synchronously instantiate a WebAssembly module|Synchronously instantiate the WebAssembly module=] |module| importing |importObject|, and let |instance| be the result. If this throws an exception, catch it, [=reject=] |promise| with the exception, and abort these substeps.
503-
1. Let |result| be the {{WebAssemblyInstantiatedSource}} value «[ "{{WebAssemblyInstantiatedSource/module}}" → |module|, "{{WebAssemblyInstantiatedSource/instance}}" → |instance| ]».
504-
1. [=Resolve=] |promise| with |result|.
504+
1. [=asynchronously instantiate a WebAssembly module|Instantiate the WebAssembly module=] |module| importing |importObject|, and let |innerPromise| be the result.
505+
1. [=Upon fulfillment=] of |innerPromise| with value |instance|.
506+
1. Let |result| be the {{WebAssemblyInstantiatedSource}} value «[ "{{WebAssemblyInstantiatedSource/module}}" → |module|, "{{WebAssemblyInstantiatedSource/instance}}" → |instance| ]».
507+
1. [=Resolve=] |promise| with |result|.
508+
1. [=Upon rejection=] of |innerPromise| with reason |reason|:
509+
1. [=Reject=] |promise| with |reason|.
505510
1. [=Upon rejection=] of |promiseOfModule| with reason |reason|:
506511
1. [=Reject=] |promise| with |reason|.
507512
1. Return |promise|.
508-
509-
Note: It would be valid to perform certain parts of the instantiation [=in parallel=], but several parts need to happen in the event loop, including JavaScript operations to access the |importObject| and execution of the start function.
510513
</div>
511514

512515
<div algorithm>

0 commit comments

Comments
 (0)