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
> When building your Javascript project, ensure to set the `"type":"module"` option in `package.json`,
82
-
> as `jco` works exclusively with Javascript modules.
81
+
> When building your JavaScript project, ensure to set the `"type":"module"` option in `package.json`,
82
+
> as `jco` works exclusively with JavaScript modules.
83
83
84
-
In the code above, the `example` world is analogous to the Javascript module itself, with the exported `add` function
84
+
In the code above, the `example` world is analogous to the JavaScript module itself, with the exported `add` function
85
85
mirroring `add` function `export`ed in the WIT.
86
86
87
-
With the WIT and Javascript in place, we can use [`jco`][jco] to create a WebAssembly component from the JS module, using `jco componentize`.
87
+
With the WIT and JavaScript in place, we can use [`jco`][jco] to create a WebAssembly component from the JS module, using `jco componentize`.
88
88
89
89
Our component is *so simple* (reminiscent of [Core WebAssembly][wasm-core], which deals primarily in numeric values) that we're actually *not using* any of the [WebAssembly System Interface][wasi] -- this means that we can `--disable` it when we invoke `jco componentize`
90
90
@@ -143,7 +143,7 @@ instance
143
143
.context("Failed to call add function")
144
144
```
145
145
146
-
A quick reminder on the power and new capabilities afforded by WebAssembly -- we've written, loaded, instantiated and executed Javascript from Rust with a strict interface, without the need for FFI, subprocesses or a network call.
146
+
A quick reminder on the power and new capabilities afforded by WebAssembly -- we've written, loaded, instantiated and executed JavaScript from Rust with a strict interface, without the need for FFI, subprocesses or a network call.
@@ -156,10 +156,10 @@ A quick reminder on the power and new capabilities afforded by WebAssembly -- we
156
156
## Running a Component from JavaScript Applications (including the Browser)
157
157
158
158
JavaScript runtimes available in browsers cannot yet execute WebAssembly components, so WebAssembly components
159
-
(Javascript or otherwise) must be "transpiled" into a JavaScript wrapper and one or more [WebAssembly core modules][wasm-core-module]
159
+
(JavaScript or otherwise) must be "transpiled" into a JavaScript wrapper and one or more [WebAssembly core modules][wasm-core-module]
160
160
which *can* be run by in-browser WebAssembly runtimes.
161
161
162
-
Given an existing WebAssembly component (e.g. `add.wasm` which implements the [`example` world][wit-example-world]), we can "transpile" the component into runnable Javscript by using `jco tranpsile`:
162
+
Given an existing WebAssembly component (e.g. `add.wasm` which implements the [`example` world][wit-example-world]), we can "transpile" the component into runnable JavaScript by using `jco tranpsile`:
163
163
164
164
```console
165
165
jco transpile add.wasm -o dist
@@ -182,7 +182,7 @@ You should see output similar to the following:
182
182
183
183
184
184
Thanks to `jco` transpilation, you can import the resulting `dist/add.js` file and run it from any JavaScript application
185
-
using a runtime that supports the [core WebAssembly specification][core-wasm] as implemented for Javascript.
185
+
using a runtime that supports the [core WebAssembly specification][core-wasm] as implemented for JavaScript.
186
186
187
187
To use this component from [NodeJS][nodejs], you can write code like the following:
188
188
@@ -192,7 +192,7 @@ import { add } from "./dist/add.js";
192
192
console.log("1 + 2 = "+add(1, 2));
193
193
```
194
194
195
-
You can execute the Javascript module with `node` directly:
195
+
You can execute the JavaScript module with `node` directly:
196
196
197
197
```console
198
198
node run.js
@@ -207,7 +207,7 @@ You should see output like the following:
207
207
This is directly comparable to the Rust host code mentioned in the previous section. Here, we are able to
208
208
use NodeJS as a host for running WebAssembly, thanks to `jco`'s ability to transpile components.
209
209
210
-
With `jco transpile` any WebAssembly binary (compiled from any language) can be run in Javascript natively.
210
+
With `jco transpile` any WebAssembly binary (compiled from any language) can be run in JavaScript natively.
@@ -270,15 +270,15 @@ OK now let's see what the JS code looks like to *implement* the `component` worl
270
270
*/
271
271
272
272
/**
273
-
* This Javascript will be interpreted by `jco` and turned into a
273
+
* This JavaScript will be interpreted by `jco` and turned into a
274
274
* WebAssembly binary with a single export (this `reverse` function).
275
275
*/
276
276
functionreverseString(s) {
277
277
returns.reverse();
278
278
}
279
279
280
280
/**
281
-
* The Javascript export below represents the export of the `reverse` interface,
281
+
* The JavaScript export below represents the export of the `reverse` interface,
282
282
* which which contains `reverse-string` as it's primary exported function.
283
283
*/
284
284
exportconstreverse= {
@@ -312,7 +312,7 @@ You should see output like the following:
312
312
OK Successfully written string-reverse.wasm.
313
313
```
314
314
315
-
Now that we have a WebAssembly binary, we can *also* use `jco` to run it in a native Javascript context by *transpiling* the WebAsssembly binary (which could have come from anywhere!) to a Javascript module.
315
+
Now that we have a WebAssembly binary, we can *also* use `jco` to run it in a native JavaScript context by *transpiling* the WebAsssembly binary (which could have come from anywhere!) to a JavaScript module.
While it's somewhat redundant in this context, what we've done from NodeJS demonstrates the usefulness of WebAssembly and the `jco` toolchain. With the help of `jco`, we have:
358
358
359
-
- Compiled Javascript to a WebAssembly module (`jco compile`), adhering to an interface defined via WIT
359
+
- Compiled JavaScript to a WebAssembly module (`jco compile`), adhering to an interface defined via WIT
360
360
- Converted the compiled WebAssembly module (which could be from *any* language) to a module that can be used from any compliant JS runtime (`jco transpile`)
361
-
- Run the transpiled WebAssembly component from a Javascript native runtime (NodeJS)
361
+
- Run the transpiled WebAssembly component from a JavaScript native runtime (NodeJS)
@@ -407,7 +407,7 @@ The `revup` world `import`s (and makes use) of `reverse` in order to `export` (p
407
407
> [!NOTE]
408
408
> Functionality is imported from the `interface`, *not* the `world`. `world`s can be included/used, but the syntax is slightly different for that.
409
409
410
-
The Javascript to make this work ([`string-reverse-upper.mjs` in `jco/examples`](https://github.com/bytecodealliance/jco/blob/main/examples/components/string-reverse-upper/string-reverse-upper.mjs)) looks like this:
410
+
The JavaScript to make this work ([`string-reverse-upper.mjs` in `jco/examples`](https://github.com/bytecodealliance/jco/blob/main/examples/components/string-reverse-upper/string-reverse-upper.mjs)) looks like this:
411
411
412
412
```js
413
413
/**
@@ -423,7 +423,7 @@ The Javascript to make this work ([`string-reverse-upper.mjs` in `jco/examples`]
* The Javascript export below represents the export of the `reversed-upper` interface,
426
+
* The JavaScript export below represents the export of the `reversed-upper` interface,
427
427
* which which contains `revup` as it's primary exported function.
428
428
*/
429
429
exportconstreversedUpper= {
@@ -495,7 +495,7 @@ world root {
495
495
496
496
It's as-if we never imported any functionality at all -- the functionality present in `string-reverse.wasm` has been *merged into*`string-reverse-upper.wasm`, and it now simply `export`s the advanced functionality.
497
497
498
-
We can run this completed component with in any WebAssembly-capable native Javascript environment by using a the transpiled result:
498
+
We can run this completed component with in any WebAssembly-capable native JavaScript environment by using a the transpiled result:
0 commit comments