Skip to content

Commit e9b984c

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 36d828d commit e9b984c

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

document/js-api/index.bs

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -425,13 +425,15 @@ A {{Module}} object represents a single WebAssembly module. Each {{Module}} obje
425425
1. Let |module| be |moduleObject|.\[[Module]].
426426
1. [=Read the imports=] of |module| with imports |importObject|, and let |imports| be the result.
427427
If this operation throws an exception, catch it, [=reject=] |promise| with the exception, and return |promise|.
428-
1. [=Queue a task=] to perform the following steps:
429-
1. [=Instantiate the core of a WebAssembly module=] |module| with |imports|, and let |instance| be the result.
430-
If this throws an exception, catch it, [=reject=] |promise| with the exception, and terminate these substeps.
431-
1. Let |instanceObject| be a [=/new=] {{Instance}}.
432-
1. [=initialize an instance object|Initialize=] |instanceObject| from |module| and |instance|.
433-
If this throws an exception, catch it, [=reject=] |promise| with the exception, and terminate these substeps.
434-
1. [=Resolve=] |promise| with |instanceObject|.
428+
1. Run the following steps [=in parallel=]:
429+
1. [=Queue a task=] to perform the following steps:
430+
Note: Implementation-specific work may be performed here.
431+
1. [=Instantiate the core of a WebAssembly module=] |module| with |imports|, and let |instance| be the result.
432+
If this throws an exception, catch it, [=reject=] |promise| with the exception, and terminate these substeps.
433+
1. Let |instanceObject| be a [=/new=] {{Instance}}.
434+
1. [=initialize an instance object|Initialize=] |instanceObject| from |module| and |instance|.
435+
If this throws an exception, catch it, [=reject=] |promise| with the exception, and terminate these substeps.
436+
1. [=Resolve=] |promise| with |instanceObject|.
435437
1. Return |promise|.
436438
</div>
437439

@@ -450,14 +452,15 @@ A {{Module}} object represents a single WebAssembly module. Each {{Module}} obje
450452

451453
1. Let |promise| be [=a new promise=]
452454
1. [=Upon fulfillment=] of |promiseOfModule| with value |module|:
453-
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.
454-
1. Let |result| be a {{WebAssemblyInstantiatedSource}} dictionary with {{WebAssemblyInstantiatedSource/module}} set to |module| and {{WebAssemblyInstantiatedSource/instance}} set to |instance|.
455-
1. [=Resolve=] |promise| with |result|.
455+
1. [=asynchronously instantiate a WebAssembly module|Instantiate the WebAssembly module=] |module| importing |importObject|, and let |innerPromise| be the result.
456+
1. [=Upon fulfillment=] of |innerPromise| with value |instance|.
457+
1. Let |result| be a {{WebAssemblyInstantiatedSource}} dictionary with {{WebAssemblyInstantiatedSource/module}} set to |module| and {{WebAssemblyInstantiatedSource/instance}} set to |instance|.
458+
1. [=Resolve=] |promise| with |result|.
459+
1. [=Upon rejection=] of |innerPromise| with reason |reason|:
460+
1. [=Reject=] |promise| with |reason|.
456461
1. [=Upon rejection=] of |promiseOfModule| with reason |reason|:
457462
1. [=Reject=] |promise| with |reason|.
458463
1. Return |promise|.
459-
460-
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.
461464
</div>
462465

463466
<div algorithm>

0 commit comments

Comments
 (0)