@bytecodealliance/preview2-shim 0.18.1 → 0.20.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -15
- package/dist/browser/cli.d.ts +16 -0
- package/dist/browser/cli.js +109 -0
- package/dist/browser/clocks.d.ts +3 -0
- package/dist/browser/clocks.js +36 -0
- package/dist/browser/config.d.ts +2 -0
- package/{lib → dist}/browser/config.js +2 -4
- package/dist/browser/environment.d.ts +5 -0
- package/dist/browser/environment.js +24 -0
- package/dist/browser/filesystem.d.ts +132 -0
- package/dist/browser/filesystem.js +488 -0
- package/dist/browser/http.d.ts +4 -0
- package/dist/browser/http.js +643 -0
- package/dist/browser/index.d.ts +7 -0
- package/dist/browser/index.js +7 -0
- package/dist/browser/io.d.ts +58 -0
- package/dist/browser/io.js +205 -0
- package/dist/browser/random.d.ts +4 -0
- package/dist/browser/random.js +49 -0
- package/dist/browser/sockets.d.ts +8 -0
- package/dist/browser/sockets.js +66 -0
- package/dist/common/instantiation.d.ts +97 -0
- package/dist/common/instantiation.js +228 -0
- package/dist/io/calls.d.ts +91 -0
- package/{lib → dist}/io/calls.js +4 -19
- package/dist/io/worker-http.d.ts +17 -0
- package/dist/io/worker-http.js +192 -0
- package/dist/io/worker-io.d.ts +84 -0
- package/dist/io/worker-io.js +381 -0
- package/dist/io/worker-socket-tcp.d.ts +34 -0
- package/dist/io/worker-socket-tcp.js +251 -0
- package/dist/io/worker-socket-udp.d.ts +54 -0
- package/dist/io/worker-socket-udp.js +493 -0
- package/dist/io/worker-sockets.d.ts +32 -0
- package/dist/io/worker-sockets.js +265 -0
- package/dist/io/worker-thread.d.ts +73 -0
- package/dist/io/worker-thread.js +794 -0
- package/dist/nodejs/cli.d.ts +30 -0
- package/dist/nodejs/cli.js +86 -0
- package/dist/nodejs/clocks.d.ts +3 -0
- package/dist/nodejs/clocks.js +61 -0
- package/dist/nodejs/filesystem.d.ts +113 -0
- package/dist/nodejs/filesystem.js +761 -0
- package/dist/nodejs/http.d.ts +82 -0
- package/dist/nodejs/http.js +674 -0
- package/dist/nodejs/index.d.ts +7 -0
- package/dist/nodejs/index.js +7 -0
- package/dist/nodejs/io.d.ts +1 -0
- package/dist/nodejs/io.js +1 -0
- package/dist/nodejs/random.d.ts +4 -0
- package/dist/nodejs/random.js +42 -0
- package/dist/nodejs/sockets.d.ts +21 -0
- package/dist/nodejs/sockets.js +482 -0
- package/dist/synckit/index.d.ts +2 -0
- package/dist/synckit/index.js +117 -0
- package/package.json +28 -15
- package/types/instantiation.d.ts +7 -7
- package/lib/browser/cli.js +0 -135
- package/lib/browser/clocks.js +0 -39
- package/lib/browser/environment.js +0 -29
- package/lib/browser/filesystem.js +0 -503
- package/lib/browser/http.js +0 -707
- package/lib/browser/index.js +0 -9
- package/lib/browser/io.js +0 -262
- package/lib/browser/random.js +0 -56
- package/lib/browser/sockets.js +0 -88
- package/lib/common/instantiation.js +0 -253
- package/lib/io/worker-http.js +0 -206
- package/lib/io/worker-io.js +0 -468
- package/lib/io/worker-socket-tcp.js +0 -331
- package/lib/io/worker-socket-udp.js +0 -587
- package/lib/io/worker-sockets.js +0 -364
- package/lib/io/worker-thread.js +0 -1051
- package/lib/nodejs/cli.js +0 -109
- package/lib/nodejs/clocks.js +0 -67
- package/lib/nodejs/filesystem.js +0 -829
- package/lib/nodejs/http.js +0 -764
- package/lib/nodejs/index.js +0 -9
- package/lib/nodejs/io.js +0 -1
- package/lib/nodejs/random.js +0 -49
- package/lib/nodejs/sockets.js +0 -565
- package/lib/synckit/index.js +0 -127
package/lib/nodejs/cli.js
DELETED
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
import process, { argv, env, cwd } from "node:process";
|
|
2
|
-
import { ioCall, streams, inputStreamCreate, outputStreamCreate } from "../io/worker-io.js";
|
|
3
|
-
import { INPUT_STREAM_CREATE, STDERR, STDIN, STDOUT } from "../io/calls.js";
|
|
4
|
-
const { InputStream, OutputStream } = streams;
|
|
5
|
-
|
|
6
|
-
export const _appendEnv = (env) => {
|
|
7
|
-
void (_env = [..._env.filter(([curKey]) => !(curKey in env)), ...Object.entries(env)]);
|
|
8
|
-
};
|
|
9
|
-
export const _setEnv = (env) => void (_env = Object.entries(env));
|
|
10
|
-
export const _setArgs = (args) => void (_args = args);
|
|
11
|
-
export const _setCwd = (cwd) => void (_cwd = cwd);
|
|
12
|
-
export const _setStdin = (stdin) => void (stdinStream = stdin);
|
|
13
|
-
export const _setStdout = (stdout) => void (stdoutStream = stdout);
|
|
14
|
-
export const _setStderr = (stderr) => void (stderrStream = stderr);
|
|
15
|
-
export const _setTerminalStdin = (terminalStdin) => void (terminalStdinInstance = terminalStdin);
|
|
16
|
-
export const _setTerminalStdout = (terminalStdout) =>
|
|
17
|
-
void (terminalStdoutInstance = terminalStdout);
|
|
18
|
-
export const _setTerminalStderr = (terminalStderr) =>
|
|
19
|
-
void (terminalStderrInstance = terminalStderr);
|
|
20
|
-
|
|
21
|
-
let _env = Object.entries(env),
|
|
22
|
-
_args = argv.slice(1),
|
|
23
|
-
_cwd = cwd();
|
|
24
|
-
|
|
25
|
-
export const environment = {
|
|
26
|
-
getEnvironment() {
|
|
27
|
-
return _env;
|
|
28
|
-
},
|
|
29
|
-
getArguments() {
|
|
30
|
-
return _args;
|
|
31
|
-
},
|
|
32
|
-
initialCwd() {
|
|
33
|
-
return _cwd;
|
|
34
|
-
},
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
export const exit = {
|
|
38
|
-
exit(status) {
|
|
39
|
-
process.exit(status.tag === "err" ? 1 : 0);
|
|
40
|
-
},
|
|
41
|
-
exitWithCode(code) {
|
|
42
|
-
process.exit(code);
|
|
43
|
-
},
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
// Stdin is created as a FILE descriptor
|
|
47
|
-
let stdinStream;
|
|
48
|
-
let stdoutStream = outputStreamCreate(STDOUT, 1);
|
|
49
|
-
let stderrStream = outputStreamCreate(STDERR, 2);
|
|
50
|
-
|
|
51
|
-
export const stdin = {
|
|
52
|
-
InputStream,
|
|
53
|
-
getStdin() {
|
|
54
|
-
if (!stdinStream) {
|
|
55
|
-
stdinStream = inputStreamCreate(STDIN, ioCall(INPUT_STREAM_CREATE | STDIN, null, null));
|
|
56
|
-
}
|
|
57
|
-
return stdinStream;
|
|
58
|
-
},
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
export const stdout = {
|
|
62
|
-
OutputStream,
|
|
63
|
-
getStdout() {
|
|
64
|
-
return stdoutStream;
|
|
65
|
-
},
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
export const stderr = {
|
|
69
|
-
OutputStream,
|
|
70
|
-
getStderr() {
|
|
71
|
-
return stderrStream;
|
|
72
|
-
},
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
class TerminalInput {}
|
|
76
|
-
class TerminalOutput {}
|
|
77
|
-
|
|
78
|
-
let terminalStdoutInstance = new TerminalOutput();
|
|
79
|
-
let terminalStderrInstance = new TerminalOutput();
|
|
80
|
-
let terminalStdinInstance = new TerminalInput();
|
|
81
|
-
|
|
82
|
-
export const terminalInput = {
|
|
83
|
-
TerminalInput,
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
export const terminalOutput = {
|
|
87
|
-
TerminalOutput,
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
export const terminalStderr = {
|
|
91
|
-
TerminalOutput,
|
|
92
|
-
getTerminalStderr() {
|
|
93
|
-
return terminalStderrInstance;
|
|
94
|
-
},
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
export const terminalStdin = {
|
|
98
|
-
TerminalInput,
|
|
99
|
-
getTerminalStdin() {
|
|
100
|
-
return terminalStdinInstance;
|
|
101
|
-
},
|
|
102
|
-
};
|
|
103
|
-
|
|
104
|
-
export const terminalStdout = {
|
|
105
|
-
TerminalOutput,
|
|
106
|
-
getTerminalStdout() {
|
|
107
|
-
return terminalStdoutInstance;
|
|
108
|
-
},
|
|
109
|
-
};
|
package/lib/nodejs/clocks.js
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import { createPoll } from "../io/worker-io.js";
|
|
2
|
-
import { CLOCKS_INSTANT_SUBSCRIBE, CLOCKS_DURATION_SUBSCRIBE } from "../io/calls.js";
|
|
3
|
-
import { hrtime } from "node:process";
|
|
4
|
-
|
|
5
|
-
const symbolCabiLower = Symbol.for("cabiLower");
|
|
6
|
-
|
|
7
|
-
function resolution() {
|
|
8
|
-
return 1n;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export const monotonicClock = {
|
|
12
|
-
resolution,
|
|
13
|
-
now() {
|
|
14
|
-
return hrtime.bigint();
|
|
15
|
-
},
|
|
16
|
-
subscribeInstant(instant) {
|
|
17
|
-
return createPoll(CLOCKS_INSTANT_SUBSCRIBE, null, instant);
|
|
18
|
-
},
|
|
19
|
-
subscribeDuration(duration) {
|
|
20
|
-
duration = BigInt(duration);
|
|
21
|
-
return createPoll(CLOCKS_DURATION_SUBSCRIBE, null, duration);
|
|
22
|
-
},
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
export const wallClock = {
|
|
26
|
-
resolution() {
|
|
27
|
-
return { seconds: 0n, nanoseconds: 1e6 };
|
|
28
|
-
},
|
|
29
|
-
now() {
|
|
30
|
-
const seconds = BigInt(Math.floor(Date.now() / 1e3));
|
|
31
|
-
const nanoseconds = (Date.now() % 1e3) * 1e6;
|
|
32
|
-
return { seconds, nanoseconds };
|
|
33
|
-
},
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
monotonicClock.resolution[symbolCabiLower] = () => resolution;
|
|
37
|
-
monotonicClock.now[symbolCabiLower] = () => hrtime.bigint;
|
|
38
|
-
wallClock.resolution[symbolCabiLower] = ({ memory }) => {
|
|
39
|
-
let buf32 = new Int32Array(memory.buffer);
|
|
40
|
-
return function now(retptr) {
|
|
41
|
-
if (memory.buffer !== buf32.buffer) {
|
|
42
|
-
buf32 = new Int32Array(memory.buffer);
|
|
43
|
-
}
|
|
44
|
-
if (retptr % 4) {
|
|
45
|
-
throw new Error("wasi-io trap: retptr not aligned");
|
|
46
|
-
}
|
|
47
|
-
buf32[(retptr >> 2) + 0] = 0;
|
|
48
|
-
buf32[(retptr >> 2) + 4] = 0;
|
|
49
|
-
buf32[(retptr >> 2) + 8] = 1_000_000;
|
|
50
|
-
};
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
wallClock.now[symbolCabiLower] = ({ memory }) => {
|
|
54
|
-
let buf32 = new Int32Array(memory.buffer);
|
|
55
|
-
let buf64 = new BigInt64Array(memory.buffer);
|
|
56
|
-
return function now(retptr) {
|
|
57
|
-
if (memory.buffer !== buf32.buffer) {
|
|
58
|
-
buf32 = new Int32Array(memory.buffer);
|
|
59
|
-
buf64 = new BigInt64Array(memory.buffer);
|
|
60
|
-
}
|
|
61
|
-
if (retptr % 4) {
|
|
62
|
-
throw new Error("wasi-io trap: retptr not aligned");
|
|
63
|
-
}
|
|
64
|
-
buf64[(retptr >> 2) + 0] = BigInt(Math.floor(Date.now() / 1e3));
|
|
65
|
-
buf32[(retptr >> 2) + 8] = (Date.now() % 1e3) * 1e6;
|
|
66
|
-
};
|
|
67
|
-
};
|