Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
54 lines (47 loc) · 1.53 KB

File metadata and controls

54 lines (47 loc) · 1.53 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import { SwiftRuntime } from "javascript-kit-swift";
import { WASI } from "@wasmer/wasi";
import { WasmFs } from "@wasmer/wasmfs";
const swift = new SwiftRuntime();
// Instantiate a new WASI Instance
const wasmFs = new WasmFs();
// Output stdout and stderr to console
const originalWriteSync = wasmFs.fs.writeSync;
wasmFs.fs.writeSync = (fd, buffer, offset, length, position) => {
const text = new TextDecoder("utf-8").decode(buffer);
// Filter out standalone "\n" added by every `print`, `console.log`
// always adds its own "\n" on top.
if (text !== "\n") {
switch (fd) {
case 1:
console.log(text);
break;
case 2:
console.error(text);
break;
}
}
return originalWriteSync(fd, buffer, offset, length, position);
};
let wasi = new WASI({
args: [],
env: {},
bindings: {
...WASI.defaultBindings,
fs: wasmFs.fs,
},
});
const startWasiTask = async () => {
// Fetch our Wasm File
const response = await fetch("JavaScriptKitExample.wasm");
const responseArrayBuffer = await response.arrayBuffer();
// Instantiate the WebAssembly file
const wasm_bytes = new Uint8Array(responseArrayBuffer).buffer;
let { instance } = await WebAssembly.instantiate(wasm_bytes, {
wasi_snapshot_preview1: wasi.wasiImport,
javascript_kit: swift.importObjects(),
});
swift.setInstance(instance);
// Start the WebAssembly WASI instance!
wasi.start(instance);
};
startWasiTask();
Morty Proxy This is a proxified and sanitized view of the page, visit original site.