aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Wagner <mail@lukewagner.name>2016-11-02 16:26:23 -0500
committerGitHub <noreply@github.com>2016-11-02 16:26:23 -0500
commit18cbacb90cd3584dd5c9aa3d392e4e55f66af6ab (patch)
treed34450abb803b51c15cf4ac12bd7bbbd0d72d3ec
parentf1f8666b2dd8a75a35a605586517bf99157bd499 (diff)
downloadnanowasm-design-18cbacb90cd3584dd5c9aa3d392e4e55f66af6ab.tar.gz
Add Module.(import|exports) (#858)
* Add Module.(import|exports) * Change imports/exports to static functions
-rw-r--r--JS.md42
1 files changed, 40 insertions, 2 deletions
diff --git a/JS.md b/JS.md
index 42856af..9296e49 100644
--- a/JS.md
+++ b/JS.md
@@ -166,6 +166,45 @@ Otherwise, this function performs synchronous compilation of the `BufferSource`:
the validated `Ast.module`.
* On failure, a new `WebAssembly.CompileError` is thrown.
+### `WebAssembly.Module.exports`
+
+The `exports` function has the signature:
+
+```
+Array exports(moduleObject)
+```
+
+If `moduleObject` is not a `WebAssembly.Module` instance, a [`TypeError`](https://tc39.github.io/ecma262/#sec-native-error-types-used-in-this-standard-typeerror)
+is thrown.
+
+This function returns an `Array` produced by mapping each
+[`Ast.export`](https://github.com/WebAssembly/spec/blob/master/interpreter/spec/ast.ml#L152)
+`e` of [moduleObject.[[Module]].exports](https://github.com/WebAssembly/spec/blob/master/interpreter/spec/ast.ml#L187)
+to the Object `{ name: String(e.name), kind: e.ekind }` where `e.name` is [decoded as UTF8](Web.md#names)
+and `e.ekind` is mapped to one of the String values `"function"`, `"table"`, `"memory"`, `"global"`.
+
+Note: other fields like `signature` may be added in the future.
+
+### `WebAssembly.Module.imports`
+
+The `imports` function has the signature:
+
+```
+Array imports(moduleObject)
+```
+
+If `moduleObject` is not a `WebAssembly.Module` instance, a [`TypeError`](https://tc39.github.io/ecma262/#sec-native-error-types-used-in-this-standard-typeerror)
+is thrown.
+
+This function returns an `Array` produced by mapping each
+[`Ast.import`](https://github.com/WebAssembly/spec/blob/master/interpreter/spec/ast.ml#L167)
+`i` of [moduleObject.[[Module]].imports](https://github.com/WebAssembly/spec/blob/master/interpreter/spec/ast.ml#L203)
+to the Object `{ module: String(i.module_name), name: String(i.item_name), kind: i.ikind }` where
+`i.module_name` and `i.item_name` are [decoded as UTF8](Web.md#names) and
+`i.ikind` is mapped to one of the String values `"function"`, `"table"`, `"memory"`, `"global"`.
+
+Note: other fields like `signature` may be added in the future.
+
### Structured Clone of a `WebAssembly.Module`
A `WebAssembly.Module` is a
@@ -676,8 +715,7 @@ fetch('demo.wasm').then(response =>
## TODO
-* `WebAssembly.Module` `exports`/`imports` properties (reflection)
-* JS API for cyclic imports (perhaps a Promise-returning `WebAssembly.instantiate`?)
+* JS API for cyclic imports
[future general]: FutureFeatures.md
[future streaming]: FutureFeatures.md#streaming-compilation