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
Copy file name to clipboardExpand all lines: rfcs/2024-05-19-on-demand-isolated-modules.md
+16-16Lines changed: 16 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
-
# On-demand Isolated Components
1
+
# On-demand Isolated Modules
2
2
3
-
This document proposes a basic assembly of tools and processes that aims to significantly reduce the time and effort required to experiment with multi-language isolated components within a host web browser Wasm runtime.
3
+
This document proposes a basic assembly of tools and processes that aims to significantly reduce the time and effort required to experiment with multi-language isolated modules within a host web browser Wasm runtime.
4
4
5
5
In most cases, the workflow may be reduced to importing a JavaScript module (available with associated TypeScript definitions) using the base64-encoded source file as a module specifier. For example:
In the example above, the action of importing each module invokes Wasm Component compilation / transpilation and Wasm instantiation behind the scenes, producing "on-demand" isolated components with high-level, comprehensively-typed JavaScript interfaces. The interface exported by the on-demand module can be invoked, re-exported and/or incorporated idiomatically into other JavaScript modules.
49
+
In the example above, the action of importing each JavaScript module invokes Wasm Component compilation / transpilation and Wasm instantiation behind the scenes, producing "on-demand" isolated Modules with high-level, comprehensively-typed JavaScript interfaces. The interface exported by the on-demand module can be invoked, re-exported and/or incorporated idiomatically into other standard JavaScript modules.
50
50
51
51
Although the example uses [dynamic import][dynamic-import], the import specifiers should work equally well when used with static imports.
52
52
@@ -81,21 +81,21 @@ Wasm runtimes in web browsers all implement [Core Wasm], which may be thought of
81
81
82
82
[Wasm Components][wasm-components] constitute an ABI defined on top of [Core Wasm], as part of ongoing [WASI] development efforts. Native support for Wasm Components is available in some Wasm runtimes, but it is not as ubiquitous as [Core Wasm].
83
83
84
-
### Components
84
+
### Modules
85
85
86
-
Although the term "component" commonly refers to discrete, composable units of a user interface, this document uses the term in the sense of a [Wasm Component][wasm-components]. In this sense, a component may be thought of as any re-usable chunk of software.
86
+
Modules are our domain jargon for a self-contained unit of code suitable for variable runtime environments. In our jargon, a [Wasm Component][wasm-components]may be thought of as a special case of a Module.
87
87
88
-
For the purposes of reasoning about what may or may not be part of a component's interface: anything that can be expressed in a [WIT][wit] definition is considered a candidate (this means you can express anything you want, probably).
88
+
For the purposes of reasoning about what may or may not be part of a Module's interface: anything that can be expressed in a [WIT][wit] definition is considered a candidate (this means you can express anything you want, probably).
89
89
90
90
### Isolation
91
91
92
-
The techniques in this document are centered on making components out of [Wasm][wasm]. Therefor, when the term isolation is used, it mainly refers to the properties enabled by the Wasm runtime insofar as we may access it in a web browser. In a typical case, a Wasm module:
92
+
The techniques in this document are centered on making Modules out of [Wasm][wasm]. Therefor, when the term isolation is used, it mainly refers to the properties enabled by the Wasm runtime insofar as we may access it in a web browser. In a typical case, a Wasm module:
93
93
94
94
- Will have its own, unshared buffer of memory
95
95
- May only import objects, capabilities and metadata from "outside" the runtime when they are explicitly provided by its host
96
96
- Must be invoked explicitly by its host
97
97
98
-
Wasm provides a reasonable, basic substrate for component isolation. But, it's important to note that this isolation does not constitute a security boundary. It is easy to accidentally grant more capabilities than intended to a Wasm module when providing it access to host APIs (especially within a web browser host). And, vulnerabilities such as [Specter][specter] and [Rowhammer][rowhammer] are theoretically possible to exploit from a Wasm module.
98
+
Wasm provides a reasonable, basic substrate for Module isolation. But, it's important to note that this isolation does not constitute a security boundary. It is easy to accidentally grant more capabilities than intended to a Wasm module when providing it access to host APIs (especially within a web browser host). And, vulnerabilities such as [Specter][specter] and [Rowhammer][rowhammer] are theoretically possible to exploit from a Wasm module.
99
99
100
100
## Tools
101
101
@@ -114,14 +114,14 @@ We will create a Build Server. The Build Server is responsible transforming rece
114
114
115
115
The Build Server provides a REST API domain in service of this responsibility.
116
116
117
-
#### POST /api/v0/component
117
+
#### POST /api/v0/module
118
118
119
119
Accepts `multipart/form-data` requests.
120
120
121
121
For the first version, the body is expected to contain two files:
122
122
123
123
- A WIT component definition
124
-
- A single source code file that implements the component interface
124
+
- A single source code file that implements the suggested component interface
125
125
126
126
To handle a valid request, the Build Server must:
127
127
@@ -141,7 +141,7 @@ The Build Server then responds with:
141
141
142
142
In the future, we may expand on this API to support many WIT definitions and source files in a single request (including support for many languages in one collection of files).
143
143
144
-
#### GET /api/v0/component/:id
144
+
#### GET /api/v0/module/:id
145
145
146
146
This API serves [Wasm Components][wasm-components] that were successfully built by earlier requests to [POST /api/v0/component](#post-apiv0component).
147
147
@@ -161,15 +161,15 @@ The [js-component-bindgen] Rust crate provides an API for transforming any valid
161
161
162
162
We will create a [Service Worker] that wraps up the capabilities of [js-component-bindgen] in order to polyfill transparent, on-demand support for [Wasm Components][wasm-components] in a web browser.
163
163
164
-
The Service Worker intercepts `GET` requests to a well-known local path that is unlikely to conflict with a REST-y path in use by the local application domain. For the purposes of this document, we'll say that the matching path looks like `/__/v0/wasm/on-demand/:ext/:wit/:source_code`. When a request is made to that path, the Service Worker performs the following steps:
164
+
The Service Worker intercepts `GET` requests to a well-known local path. For the purposes of this document, we'll say that the matching path looks like `/module/on-demand/:ext/:wit/:source_code`. When a request is made to that path, the Service Worker performs the following steps:
165
165
166
166
1. Resolve the [WIT][wit] component definition by base64-decoding the `wit` part of the path
167
167
2. Resolve the component source code by base64-decoding the `source_code` part of the path
168
168
3. Prepare a `multipart/form-data` request body that includes two files:
169
169
1.`component.wit`: The resolved WIT component definition
170
170
2.`component.$EXT`: The resolved source file, where `$EXT` is replaced with the `ext` part of the path
171
-
4. Make a request to [`POST /api/v0/component`](#post-apiv0component) on a running [Build Server](#build-server) using the prepared request body
172
-
5. Make a request for the prepared [Wasm Component][wasm-components] using [`GET /api/v0/component/:id`](#get-apiv0componentid) on a running Build Server
171
+
4. Make a request to [`POST /api/v0/module`](#post-apiv0component) on a running [Build Server](#build-server) using the prepared request body
172
+
5. Make a request for the prepared [Wasm Component][wasm-components] using [`GET /api/v0/module/:id`](#get-apiv0componentid) on a running Build Server
173
173
6. Invoke the [`transpile`][js-component-bindgen-transpile] API provided by [js-component-bindgen] and cache the returned files at the appropriate paths
174
174
7. Create a wrapper ESM that imports the cached artifacts and re-exports the component API
175
175
8. Respond to the intercepted request with the generated wrapper module
0 commit comments