You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Apr 25, 2025. It is now read-only.
Copy file name to clipboardExpand all lines: document/js-api/index.bs
+20-13Lines changed: 20 additions & 13 deletions
Original file line number
Diff line number
Diff line change
@@ -496,18 +496,20 @@ The verification of WebAssembly type requirements is deferred to the
496
496
1. Let |module| be |moduleObject|.\[[Module]].
497
497
1. [=Read the imports=] of |module| with imports |importObject|, and let |imports| be the result.
498
498
If this operation throws an exception, catch it, [=reject=] |promise| with the exception, and return |promise|.
499
-
1. [=Queue a task=] to perform the following steps:
500
-
1. [=Instantiate the core of a WebAssembly module=] |module| with |imports|, and let |instance| be the result.
501
-
If this throws an exception, catch it, [=reject=] |promise| with the exception, and terminate these substeps.
502
-
1. Let |instanceObject| be a [=/new=]{{Instance}}.
503
-
1. [=initialize an instance object|Initialize=] |instanceObject| from |module| and |instance|.
504
-
If this throws an exception, catch it, [=reject=] |promise| with the exception, and terminate these substeps.
505
-
1. [=Resolve=] |promise| with |instanceObject|.
499
+
1. Run the following steps [=in parallel=]:
500
+
1. [=Queue a task=] to perform the following steps:
501
+
Note: Implementation-specific work may be performed here.
502
+
1. [=Instantiate the core of a WebAssembly module=] |module| with |imports|, and let |instance| be the result.
503
+
If this throws an exception, catch it, [=reject=] |promise| with the exception, and terminate these substeps.
504
+
1. Let |instanceObject| be a [=/new=]{{Instance}}.
505
+
1. [=initialize an instance object|Initialize=] |instanceObject| from |module| and |instance|.
506
+
If this throws an exception, catch it, [=reject=] |promise| with the exception, and terminate these substeps.
507
+
1. [=Resolve=] |promise| with |instanceObject|.
506
508
1. Return |promise|.
507
509
</div>
508
510
509
511
<div algorithm="instantiate">
510
-
To <dfn>instantiate a WebAssembly module</dfn> from a {{Module}} |moduleObject| and imports |importObject|, perform the following steps:
512
+
To <dfn>synchronously instantiate a WebAssembly module</dfn> from a {{Module}} |moduleObject| and imports |importObject|, perform the following steps:
511
513
1. Let |module| be |moduleObject|.\[[Module]].
512
514
1. [=Read the imports=] of |module| with imports |importObject|, and let |imports| be the result.
513
515
1. [=Instantiate the core of a WebAssembly module=] |module| with |imports|, and let |instance| be the result.
@@ -521,14 +523,15 @@ The verification of WebAssembly type requirements is deferred to the
521
523
522
524
1. Let |promise| be [=a new promise=].
523
525
1. [=Upon fulfillment=] of |promiseOfModule| with value |module|:
524
-
1. [=instantiate a WebAssembly module|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.
525
-
1. Let |result| be the {{WebAssemblyInstantiatedSource}} value «[ "{{WebAssemblyInstantiatedSource/module}}" → |module|, "{{WebAssemblyInstantiatedSource/instance}}" → |instance| ]».
526
-
1. [=Resolve=] |promise| with |result|.
526
+
1. [=asynchronously instantiate a WebAssembly module|Instantiate the WebAssembly module=] |module| importing |importObject|, and let |innerPromise| be the result.
527
+
1. [=Upon fulfillment=] of |innerPromise| with value |instance|.
528
+
1. Let |result| be the {{WebAssemblyInstantiatedSource}} value «[ "{{WebAssemblyInstantiatedSource/module}}" → |module|, "{{WebAssemblyInstantiatedSource/instance}}" → |instance| ]».
529
+
1. [=Resolve=] |promise| with |result|.
530
+
1. [=Upon rejection=] of |innerPromise| with reason |reason|:
531
+
1. [=Reject=] |promise| with |reason|.
527
532
1. [=Upon rejection=] of |promiseOfModule| with reason |reason|:
528
533
1. [=Reject=] |promise| with |reason|.
529
534
1. Return |promise|.
530
-
531
-
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.
532
535
</div>
533
536
534
537
<div algorithm>
@@ -628,6 +631,8 @@ interface Module {
628
631
1. If |module| is [=error=], throw a {{CompileError}} exception.
629
632
1. Set **this**.\[[Module]] to |module|.
630
633
1. Set **this**.\[[Bytes]] to |stableBytes|.
634
+
635
+
Note: Some implementations enforce a size limitation on |bytes|. Use of this API is discouraged, in favor of asynchronous APIs.
631
636
</div>
632
637
633
638
<h3 id="instances">Instances</h3>
@@ -646,6 +651,8 @@ interface Instance {
646
651
1. [=Read the imports=] of |module| with imports |importObject|, and let |imports| be the result.
647
652
1. [=Instantiate the core of a WebAssembly module=] |module| with |imports|, and let |instance| be the result.
648
653
1. [=initialize an instance object|Initialize=] **this** from |module| and |instance|.
654
+
655
+
Note: The use of this synchronous API is discouraged, as some implementations sometimes do long-running compilation work when instantiating.
0 commit comments