@@ -83,18 +83,33 @@ precise descriptions of:
83
83
84
84
## Code loading and imports
85
85
* The loadable unit of WebAssembly code is a * module* .
86
- * WebAssembly modules can be loaded declaratively (via import on page load) or imperatively (via API call)
87
- and can be compiled dynamically (from bytes, as defined by the binary format).
88
- * A natural integration point with JS would be to have WebAssembly modules be reflected to JS
89
- as ES6 Modules.
90
- * The module interface would mostly hide whether the module was JS or WebAssembly (except for things
91
- like ` fun.toSource() ` ) and allow webapps to be naturally composed of both JS and WebAssembly modules.
92
- * ES6 Modules can be loaded declaratively (via imports) or imperatively (via API calls at runtime).
93
- * The ES6 Module API also allows dynamically generated modules (a JS module can be compiled from a string);
94
- building on this, WebAssembly modules could be dynamically compiled from an ArrayBuffer.
95
- * Just like ES6 modules, WebAssembly modules could import other modules (JS or WebAssembly); this would
96
- replace asm.js [ FFIs] ( http://asmjs.org/spec/latest/index.html#external-code-and-data ) .
97
-
86
+ * Modules can be loaded before execution begins or at runtime.
87
+ * A module is loaded from a sequence of bytes (specified by the [ binary format] ( V1.md#binary-format ) )
88
+ that are either fetched via URL (which can be a filename via file:///) or
89
+ given in the heap of a running WebAssembly module.
90
+ * A module can declare a subset of its functions to be exports.
91
+ * A module can declare that it imports functions (with given names and signatures) from other modules
92
+ (with given URLs) and these imports will be recursively loaded when the module is loaded.
93
+ * An load-time error is raised if the signature of an import does not match the signature of the export.
94
+ * These imported functions can be called like other internal functions
95
+ ([ directly or indirectly] ( AstSemantics.md#calls ) ).
96
+ * Modules can be loaded at runtime by WebAssembly code calling a
97
+ builtin function (implemented by the host environment).
98
+ * Functions are imported by name/signature with error on mismatch.
99
+ * These imported functions can only be called [ indirectly] ( AstSemantics.md#calls ) .
100
+ * Another builtin function would invalidate all existing function pointer values for a given
101
+ dynamically-loaded module, allowing it to be unloaded from memory (as soon as it is not active
102
+ on the stack and not referenced elsewhere).
103
+ * All forms of module import produce disjoint [ heaps] ( V1.md#heap ) and do not allow function-pointer
104
+ values to be passed between modules. Thus, separately imported modules are like separate processes
105
+ that run (and can be synchronously called) on the same thread.
106
+ * Support for true native dynamic linking, which requires the ability to load a
107
+ module into the * same* address space and is a planned [ future feature] ( FutureFeatures.md#dynamic-linking ) .
108
+ * In a Web environment, WebAssembly modules are reflected in JS as ES6 modules:
109
+ * JS can import WebAssembly via ` import ` , ` Reflect ` APIs, etc, the same way as ES6 modules;
110
+ * WebAssembly imports can resolve to ES6 modules; and
111
+ * WebAssembly modules are loaded with the same [ Module Loader pipeline] ( http://whatwg.github.io/loader/ ) .
112
+
98
113
## Heap
99
114
* In v.1, when a WebAssembly module is loaded, it creates a new heap.
100
115
* The [ dynamic linking] ( FutureFeatures.md#dynamic-linking ) feature will be necessary for two
@@ -123,8 +138,8 @@ precise descriptions of:
123
138
for portable C/C++ code.
124
139
125
140
## Non-browser embedding
126
- * Host environments can define builtin modules that are implemented natively and thus be imported
127
- directly by WebAssembly modules.
141
+ * Host environments can define builtin modules that are implemented natively but can otherwise
142
+ be imported like [ other modules] ( V1.md#code-loading-and-imports ) .
128
143
* For example, a WebAssembly shell might define a builtin ` stdio ` library with an export ` puts ` .
129
144
* Another example, in the browser, would be the WebIDL support mentioned in [ future features] ( FutureFeatures.md ) .
130
145
* Where there is overlap between the browser and popular non-browser environments, a shared spec could be
0 commit comments