quickjs-wasi-reactor 0.0.1
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/LICENSE +25 -0
- package/README.md +230 -0
- package/dist/fd.d.ts +106 -0
- package/dist/fd.d.ts.map +1 -0
- package/dist/fd.js +110 -0
- package/dist/fd.js.map +1 -0
- package/dist/fs-mem.d.ts +255 -0
- package/dist/fs-mem.d.ts.map +1 -0
- package/dist/fs-mem.js +679 -0
- package/dist/fs-mem.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +13 -0
- package/dist/index.js.map +1 -0
- package/dist/quickjs.d.ts +136 -0
- package/dist/quickjs.d.ts.map +1 -0
- package/dist/quickjs.js +334 -0
- package/dist/quickjs.js.map +1 -0
- package/dist/version.d.ts +5 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +7 -0
- package/dist/version.js.map +1 -0
- package/dist/wasi-defs.d.ts +119 -0
- package/dist/wasi-defs.d.ts.map +1 -0
- package/dist/wasi-defs.js +247 -0
- package/dist/wasi-defs.js.map +1 -0
- package/dist/wasi.d.ts +41 -0
- package/dist/wasi.d.ts.map +1 -0
- package/dist/wasi.js +638 -0
- package/dist/wasi.js.map +1 -0
- package/package.json +61 -0
- package/qjs-wasi.wasm +0 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024-2026 Christian Stewart <christian@aperture.us>
|
|
4
|
+
Copyright (c) 2017-2024 Fabrice Bellard
|
|
5
|
+
Copyright (c) 2017-2024 Charlie Gordon
|
|
6
|
+
Copyright (c) 2023-2025 Ben Noordhuis
|
|
7
|
+
Copyright (c) 2023-2025 Saúl Ibarra Corretgé
|
|
8
|
+
|
|
9
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
10
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
11
|
+
in the Software without restriction, including without limitation the rights
|
|
12
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
13
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
14
|
+
furnished to do so, subject to the following conditions:
|
|
15
|
+
|
|
16
|
+
The above copyright notice and this permission notice shall be included in
|
|
17
|
+
all copies or substantial portions of the Software.
|
|
18
|
+
|
|
19
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
20
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
21
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
22
|
+
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
23
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
24
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
25
|
+
THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
# js-quickjs-wasi-reactor
|
|
2
|
+
|
|
3
|
+
> JavaScript/TypeScript harness for running QuickJS-NG in WASI reactor mode
|
|
4
|
+
|
|
5
|
+
This package provides a JavaScript/TypeScript implementation for running QuickJS-NG compiled to WebAssembly using the WASI reactor model. It includes a complete browser-compatible WASI shim and high-level API for JavaScript execution.
|
|
6
|
+
|
|
7
|
+
## Related Projects
|
|
8
|
+
|
|
9
|
+
- [go-quickjs-wasi-reactor](https://github.com/aperturerobotics/go-quickjs-wasi-reactor) - Go implementation with wazero
|
|
10
|
+
- [paralin/quickjs](https://github.com/paralin/quickjs) - QuickJS-NG fork with reactor build target
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
npm install quickjs-wasi-reactor
|
|
16
|
+
# or
|
|
17
|
+
bun add quickjs-wasi-reactor
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Usage
|
|
21
|
+
|
|
22
|
+
### Basic Usage
|
|
23
|
+
|
|
24
|
+
```typescript
|
|
25
|
+
import { loadQuickJS, buildFileSystem } from 'quickjs-wasi-reactor'
|
|
26
|
+
|
|
27
|
+
// Load QuickJS from a URL or buffer
|
|
28
|
+
const qjs = await loadQuickJS('/path/to/qjs-wasi.wasm')
|
|
29
|
+
|
|
30
|
+
// Initialize with std module
|
|
31
|
+
qjs.initArgv()
|
|
32
|
+
|
|
33
|
+
// Evaluate JavaScript code
|
|
34
|
+
qjs.eval(`console.log("Hello from QuickJS!")`)
|
|
35
|
+
|
|
36
|
+
// Run the event loop
|
|
37
|
+
await qjs.runLoop()
|
|
38
|
+
|
|
39
|
+
// Cleanup
|
|
40
|
+
qjs.destroy()
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### With Virtual Filesystem
|
|
44
|
+
|
|
45
|
+
```typescript
|
|
46
|
+
import { loadQuickJS, buildFileSystem } from 'quickjs-wasi-reactor'
|
|
47
|
+
|
|
48
|
+
// Build a virtual filesystem
|
|
49
|
+
const fs = buildFileSystem(
|
|
50
|
+
new Map([
|
|
51
|
+
['script.js', 'console.log("Hello from script!")'],
|
|
52
|
+
['lib/utils.js', 'export function greet(name) { return `Hello, ${name}!` }'],
|
|
53
|
+
]),
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
const qjs = await loadQuickJS('/path/to/qjs-wasi.wasm', {
|
|
57
|
+
args: ['qjs', '--std', 'script.js'],
|
|
58
|
+
fs,
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
qjs.initArgv()
|
|
62
|
+
await qjs.runLoop()
|
|
63
|
+
qjs.destroy()
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### Custom I/O Handlers
|
|
67
|
+
|
|
68
|
+
```typescript
|
|
69
|
+
import { loadQuickJS } from 'quickjs-wasi-reactor'
|
|
70
|
+
|
|
71
|
+
const qjs = await loadQuickJS('/path/to/qjs-wasi.wasm', {
|
|
72
|
+
stdout: (line) => document.body.innerHTML += `<p>${line}</p>`,
|
|
73
|
+
stderr: (line) => console.error('Error:', line),
|
|
74
|
+
onDevOut: (data) => {
|
|
75
|
+
// Handle binary data written to /dev/out
|
|
76
|
+
console.log('Received', data.length, 'bytes')
|
|
77
|
+
},
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
qjs.initArgv()
|
|
81
|
+
qjs.eval(`console.log("This goes to custom stdout")`)
|
|
82
|
+
await qjs.runLoop()
|
|
83
|
+
qjs.destroy()
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### Feeding Stdin Data
|
|
87
|
+
|
|
88
|
+
```typescript
|
|
89
|
+
import { loadQuickJS, PollableStdin } from 'quickjs-wasi-reactor'
|
|
90
|
+
|
|
91
|
+
const stdin = new PollableStdin()
|
|
92
|
+
|
|
93
|
+
const qjs = await loadQuickJS('/path/to/qjs-wasi.wasm', { stdin })
|
|
94
|
+
|
|
95
|
+
qjs.initArgv()
|
|
96
|
+
|
|
97
|
+
// Push data to stdin
|
|
98
|
+
qjs.pushStdin(new TextEncoder().encode('Hello from stdin\n'))
|
|
99
|
+
|
|
100
|
+
// Run the loop - QuickJS can read from stdin
|
|
101
|
+
await qjs.runLoop()
|
|
102
|
+
qjs.destroy()
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
## API
|
|
106
|
+
|
|
107
|
+
### `loadQuickJS(wasmSource, options?)`
|
|
108
|
+
|
|
109
|
+
Load and create a QuickJS instance from a WASM source.
|
|
110
|
+
|
|
111
|
+
**Parameters:**
|
|
112
|
+
|
|
113
|
+
- `wasmSource`: URL string, `Response`, `ArrayBuffer`, or `Uint8Array`
|
|
114
|
+
- `options`: Optional configuration (see `QuickJSOptions`)
|
|
115
|
+
|
|
116
|
+
**Returns:** `Promise<QuickJS>`
|
|
117
|
+
|
|
118
|
+
### `createQuickJS(wasmModule, options?)`
|
|
119
|
+
|
|
120
|
+
Create a QuickJS instance from a pre-compiled WebAssembly module.
|
|
121
|
+
|
|
122
|
+
**Parameters:**
|
|
123
|
+
|
|
124
|
+
- `wasmModule`: `WebAssembly.Module`
|
|
125
|
+
- `options`: Optional configuration
|
|
126
|
+
|
|
127
|
+
**Returns:** `QuickJS`
|
|
128
|
+
|
|
129
|
+
### `QuickJSOptions`
|
|
130
|
+
|
|
131
|
+
| Option | Type | Default | Description |
|
|
132
|
+
| ---------- | --------------------------- | ------------------------- | ---------------------------------- |
|
|
133
|
+
| `args` | `string[]` | `['qjs', '--std']` | WASI command-line arguments |
|
|
134
|
+
| `env` | `string[]` | `[]` | Environment variables (key=value) |
|
|
135
|
+
| `debug` | `boolean` | `false` | Enable WASI debug logging |
|
|
136
|
+
| `stdout` | `(line: string) => void` | `console.log` | Custom stdout line handler |
|
|
137
|
+
| `stderr` | `(line: string) => void` | `console.error` | Custom stderr line handler |
|
|
138
|
+
| `fs` | `Map<string, File\|Dir>` | `new Map()` | Virtual filesystem root contents |
|
|
139
|
+
| `onDevOut` | `(data: Uint8Array) => void`| `undefined` | Handler for /dev/out writes |
|
|
140
|
+
| `stdin` | `PollableStdin` | `new PollableStdin()` | Custom stdin source |
|
|
141
|
+
|
|
142
|
+
### `QuickJS` Methods
|
|
143
|
+
|
|
144
|
+
#### `initArgv()`
|
|
145
|
+
|
|
146
|
+
Initialize QuickJS with command-line arguments. Call this after creating the instance.
|
|
147
|
+
|
|
148
|
+
#### `init()`
|
|
149
|
+
|
|
150
|
+
Initialize QuickJS with an empty context (without loading scripts via args).
|
|
151
|
+
|
|
152
|
+
#### `eval(code, isModule?, filename?)`
|
|
153
|
+
|
|
154
|
+
Evaluate JavaScript code.
|
|
155
|
+
|
|
156
|
+
- `code`: JavaScript source code
|
|
157
|
+
- `isModule`: Treat as ES module (default: `false`)
|
|
158
|
+
- `filename`: Filename for error messages (default: `'<eval>'`)
|
|
159
|
+
|
|
160
|
+
#### `loopOnce()`
|
|
161
|
+
|
|
162
|
+
Run one iteration of the event loop. Returns:
|
|
163
|
+
|
|
164
|
+
- `> 0`: Next timer fires in N milliseconds
|
|
165
|
+
- `0`: More microtasks pending
|
|
166
|
+
- `-1` (`LOOP_IDLE`): No pending work
|
|
167
|
+
- `-2` (`LOOP_ERROR`): Error occurred
|
|
168
|
+
|
|
169
|
+
#### `runLoop(onTick?)`
|
|
170
|
+
|
|
171
|
+
Run the event loop until idle. Yields to the browser event loop between iterations.
|
|
172
|
+
|
|
173
|
+
**Returns:** `Promise<number>` (exit code)
|
|
174
|
+
|
|
175
|
+
#### `runLoopSync()`
|
|
176
|
+
|
|
177
|
+
Run the event loop synchronously. Suitable for Node.js/Bun.
|
|
178
|
+
|
|
179
|
+
**Returns:** `number` (exit code)
|
|
180
|
+
|
|
181
|
+
#### `pollIO(timeoutMs?)`
|
|
182
|
+
|
|
183
|
+
Poll for I/O events and invoke handlers.
|
|
184
|
+
|
|
185
|
+
#### `pushStdin(data)`
|
|
186
|
+
|
|
187
|
+
Push data to stdin for the QuickJS instance to read.
|
|
188
|
+
|
|
189
|
+
#### `hasStdinData()`
|
|
190
|
+
|
|
191
|
+
Check if stdin has data available.
|
|
192
|
+
|
|
193
|
+
#### `stop()`
|
|
194
|
+
|
|
195
|
+
Stop the event loop.
|
|
196
|
+
|
|
197
|
+
#### `destroy()`
|
|
198
|
+
|
|
199
|
+
Destroy the QuickJS runtime and release resources.
|
|
200
|
+
|
|
201
|
+
### `buildFileSystem(files)`
|
|
202
|
+
|
|
203
|
+
Build a virtual filesystem from a map of paths to content.
|
|
204
|
+
|
|
205
|
+
```typescript
|
|
206
|
+
const fs = buildFileSystem(
|
|
207
|
+
new Map([
|
|
208
|
+
['path/to/file.js', 'content'],
|
|
209
|
+
['another/file.txt', new Uint8Array([1, 2, 3])],
|
|
210
|
+
]),
|
|
211
|
+
)
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
## Reactor Model
|
|
215
|
+
|
|
216
|
+
Unlike the standard WASI "command" model that blocks in `_start()`, the reactor model exports functions that the host calls:
|
|
217
|
+
|
|
218
|
+
- `qjs_init()` - Initialize empty runtime
|
|
219
|
+
- `qjs_init_argv(argc, argv)` - Initialize with CLI args
|
|
220
|
+
- `qjs_eval(code, len, filename, is_module)` - Evaluate JS code
|
|
221
|
+
- `qjs_loop_once()` - Run one event loop iteration
|
|
222
|
+
- `qjs_poll_io(timeout_ms)` - Poll for I/O events
|
|
223
|
+
- `qjs_destroy()` - Cleanup runtime
|
|
224
|
+
- `malloc/free` - Memory allocation
|
|
225
|
+
|
|
226
|
+
This enables re-entrant execution in JavaScript host environments where blocking is not possible.
|
|
227
|
+
|
|
228
|
+
## License
|
|
229
|
+
|
|
230
|
+
MIT
|
package/dist/fd.d.ts
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import * as wasi from "./wasi-defs.js";
|
|
2
|
+
/**
|
|
3
|
+
* PollResult is returned by fd_poll to indicate readiness for I/O.
|
|
4
|
+
*/
|
|
5
|
+
export interface PollResult {
|
|
6
|
+
/** Whether the fd is ready for the requested operation */
|
|
7
|
+
ready: boolean;
|
|
8
|
+
/** Number of bytes available to read (for FD_READ) */
|
|
9
|
+
nbytes: bigint;
|
|
10
|
+
/** Any flags to set on the event (e.g., HANGUP) */
|
|
11
|
+
flags: number;
|
|
12
|
+
}
|
|
13
|
+
export declare abstract class Fd {
|
|
14
|
+
fd_allocate(_offset: bigint, _len: bigint): number;
|
|
15
|
+
fd_close(): number;
|
|
16
|
+
fd_fdstat_get(): {
|
|
17
|
+
ret: number;
|
|
18
|
+
fdstat: wasi.Fdstat | null;
|
|
19
|
+
};
|
|
20
|
+
fd_fdstat_set_flags(_flags: number): number;
|
|
21
|
+
fd_fdstat_set_rights(_fs_rights_base: bigint, _fs_rights_inheriting: bigint): number;
|
|
22
|
+
fd_filestat_get(): {
|
|
23
|
+
ret: number;
|
|
24
|
+
filestat: wasi.Filestat | null;
|
|
25
|
+
};
|
|
26
|
+
fd_filestat_set_size(_size: bigint): number;
|
|
27
|
+
fd_filestat_set_times(_atim: bigint, _mtim: bigint, _fst_flags: number): number;
|
|
28
|
+
fd_pread(_size: number, _offset: bigint): {
|
|
29
|
+
ret: number;
|
|
30
|
+
data: Uint8Array;
|
|
31
|
+
};
|
|
32
|
+
fd_prestat_get(): {
|
|
33
|
+
ret: number;
|
|
34
|
+
prestat: wasi.Prestat | null;
|
|
35
|
+
};
|
|
36
|
+
fd_pwrite(_data: Uint8Array, _offset: bigint): {
|
|
37
|
+
ret: number;
|
|
38
|
+
nwritten: number;
|
|
39
|
+
};
|
|
40
|
+
fd_read(_size: number): {
|
|
41
|
+
ret: number;
|
|
42
|
+
data: Uint8Array;
|
|
43
|
+
};
|
|
44
|
+
fd_readdir_single(_cookie: bigint): {
|
|
45
|
+
ret: number;
|
|
46
|
+
dirent: wasi.Dirent | null;
|
|
47
|
+
};
|
|
48
|
+
fd_seek(_offset: bigint, _whence: number): {
|
|
49
|
+
ret: number;
|
|
50
|
+
offset: bigint;
|
|
51
|
+
};
|
|
52
|
+
fd_sync(): number;
|
|
53
|
+
fd_tell(): {
|
|
54
|
+
ret: number;
|
|
55
|
+
offset: bigint;
|
|
56
|
+
};
|
|
57
|
+
fd_write(_data: Uint8Array): {
|
|
58
|
+
ret: number;
|
|
59
|
+
nwritten: number;
|
|
60
|
+
};
|
|
61
|
+
path_create_directory(_path: string): number;
|
|
62
|
+
path_filestat_get(_flags: number, _path: string): {
|
|
63
|
+
ret: number;
|
|
64
|
+
filestat: wasi.Filestat | null;
|
|
65
|
+
};
|
|
66
|
+
path_filestat_set_times(_flags: number, _path: string, _atim: bigint, _mtim: bigint, _fst_flags: number): number;
|
|
67
|
+
path_link(_path: string, _inode: Inode, _allow_dir: boolean): number;
|
|
68
|
+
path_unlink(_path: string): {
|
|
69
|
+
ret: number;
|
|
70
|
+
inode_obj: Inode | null;
|
|
71
|
+
};
|
|
72
|
+
path_lookup(_path: string, _dirflags: number): {
|
|
73
|
+
ret: number;
|
|
74
|
+
inode_obj: Inode | null;
|
|
75
|
+
};
|
|
76
|
+
path_open(_dirflags: number, _path: string, _oflags: number, _fs_rights_base: bigint, _fs_rights_inheriting: bigint, _fd_flags: number): {
|
|
77
|
+
ret: number;
|
|
78
|
+
fd_obj: Fd | null;
|
|
79
|
+
};
|
|
80
|
+
path_readlink(_path: string): {
|
|
81
|
+
ret: number;
|
|
82
|
+
data: string | null;
|
|
83
|
+
};
|
|
84
|
+
path_remove_directory(_path: string): number;
|
|
85
|
+
path_rename(_old_path: string, _new_fd: number, _new_path: string): number;
|
|
86
|
+
path_unlink_file(_path: string): number;
|
|
87
|
+
/**
|
|
88
|
+
* Poll for I/O readiness. Override this in subclasses that support polling.
|
|
89
|
+
* @param eventtype EVENTTYPE_FD_READ or EVENTTYPE_FD_WRITE
|
|
90
|
+
* @returns PollResult indicating readiness
|
|
91
|
+
*/
|
|
92
|
+
fd_poll(_eventtype: number): PollResult;
|
|
93
|
+
}
|
|
94
|
+
export declare abstract class Inode {
|
|
95
|
+
ino: bigint;
|
|
96
|
+
constructor();
|
|
97
|
+
private static next_ino;
|
|
98
|
+
static issue_ino(): bigint;
|
|
99
|
+
static root_ino(): bigint;
|
|
100
|
+
abstract path_open(oflags: number, fs_rights_base: bigint, fd_flags: number): {
|
|
101
|
+
ret: number;
|
|
102
|
+
fd_obj: Fd | null;
|
|
103
|
+
};
|
|
104
|
+
abstract stat(): wasi.Filestat;
|
|
105
|
+
}
|
|
106
|
+
//# sourceMappingURL=fd.d.ts.map
|
package/dist/fd.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fd.d.ts","sourceRoot":"","sources":["../src/fd.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,IAAI,MAAM,gBAAgB,CAAC;AAEvC;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,0DAA0D;IAC1D,KAAK,EAAE,OAAO,CAAC;IACf,sDAA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EAAE,MAAM,EACf,eAAe,EAAE,MAAM,EACvB,qBAAqB,EAAE,MAAM,EAC7B,SAAS,EAAE,MAAM,GAChB;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,EAAE,GAAG,IAAI,CAAA;KAAE;IAGrC,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAA;KAAE;IAGlE,qBAAqB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;IAG5C,WAAW,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM;IAG1E,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;IAIvC;;;;OAIG;IACH,OAAO,CAAC,UAAU,EAAE,MAAM,GAAG,UAAU;CAGxC;AAED,8BAAsB,KAAK;IACzB,GAAG,EAAE,MAAM,CAAC;;IAMZ,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAc;IACrC,MAAM,CAAC,SAAS,IAAI,MAAM;IAG1B,MAAM,CAAC,QAAQ,IAAI,MAAM;IAIzB,QAAQ,CAAC,SAAS,CAChB,MAAM,EAAE,MAAM,EACd,cAAc,EAAE,MAAM,EACtB,QAAQ,EAAE,MAAM,GACf;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,EAAE,GAAG,IAAI,CAAA;KAAE;IAErC,QAAQ,CAAC,IAAI,IAAI,IAAI,CAAC,QAAQ;CAC/B"}
|
package/dist/fd.js
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
// File descriptor abstraction for WASI
|
|
2
|
+
import * as wasi from "./wasi-defs.js";
|
|
3
|
+
export class Fd {
|
|
4
|
+
fd_allocate(_offset, _len) {
|
|
5
|
+
return wasi.ERRNO_NOTSUP;
|
|
6
|
+
}
|
|
7
|
+
fd_close() {
|
|
8
|
+
return 0;
|
|
9
|
+
}
|
|
10
|
+
fd_fdstat_get() {
|
|
11
|
+
return { ret: wasi.ERRNO_NOTSUP, fdstat: null };
|
|
12
|
+
}
|
|
13
|
+
fd_fdstat_set_flags(_flags) {
|
|
14
|
+
return wasi.ERRNO_NOTSUP;
|
|
15
|
+
}
|
|
16
|
+
fd_fdstat_set_rights(_fs_rights_base, _fs_rights_inheriting) {
|
|
17
|
+
return wasi.ERRNO_NOTSUP;
|
|
18
|
+
}
|
|
19
|
+
fd_filestat_get() {
|
|
20
|
+
return { ret: wasi.ERRNO_NOTSUP, filestat: null };
|
|
21
|
+
}
|
|
22
|
+
fd_filestat_set_size(_size) {
|
|
23
|
+
return wasi.ERRNO_NOTSUP;
|
|
24
|
+
}
|
|
25
|
+
fd_filestat_set_times(_atim, _mtim, _fst_flags) {
|
|
26
|
+
return wasi.ERRNO_NOTSUP;
|
|
27
|
+
}
|
|
28
|
+
fd_pread(_size, _offset) {
|
|
29
|
+
return { ret: wasi.ERRNO_NOTSUP, data: new Uint8Array() };
|
|
30
|
+
}
|
|
31
|
+
fd_prestat_get() {
|
|
32
|
+
return { ret: wasi.ERRNO_NOTSUP, prestat: null };
|
|
33
|
+
}
|
|
34
|
+
fd_pwrite(_data, _offset) {
|
|
35
|
+
return { ret: wasi.ERRNO_NOTSUP, nwritten: 0 };
|
|
36
|
+
}
|
|
37
|
+
fd_read(_size) {
|
|
38
|
+
return { ret: wasi.ERRNO_NOTSUP, data: new Uint8Array() };
|
|
39
|
+
}
|
|
40
|
+
fd_readdir_single(_cookie) {
|
|
41
|
+
return { ret: wasi.ERRNO_NOTSUP, dirent: null };
|
|
42
|
+
}
|
|
43
|
+
fd_seek(_offset, _whence) {
|
|
44
|
+
return { ret: wasi.ERRNO_NOTSUP, offset: 0n };
|
|
45
|
+
}
|
|
46
|
+
fd_sync() {
|
|
47
|
+
return 0;
|
|
48
|
+
}
|
|
49
|
+
fd_tell() {
|
|
50
|
+
return { ret: wasi.ERRNO_NOTSUP, offset: 0n };
|
|
51
|
+
}
|
|
52
|
+
fd_write(_data) {
|
|
53
|
+
return { ret: wasi.ERRNO_NOTSUP, nwritten: 0 };
|
|
54
|
+
}
|
|
55
|
+
path_create_directory(_path) {
|
|
56
|
+
return wasi.ERRNO_NOTSUP;
|
|
57
|
+
}
|
|
58
|
+
path_filestat_get(_flags, _path) {
|
|
59
|
+
return { ret: wasi.ERRNO_NOTSUP, filestat: null };
|
|
60
|
+
}
|
|
61
|
+
path_filestat_set_times(_flags, _path, _atim, _mtim, _fst_flags) {
|
|
62
|
+
return wasi.ERRNO_NOTSUP;
|
|
63
|
+
}
|
|
64
|
+
path_link(_path, _inode, _allow_dir) {
|
|
65
|
+
return wasi.ERRNO_NOTSUP;
|
|
66
|
+
}
|
|
67
|
+
path_unlink(_path) {
|
|
68
|
+
return { ret: wasi.ERRNO_NOTSUP, inode_obj: null };
|
|
69
|
+
}
|
|
70
|
+
path_lookup(_path, _dirflags) {
|
|
71
|
+
return { ret: wasi.ERRNO_NOTSUP, inode_obj: null };
|
|
72
|
+
}
|
|
73
|
+
path_open(_dirflags, _path, _oflags, _fs_rights_base, _fs_rights_inheriting, _fd_flags) {
|
|
74
|
+
return { ret: wasi.ERRNO_NOTDIR, fd_obj: null };
|
|
75
|
+
}
|
|
76
|
+
path_readlink(_path) {
|
|
77
|
+
return { ret: wasi.ERRNO_NOTSUP, data: null };
|
|
78
|
+
}
|
|
79
|
+
path_remove_directory(_path) {
|
|
80
|
+
return wasi.ERRNO_NOTSUP;
|
|
81
|
+
}
|
|
82
|
+
path_rename(_old_path, _new_fd, _new_path) {
|
|
83
|
+
return wasi.ERRNO_NOTSUP;
|
|
84
|
+
}
|
|
85
|
+
path_unlink_file(_path) {
|
|
86
|
+
return wasi.ERRNO_NOTSUP;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Poll for I/O readiness. Override this in subclasses that support polling.
|
|
90
|
+
* @param eventtype EVENTTYPE_FD_READ or EVENTTYPE_FD_WRITE
|
|
91
|
+
* @returns PollResult indicating readiness
|
|
92
|
+
*/
|
|
93
|
+
fd_poll(_eventtype) {
|
|
94
|
+
return { ready: false, nbytes: 0n, flags: 0 };
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
export class Inode {
|
|
98
|
+
ino;
|
|
99
|
+
constructor() {
|
|
100
|
+
this.ino = Inode.issue_ino();
|
|
101
|
+
}
|
|
102
|
+
static next_ino = 1n;
|
|
103
|
+
static issue_ino() {
|
|
104
|
+
return Inode.next_ino++;
|
|
105
|
+
}
|
|
106
|
+
static root_ino() {
|
|
107
|
+
return 0n;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
//# sourceMappingURL=fd.js.map
|
package/dist/fd.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fd.js","sourceRoot":"","sources":["../src/fd.ts"],"names":[],"mappings":"AAAA,uCAAuC;AAEvC,OAAO,KAAK,IAAI,MAAM,gBAAgB,CAAC;AAcvC,MAAM,OAAgB,EAAE;IACtB,WAAW,CAAC,OAAe,EAAE,IAAY;QACvC,OAAO,IAAI,CAAC,YAAY,CAAC;IAC3B,CAAC;IACD,QAAQ;QACN,OAAO,CAAC,CAAC;IACX,CAAC;IACD,aAAa;QACX,OAAO,EAAE,GAAG,EAAE,IAAI,CAAC,YAAY,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;IAClD,CAAC;IACD,mBAAmB,CAAC,MAAc;QAChC,OAAO,IAAI,CAAC,YAAY,CAAC;IAC3B,CAAC;IACD,oBAAoB,CAClB,eAAuB,EACvB,qBAA6B;QAE7B,OAAO,IAAI,CAAC,YAAY,CAAC;IAC3B,CAAC;IACD,eAAe;QACb,OAAO,EAAE,GAAG,EAAE,IAAI,CAAC,YAAY,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;IACpD,CAAC;IACD,oBAAoB,CAAC,KAAa;QAChC,OAAO,IAAI,CAAC,YAAY,CAAC;IAC3B,CAAC;IACD,qBAAqB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