diff --git a/document/js-api/index.bs b/document/js-api/index.bs
index 74e63ef8f0..5643fb149b 100644
--- a/document/js-api/index.bs
+++ b/document/js-api/index.bs
@@ -315,7 +315,7 @@ A {{Module}} object represents a single WebAssembly module. Each {{Module}} obje
- To
instantiate a WebAssembly module from a {{Module}} |moduleObject| and imports |importObject|, perform the following steps:
+ To
instantiate a WebAssembly module from a {{Module}} |moduleObject| and imports |importObject|, and optional algorithm |steps| is given |importObject| as a parameter, perform the following steps:
1. Let |module| be |moduleObject|.\[[Module]].
1. If |module|.[=πππππππ=] is not an empty list, and |importObject| is undefined, throw a {{TypeError}} exception.
1. Let |imports| be an empty [=list=] of [=external value=]s.
@@ -362,42 +362,44 @@ A {{Module}} object represents a single WebAssembly module. Each {{Module}} obje
2. Let |tableaddr| be |v|.\[[Table]]
1. Let |externtable| be the [=external value=] [=external value|ππΊπ»π
πΎ=] |tableaddr|.
1. [=Append=] |externtable| to |imports|.
- 1. Let (|store|, |instance|) be [=instantiate_module=](|store|, |module|, |imports|).
- 1. If |instance| is [=error=], throw an appropriate exception type:
- * A {{LinkError}} exception for most cases which occur during linking.
- * If the error came when running the start function, throw a {{RuntimeError}} for most errors which occur from WebAssembly, or the error object propagated from inner ECMAScript code.
- * Another error type if appropriate, for example an out-of-memory exception, as documented in
the WebAssembly error mapping.
- 1. Let |exportsObject| be ! [=ObjectCreate=](null).
- 1. For each pair (|name|, |externtype|) in [=module_exports=](|module|),
- 1. Let |externval| be [=get_export=](|instance|, |name|).
- 1. Assert: |externval| is not [=error=].
- 1. If |externtype| is of the form [=πΏπππΌ=] |functype|,
- 1. Assert: |externval| is of the form [=external value|πΏπππΌ=] |funcaddr|.
- 1. Let [=external value|πΏπππΌ=] |funcaddr| be |externval|.
- 1. Let |func| be the result of creating [=a new Exported Function=] from |funcaddr|.
- 1. Let |value| be |func|.
- 1. If |externtype| is of the form [=ππ
ππ»πΊπ
=]
globaltype,
- 1. Assert: |externval| is of the form [=external value|ππ
ππ»πΊπ
=] |globaladdr|.
- 1. Let [=external value|ππ
ππ»πΊπ
=] |globaladdr| be |externval|.
- 1. Let |global| be [=create a global object|a new Global object=] created from |globaladdr|.
- 1. Let |value| be |global|.
- 1. If |externtype| is of the form [=ππΎπ=] |memtype|,
- 1. Assert: |externval| is of the form [=external value|ππΎπ=] |memaddr|.
- 1. Let [=external value|ππΎπ=] |memaddr| be |externval|.
- 1. Let |memory| be [=create a memory object|a new Memory object=] created from |memaddr|.
- 1. Let |value| be |memory|.
- 1. Otherwise, |externtype| is of the form [=ππΊπ»π
πΎ=] |tabletype|,
- 1. Assert: |externval| is of the form [=external value|ππΊπ»π
πΎ=] |tableaddr|.
- 1. Let [=external value|ππΊπ»π
πΎ=] |tableaddr| be |externval|.
- 1. Let |table| be [=create a Table object|a new Table object=] created from |tableaddr|.
- 1. Let |value| be |table|.
- 1. Let |status| be ! [=CreateDataProperty=](|exportsObject|, |name|, |value|).
- 1. Assert: |status| is true.
-
- Note: the validity and uniqueness checks performed during [=WebAssembly module validation=] ensure that each property name is valid and no properties are defined twice.
- 1. Perform ! [=SetIntegrityLevel=](|exportsObject|, `"frozen"`).
- 1. Let |instanceObject| be a new {{Instance}} object whose internal \[[Instance]] slot is set to |instance| and the \[[Exports]] slot to |exportsObject|.
- 1. Return |instanceObject|.
+ 1. If |steps| is provided, user agents may either perform the following steps, or may perform additional work [=in parallel=] and then [=queue a task=] to perform the following steps. If |steps| is not provided, perform the following steps:
+ 1. Let (|store|, |instance|) be [=instantiate_module=](|store|, |module|, |imports|).
+ 1. If |instance| is [=error=], throw an appropriate exception type:
+ * A {{LinkError}} exception for most cases which occur during linking.
+ * If the error came when running the start function, throw a {{RuntimeError}} for most errors which occur from WebAssembly, or the error object propagated from inner ECMAScript code.
+ * Another error type if appropriate, for example an out-of-memory exception, as documented in
the WebAssembly error mapping.
+ 1. Let |exportsObject| be ! [=ObjectCreate=](null).
+ 1. For each pair (|name|, |externtype|) in [=module_exports=](|module|),
+ 1. Let |externval| be [=get_export=](|instance|, |name|).
+ 1. Assert: |externval| is not [=error=].
+ 1. If |externtype| is of the form [=πΏπππΌ=] |functype|,
+ 1. Assert: |externval| is of the form [=external value|πΏπππΌ=] |funcaddr|.
+ 1. Let [=external value|πΏπππΌ=] |funcaddr| be |externval|.
+ 1. Let |func| be the result of creating [=a new Exported Function=] from |funcaddr|.
+ 1. Let |value| be |func|.
+ 1. If |externtype| is of the form [=ππ
ππ»πΊπ
=]
globaltype,
+ 1. Assert: |externval| is of the form [=external value|ππ
ππ»πΊπ
=] |globaladdr|.
+ 1. Let [=external value|ππ
ππ»πΊπ
=] |globaladdr| be |externval|.
+ 1. Let |global| be [=create a global object|a new Global object=] created from |globaladdr|.
+ 1. Let |value| be |global|.
+ 1. If |externtype| is of the form [=ππΎπ=] |memtype|,
+ 1. Assert: |externval| is of the form [=external value|ππΎπ=] |memaddr|.
+ 1. Let [=external value|ππΎπ=] |memaddr| be |externval|.
+ 1. Let |memory| be [=create a memory object|a new Memory object=] created from |memaddr|.
+ 1. Let |value| be |memory|.
+ 1. Otherwise, |externtype| is of the form [=ππΊπ»π
πΎ=] |tabletype|,
+ 1. Assert: |externval| is of the form [=external value|ππΊπ»π
πΎ=] |tableaddr|.
+ 1. Let [=external value|ππΊπ»π
πΎ=] |tableaddr| be |externval|.
+ 1. Let |table| be [=create a Table object|a new Table object=] created from |tableaddr|.
+ 1. Let |value| be |table|.
+ 1. Let |status| be ! [=CreateDataProperty=](|exportsObject|, |name|, |value|).
+ 1. Assert: |status| is true.
+
+ Note: the validity and uniqueness checks performed during [=WebAssembly module validation=] ensure that each property name is valid and no properties are defined twice.
+ 1. Perform ! [=SetIntegrityLevel=](|exportsObject|, `"frozen"`).
+ 1. Let |instanceObject| be a new {{Instance}} object whose internal \[[Instance]] slot is set to |instance| and the \[[Exports]] slot to |exportsObject|.
+ 1. If |steps| is provided, perform |steps| given |instanceObject|.
+ 1. Otherwise, return |instanceObject|.
@@ -405,9 +407,9 @@ A {{Module}} object represents a single WebAssembly module. Each {{Module}} obje
1. Let |promise| be [=a new promise=]
1. [=Upon fulfillment=] of |promiseOfModule| with value |module|:
- 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.
- 1. Let |result| be a {{WebAssemblyInstantiatedSource}} dictionary with {{WebAssemblyInstantiatedSource/module}} set to |module| and {{WebAssemblyInstantiatedSource/instance}} set to |instance|.
- 1. [=Resolve=] |promise| with |result|.
+ 1. [=instantiate a WebAssembly module|Instantiate the WebAssembly module=] |module| importing |importObject|, with the following steps given |instance|. If this throws an exception, catch it, [=reject=] |promise| with the exception, and abort these substeps.
+ 1. Let |result| be a {{WebAssemblyInstantiatedSource}} dictionary with {{WebAssemblyInstantiatedSource/module}} set to |module| and {{WebAssemblyInstantiatedSource/instance}} set to |instance|.
+ 1. [=Resolve=] |promise| with |result|.
1. [=Upon rejection=] of |promiseOfModule| with reason |reason|:
1. [=Reject=] |promise| with |reason|.
1. Return |promise|.
@@ -425,8 +427,7 @@ A {{Module}} object represents a single WebAssembly module. Each {{Module}} obje
The instantiate(|moduleObject|, |importObject|) method, when invoked, performs the following steps:
1. Let |promise| be [=a new promise=].
- 1. [=Queue a task=] to perform the following steps:
- 1. [=instantiate a WebAssembly module|Instantiate the WebAssembly module=] |moduleObject| importing |importObject|, and let |instance| be the result. If this throws an exception, catch it, and [=reject=] |promise| with the exception.
+ 1. [=instantiate a WebAssembly module|Instantiate the WebAssembly module=] |moduleObject| importing |importObject|, with the following steps, given |instance|. If this throws an exception, catch it, and [=reject=] |promise| with the exception.
1. [=Resolve=] |promise| with |instance|.
1. Return |promise|