From 47c258977378a052f4ef4676a3f59cd047679da7 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Mon, 11 Mar 2019 17:05:50 +0100 Subject: [PATCH 1/6] Editorial: Stop breaking lists to insert a note. --- document/js-api/index.bs | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/document/js-api/index.bs b/document/js-api/index.bs index 27b1d0a41c..f75b564f60 100644 --- a/document/js-api/index.bs +++ b/document/js-api/index.bs @@ -351,17 +351,13 @@ A {{Module}} object represents a single WebAssembly module. Each {{Module}} obje 1. [=Append=] |externglobal| to |imports|. 1. If |externtype| is of the form [=𝗆𝖾𝗆=] |memtype|, 1. If |v| is not a {{Memory}} object, throw a {{LinkError}} exception. - - Note: [=instantiate_module=] invoked below will check the imported {{Memory}}'s size against the importing module's requirements. - - 2. Let |externmem| be the [=external value=] [=external value|𝗆𝖾𝗆=] |v|.\[[Memory]]. + 1. Note: [=instantiate_module=] invoked below will check the imported {{Memory}}'s size against the importing module's requirements. + 1. Let |externmem| be the [=external value=] [=external value|𝗆𝖾𝗆=] |v|.\[[Memory]]. 1. [=Append=] |externmem| to |imports|. 1. Otherwise, |externtype| is of the form [=𝗍𝖺𝖻𝗅𝖾=] |tabletype|, 1. If |v| is not a {{Table}} instance, throw a {{LinkError}} exception. - - Note: The table's length, etc. is checked by [=instantiate_module=] invoked below. - - 2. Let |tableaddr| be |v|.\[[Table]] + 1. Note: The table's length, etc. is checked by [=instantiate_module=] invoked below. + 1. Let |tableaddr| be |v|.\[[Table]] 1. Let |externtable| be the [=external value=] [=external value|𝗍𝖺𝖻𝗅𝖾=] |tableaddr|. 1. [=Append=] |externtable| to |imports|. 1. Let |store| be the [=surrounding agent=]'s [=associated store=]. From d40299d0cd809648598a377e7b58ea727a0d86a7 Mon Sep 17 00:00:00 2001 From: Daniel Ehrenberg Date: Mon, 11 Mar 2019 17:15:53 +0100 Subject: [PATCH 2/6] Editorial: Extract a "read the imports" algorithm. --- document/js-api/index.bs | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/document/js-api/index.bs b/document/js-api/index.bs index f75b564f60..8876feb678 100644 --- a/document/js-api/index.bs +++ b/document/js-api/index.bs @@ -316,9 +316,8 @@ A {{Module}} object represents a single WebAssembly module. Each {{Module}} obje 1. [=Asynchronously compile a WebAssembly module=] from |stableBytes| and return the result. -
- To instantiate a WebAssembly module from a {{Module}} |moduleObject| and imports |importObject|, perform the following steps: - 1. Let |module| be |moduleObject|.\[[Module]]. +
+ To read the imports from a WebAssembly module |module| from imports object |importObject|, perform the following steps: 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. 1. For each (|moduleName|, |componentName|, |externtype|) in [=module_imports=](|module|), do @@ -349,17 +348,24 @@ A {{Module}} object represents a single WebAssembly module. Each {{Module}} obje 1. Throw a {{LinkError}} exception. 1. Let |externglobal| be [=external value|π—€π—…π—ˆπ–»π–Ίπ—…=] |globaladdr|. 1. [=Append=] |externglobal| to |imports|. - 1. If |externtype| is of the form [=𝗆𝖾𝗆=] |memtype|, + 1. If |externtype| is of the form [=𝗆𝖾𝗆=] memtype, 1. If |v| is not a {{Memory}} object, throw a {{LinkError}} exception. 1. Note: [=instantiate_module=] invoked below will check the imported {{Memory}}'s size against the importing module's requirements. 1. Let |externmem| be the [=external value=] [=external value|𝗆𝖾𝗆=] |v|.\[[Memory]]. 1. [=Append=] |externmem| to |imports|. - 1. Otherwise, |externtype| is of the form [=𝗍𝖺𝖻𝗅𝖾=] |tabletype|, + 1. Otherwise, |externtype| is of the form [=𝗍𝖺𝖻𝗅𝖾=] tabletype, 1. If |v| is not a {{Table}} instance, throw a {{LinkError}} exception. 1. Note: The table's length, etc. is checked by [=instantiate_module=] invoked below. 1. Let |tableaddr| be |v|.\[[Table]] 1. Let |externtable| be the [=external value=] [=external value|𝗍𝖺𝖻𝗅𝖾=] |tableaddr|. 1. [=Append=] |externtable| to |imports|. + 1. Return |imports|. +
+ +
+ To instantiate a WebAssembly module from a {{Module}} |moduleObject| and imports |importObject|, perform the following steps: + 1. Let |module| be |moduleObject|.\[[Module]]. + 1. [=Read the imports=] of |module| with imports |importObject|, and let |imports| be the result. 1. Let |store| be the [=surrounding agent=]'s [=associated store=]. 1. Let |result| be [=instantiate_module=](|store|, |module|, |imports|). 1. If |result| is [=error=], throw an appropriate exception type: @@ -372,7 +378,7 @@ A {{Module}} object represents a single WebAssembly module. Each {{Module}} obje 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. 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|. @@ -382,12 +388,12 @@ A {{Module}} object represents a single WebAssembly module. Each {{Module}} obje 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. 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. 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|. From 3b7b313bc3a6a2ccad2e302b1e1ecc9aba086e8c Mon Sep 17 00:00:00 2001 From: Daniel Ehrenberg Date: Mon, 11 Mar 2019 17:18:32 +0100 Subject: [PATCH 3/6] Editorial: Extract a "create an instance object" algorithm. --- document/js-api/index.bs | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/document/js-api/index.bs b/document/js-api/index.bs index 8876feb678..731517a9b8 100644 --- a/document/js-api/index.bs +++ b/document/js-api/index.bs @@ -362,18 +362,8 @@ A {{Module}} object represents a single WebAssembly module. Each {{Module}} obje 1. Return |imports|.
-
- To instantiate a WebAssembly module from a {{Module}} |moduleObject| and imports |importObject|, perform the following steps: - 1. Let |module| be |moduleObject|.\[[Module]]. - 1. [=Read the imports=] of |module| with imports |importObject|, and let |imports| be the result. - 1. Let |store| be the [=surrounding agent=]'s [=associated store=]. - 1. Let |result| be [=instantiate_module=](|store|, |module|, |imports|). - 1. If |result| 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 (|store|, |instance|) be |result|. - 1. Set the [=surrounding agent=]'s [=associated store=] to |store|. +
+ To create an instance object from a WebAssembly module |module| and instance |instance|, perform the following steps: 1. Let |exportsObject| be ! [=ObjectCreate=](null). 1. For each pair (|name|, |externtype|) in [=module_exports=](|module|), 1. Let |externval| be [=get_export=](|instance|, |name|). @@ -407,6 +397,22 @@ A {{Module}} object represents a single WebAssembly module. Each {{Module}} obje 1. Return |instanceObject|.
+
+ To instantiate a WebAssembly module from a {{Module}} |moduleObject| and imports |importObject|, perform the following steps: + 1. Let |module| be |moduleObject|.\[[Module]]. + 1. [=Read the imports=] of |module| with imports |importObject|, and let |imports| be the result. + 1. Let |store| be the [=surrounding agent=]'s [=associated store=]. + 1. Let |result| be [=instantiate_module=](|store|, |module|, |imports|). + 1. If |result| 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 (|store|, |instance|) be |result|. + 1. Set the [=surrounding agent=]'s [=associated store=] to |store|. + 1. [=Create an instance object=] from |module| and |instance|, and let the result be |instanceObject|. + 1. Return |instanceObject|. +
+
To instantiate a promise of a module |promiseOfModule| with imports |importObject|, perform the following steps: From a3d76853ba8c4d69b633ec717c79172b09337fec Mon Sep 17 00:00:00 2001 From: Daniel Ehrenberg Date: Mon, 11 Mar 2019 17:19:09 +0100 Subject: [PATCH 4/6] Editorial: Remove an unnecessary local variable in "create an instance object". --- document/js-api/index.bs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/document/js-api/index.bs b/document/js-api/index.bs index 731517a9b8..365f4cfac6 100644 --- a/document/js-api/index.bs +++ b/document/js-api/index.bs @@ -393,8 +393,7 @@ A {{Module}} object represents a single WebAssembly module. Each {{Module}} obje 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. Return a new {{Instance}} object whose internal \[[Instance]] slot is set to |instance| and the \[[Exports]] slot to |exportsObject|.
From 34bda719f6b3b2441cfd3a23bbd58a7b4ab7c74a Mon Sep 17 00:00:00 2001 From: Daniel Ehrenberg Date: Mon, 11 Mar 2019 17:56:28 +0100 Subject: [PATCH 5/6] Editorial: Extract an "instantiate the core of a WebAssembly module" algorithm. --- document/js-api/index.bs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/document/js-api/index.bs b/document/js-api/index.bs index 365f4cfac6..ff5fb24598 100644 --- a/document/js-api/index.bs +++ b/document/js-api/index.bs @@ -396,10 +396,8 @@ A {{Module}} object represents a single WebAssembly module. Each {{Module}} obje 1. Return a new {{Instance}} object whose internal \[[Instance]] slot is set to |instance| and the \[[Exports]] slot to |exportsObject|.
-
- To instantiate a WebAssembly module from a {{Module}} |moduleObject| and imports |importObject|, perform the following steps: - 1. Let |module| be |moduleObject|.\[[Module]]. - 1. [=Read the imports=] of |module| with imports |importObject|, and let |imports| be the result. +
+ To instantiate the core of a WebAssembly module from a module |module| and imports |imports|, perform the following steps: 1. Let |store| be the [=surrounding agent=]'s [=associated store=]. 1. Let |result| be [=instantiate_module=](|store|, |module|, |imports|). 1. If |result| is [=error=], throw an appropriate exception type: @@ -408,6 +406,14 @@ A {{Module}} object represents a single WebAssembly module. Each {{Module}} obje * Another error type if appropriate, for example an out-of-memory exception, as documented in the WebAssembly error mapping. 1. Let (|store|, |instance|) be |result|. 1. Set the [=surrounding agent=]'s [=associated store=] to |store|. + 1. Return |instance|. +
+ +
+ To instantiate a WebAssembly module from a {{Module}} |moduleObject| and imports |importObject|, perform the following steps: + 1. Let |module| be |moduleObject|.\[[Module]]. + 1. [=Read the imports=] of |module| with imports |importObject|, and let |imports| be the result. + 1. [=Instantiate the core of a WebAssembly module=] |module| with |imports|, and let |instance| be the result. 1. [=Create an instance object=] from |module| and |instance|, and let the result be |instanceObject|. 1. Return |instanceObject|.
From 854a2785509b8f106340457d4d0af5826d25d415 Mon Sep 17 00:00:00 2001 From: Daniel Ehrenberg Date: Tue, 12 Mar 2019 11:04:00 +0100 Subject: [PATCH 6/6] Editorial: Extract an "asynchronously instantiate a WebAssembly module" algorithm. --- document/js-api/index.bs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/document/js-api/index.bs b/document/js-api/index.bs index ff5fb24598..ff66fa50a6 100644 --- a/document/js-api/index.bs +++ b/document/js-api/index.bs @@ -409,6 +409,15 @@ A {{Module}} object represents a single WebAssembly module. Each {{Module}} obje 1. Return |instance|.
+
+ To asynchronously instantiate a WebAssembly module from a {{Module}} |moduleObject| and imports |importObject|, perform 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. [=Resolve=] |promise| with |instance|. + 1. Return |promise|. +
+
To instantiate a WebAssembly module from a {{Module}} |moduleObject| and imports |importObject|, perform the following steps: 1. Let |module| be |moduleObject|.\[[Module]]. @@ -442,11 +451,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. [=Resolve=] |promise| with |instance|. - 1. Return |promise| + 1. [=asynchronously instantiate a WebAssembly module|Asynchronously instantiate the WebAssembly module=] |moduleObject| importing |importObject|, and return the result.
Note: A follow-on streaming API is documented in the WebAssembly Web API.