fullbleed 0.2.0 → 0.3.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/README.md +65 -8
- package/dist/THIRD_PARTY_NOTICES.txt +2 -2
- package/dist/browser/asset-manifest.json +67 -0
- package/dist/browser/client.js +225 -0
- package/dist/browser/worker.js +1477 -0
- package/dist/build.json +20 -8
- package/dist/engine.wasm +0 -0
- package/package.json +18 -6
- package/src/browser-worker.js +39 -0
- package/src/browser.d.ts +37 -0
- package/src/browser.js +103 -0
- package/src/copy-browser-assets.cjs +43 -0
- package/src/engine-runner.js +46 -0
- package/src/index.cjs +1 -45
- package/src/render-input.cjs +51 -0
- package/src/worker.js +3 -43
|
@@ -0,0 +1,1477 @@
|
|
|
1
|
+
// <define:__FULLBLEED_FONT_NAMES__>
|
|
2
|
+
var define_FULLBLEED_FONT_NAMES_default = ["Inter-Variable.ttf", "DMSerifDisplay-Regular.ttf", "DMSerifDisplay-Italic.ttf", "BebasNeue-Regular.ttf"];
|
|
3
|
+
|
|
4
|
+
// <define:__FULLBLEED_RUNTIME_FILES__>
|
|
5
|
+
var define_FULLBLEED_RUNTIME_FILES_default = { "engine.wasm": { bytes: 5075752, sha256: "4fcbecb954f6a5a64ea840795e74d719cc045d5ba35d5ffa730fcb46b3ce8b3c" }, "fonts/Inter-Variable.ttf": { bytes: 876576, sha256: "29160a80ff49ddcab2c97711247e08b1fab27a484a329ce8b813d820dc559031" }, "fonts/DMSerifDisplay-Regular.ttf": { bytes: 76580, sha256: "8cc3643535edf039aa5d95440a8542735e9197e4f4b8d9303e980fefbf5ab616" }, "fonts/DMSerifDisplay-Italic.ttf": { bytes: 71208, sha256: "df74c0ac387baeaeb0fe4f2324e1668e6a3ed8c09cd9796fe162c71753e19e45" }, "fonts/BebasNeue-Regular.ttf": { bytes: 61400, sha256: "08e4623805102d819f58601e46e345648846075e363b2ceb23313c2d1c83ec73" } };
|
|
6
|
+
|
|
7
|
+
// node_modules/@bjorn3/browser_wasi_shim/dist/wasi_defs.js
|
|
8
|
+
var CLOCKID_REALTIME = 0;
|
|
9
|
+
var CLOCKID_MONOTONIC = 1;
|
|
10
|
+
var ERRNO_SUCCESS = 0;
|
|
11
|
+
var ERRNO_BADF = 8;
|
|
12
|
+
var ERRNO_EXIST = 20;
|
|
13
|
+
var ERRNO_INVAL = 28;
|
|
14
|
+
var ERRNO_ISDIR = 31;
|
|
15
|
+
var ERRNO_NAMETOOLONG = 37;
|
|
16
|
+
var ERRNO_NOENT = 44;
|
|
17
|
+
var ERRNO_NOSYS = 52;
|
|
18
|
+
var ERRNO_NOTDIR = 54;
|
|
19
|
+
var ERRNO_NOTEMPTY = 55;
|
|
20
|
+
var ERRNO_NOTSUP = 58;
|
|
21
|
+
var ERRNO_PERM = 63;
|
|
22
|
+
var ERRNO_NOTCAPABLE = 76;
|
|
23
|
+
var RIGHTS_FD_DATASYNC = 1 << 0;
|
|
24
|
+
var RIGHTS_FD_READ = 1 << 1;
|
|
25
|
+
var RIGHTS_FD_SEEK = 1 << 2;
|
|
26
|
+
var RIGHTS_FD_FDSTAT_SET_FLAGS = 1 << 3;
|
|
27
|
+
var RIGHTS_FD_SYNC = 1 << 4;
|
|
28
|
+
var RIGHTS_FD_TELL = 1 << 5;
|
|
29
|
+
var RIGHTS_FD_WRITE = 1 << 6;
|
|
30
|
+
var RIGHTS_FD_ADVISE = 1 << 7;
|
|
31
|
+
var RIGHTS_FD_ALLOCATE = 1 << 8;
|
|
32
|
+
var RIGHTS_PATH_CREATE_DIRECTORY = 1 << 9;
|
|
33
|
+
var RIGHTS_PATH_CREATE_FILE = 1 << 10;
|
|
34
|
+
var RIGHTS_PATH_LINK_SOURCE = 1 << 11;
|
|
35
|
+
var RIGHTS_PATH_LINK_TARGET = 1 << 12;
|
|
36
|
+
var RIGHTS_PATH_OPEN = 1 << 13;
|
|
37
|
+
var RIGHTS_FD_READDIR = 1 << 14;
|
|
38
|
+
var RIGHTS_PATH_READLINK = 1 << 15;
|
|
39
|
+
var RIGHTS_PATH_RENAME_SOURCE = 1 << 16;
|
|
40
|
+
var RIGHTS_PATH_RENAME_TARGET = 1 << 17;
|
|
41
|
+
var RIGHTS_PATH_FILESTAT_GET = 1 << 18;
|
|
42
|
+
var RIGHTS_PATH_FILESTAT_SET_SIZE = 1 << 19;
|
|
43
|
+
var RIGHTS_PATH_FILESTAT_SET_TIMES = 1 << 20;
|
|
44
|
+
var RIGHTS_FD_FILESTAT_GET = 1 << 21;
|
|
45
|
+
var RIGHTS_FD_FILESTAT_SET_SIZE = 1 << 22;
|
|
46
|
+
var RIGHTS_FD_FILESTAT_SET_TIMES = 1 << 23;
|
|
47
|
+
var RIGHTS_PATH_SYMLINK = 1 << 24;
|
|
48
|
+
var RIGHTS_PATH_REMOVE_DIRECTORY = 1 << 25;
|
|
49
|
+
var RIGHTS_PATH_UNLINK_FILE = 1 << 26;
|
|
50
|
+
var RIGHTS_POLL_FD_READWRITE = 1 << 27;
|
|
51
|
+
var RIGHTS_SOCK_SHUTDOWN = 1 << 28;
|
|
52
|
+
var Iovec = class _Iovec {
|
|
53
|
+
static read_bytes(view, ptr) {
|
|
54
|
+
const iovec = new _Iovec();
|
|
55
|
+
iovec.buf = view.getUint32(ptr, true);
|
|
56
|
+
iovec.buf_len = view.getUint32(ptr + 4, true);
|
|
57
|
+
return iovec;
|
|
58
|
+
}
|
|
59
|
+
static read_bytes_array(view, ptr, len) {
|
|
60
|
+
const iovecs = [];
|
|
61
|
+
for (let i = 0; i < len; i++) {
|
|
62
|
+
iovecs.push(_Iovec.read_bytes(view, ptr + 8 * i));
|
|
63
|
+
}
|
|
64
|
+
return iovecs;
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
var Ciovec = class _Ciovec {
|
|
68
|
+
static read_bytes(view, ptr) {
|
|
69
|
+
const iovec = new _Ciovec();
|
|
70
|
+
iovec.buf = view.getUint32(ptr, true);
|
|
71
|
+
iovec.buf_len = view.getUint32(ptr + 4, true);
|
|
72
|
+
return iovec;
|
|
73
|
+
}
|
|
74
|
+
static read_bytes_array(view, ptr, len) {
|
|
75
|
+
const iovecs = [];
|
|
76
|
+
for (let i = 0; i < len; i++) {
|
|
77
|
+
iovecs.push(_Ciovec.read_bytes(view, ptr + 8 * i));
|
|
78
|
+
}
|
|
79
|
+
return iovecs;
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
var WHENCE_SET = 0;
|
|
83
|
+
var WHENCE_CUR = 1;
|
|
84
|
+
var WHENCE_END = 2;
|
|
85
|
+
var FILETYPE_CHARACTER_DEVICE = 2;
|
|
86
|
+
var FILETYPE_DIRECTORY = 3;
|
|
87
|
+
var FILETYPE_REGULAR_FILE = 4;
|
|
88
|
+
var Dirent = class {
|
|
89
|
+
head_length() {
|
|
90
|
+
return 24;
|
|
91
|
+
}
|
|
92
|
+
name_length() {
|
|
93
|
+
return this.dir_name.byteLength;
|
|
94
|
+
}
|
|
95
|
+
write_head_bytes(view, ptr) {
|
|
96
|
+
view.setBigUint64(ptr, this.d_next, true);
|
|
97
|
+
view.setBigUint64(ptr + 8, this.d_ino, true);
|
|
98
|
+
view.setUint32(ptr + 16, this.dir_name.length, true);
|
|
99
|
+
view.setUint8(ptr + 20, this.d_type);
|
|
100
|
+
}
|
|
101
|
+
write_name_bytes(view8, ptr, buf_len) {
|
|
102
|
+
view8.set(this.dir_name.slice(0, Math.min(this.dir_name.byteLength, buf_len)), ptr);
|
|
103
|
+
}
|
|
104
|
+
constructor(next_cookie, d_ino, name, type) {
|
|
105
|
+
const encoded_name = new TextEncoder().encode(name);
|
|
106
|
+
this.d_next = next_cookie;
|
|
107
|
+
this.d_ino = d_ino;
|
|
108
|
+
this.d_namlen = encoded_name.byteLength;
|
|
109
|
+
this.d_type = type;
|
|
110
|
+
this.dir_name = encoded_name;
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
var FDFLAGS_APPEND = 1 << 0;
|
|
114
|
+
var FDFLAGS_DSYNC = 1 << 1;
|
|
115
|
+
var FDFLAGS_NONBLOCK = 1 << 2;
|
|
116
|
+
var FDFLAGS_RSYNC = 1 << 3;
|
|
117
|
+
var FDFLAGS_SYNC = 1 << 4;
|
|
118
|
+
var Fdstat = class {
|
|
119
|
+
write_bytes(view, ptr) {
|
|
120
|
+
view.setUint8(ptr, this.fs_filetype);
|
|
121
|
+
view.setUint16(ptr + 2, this.fs_flags, true);
|
|
122
|
+
view.setBigUint64(ptr + 8, this.fs_rights_base, true);
|
|
123
|
+
view.setBigUint64(ptr + 16, this.fs_rights_inherited, true);
|
|
124
|
+
}
|
|
125
|
+
constructor(filetype, flags) {
|
|
126
|
+
this.fs_rights_base = 0n;
|
|
127
|
+
this.fs_rights_inherited = 0n;
|
|
128
|
+
this.fs_filetype = filetype;
|
|
129
|
+
this.fs_flags = flags;
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
var FSTFLAGS_ATIM = 1 << 0;
|
|
133
|
+
var FSTFLAGS_ATIM_NOW = 1 << 1;
|
|
134
|
+
var FSTFLAGS_MTIM = 1 << 2;
|
|
135
|
+
var FSTFLAGS_MTIM_NOW = 1 << 3;
|
|
136
|
+
var OFLAGS_CREAT = 1 << 0;
|
|
137
|
+
var OFLAGS_DIRECTORY = 1 << 1;
|
|
138
|
+
var OFLAGS_EXCL = 1 << 2;
|
|
139
|
+
var OFLAGS_TRUNC = 1 << 3;
|
|
140
|
+
var Filestat = class {
|
|
141
|
+
write_bytes(view, ptr) {
|
|
142
|
+
view.setBigUint64(ptr, this.dev, true);
|
|
143
|
+
view.setBigUint64(ptr + 8, this.ino, true);
|
|
144
|
+
view.setUint8(ptr + 16, this.filetype);
|
|
145
|
+
view.setBigUint64(ptr + 24, this.nlink, true);
|
|
146
|
+
view.setBigUint64(ptr + 32, this.size, true);
|
|
147
|
+
view.setBigUint64(ptr + 38, this.atim, true);
|
|
148
|
+
view.setBigUint64(ptr + 46, this.mtim, true);
|
|
149
|
+
view.setBigUint64(ptr + 52, this.ctim, true);
|
|
150
|
+
}
|
|
151
|
+
constructor(ino, filetype, size) {
|
|
152
|
+
this.dev = 0n;
|
|
153
|
+
this.nlink = 0n;
|
|
154
|
+
this.atim = 0n;
|
|
155
|
+
this.mtim = 0n;
|
|
156
|
+
this.ctim = 0n;
|
|
157
|
+
this.ino = ino;
|
|
158
|
+
this.filetype = filetype;
|
|
159
|
+
this.size = size;
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
var EVENTTYPE_CLOCK = 0;
|
|
163
|
+
var EVENTRWFLAGS_FD_READWRITE_HANGUP = 1 << 0;
|
|
164
|
+
var SUBCLOCKFLAGS_SUBSCRIPTION_CLOCK_ABSTIME = 1 << 0;
|
|
165
|
+
var Subscription = class _Subscription {
|
|
166
|
+
static read_bytes(view, ptr) {
|
|
167
|
+
return new _Subscription(view.getBigUint64(ptr, true), view.getUint8(ptr + 8), view.getUint32(ptr + 16, true), view.getBigUint64(ptr + 24, true), view.getUint16(ptr + 36, true));
|
|
168
|
+
}
|
|
169
|
+
constructor(userdata, eventtype, clockid, timeout, flags) {
|
|
170
|
+
this.userdata = userdata;
|
|
171
|
+
this.eventtype = eventtype;
|
|
172
|
+
this.clockid = clockid;
|
|
173
|
+
this.timeout = timeout;
|
|
174
|
+
this.flags = flags;
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
var Event = class {
|
|
178
|
+
write_bytes(view, ptr) {
|
|
179
|
+
view.setBigUint64(ptr, this.userdata, true);
|
|
180
|
+
view.setUint16(ptr + 8, this.error, true);
|
|
181
|
+
view.setUint8(ptr + 10, this.eventtype);
|
|
182
|
+
}
|
|
183
|
+
constructor(userdata, error, eventtype) {
|
|
184
|
+
this.userdata = userdata;
|
|
185
|
+
this.error = error;
|
|
186
|
+
this.eventtype = eventtype;
|
|
187
|
+
}
|
|
188
|
+
};
|
|
189
|
+
var RIFLAGS_RECV_PEEK = 1 << 0;
|
|
190
|
+
var RIFLAGS_RECV_WAITALL = 1 << 1;
|
|
191
|
+
var ROFLAGS_RECV_DATA_TRUNCATED = 1 << 0;
|
|
192
|
+
var SDFLAGS_RD = 1 << 0;
|
|
193
|
+
var SDFLAGS_WR = 1 << 1;
|
|
194
|
+
var PREOPENTYPE_DIR = 0;
|
|
195
|
+
var PrestatDir = class {
|
|
196
|
+
write_bytes(view, ptr) {
|
|
197
|
+
view.setUint32(ptr, this.pr_name.byteLength, true);
|
|
198
|
+
}
|
|
199
|
+
constructor(name) {
|
|
200
|
+
this.pr_name = new TextEncoder().encode(name);
|
|
201
|
+
}
|
|
202
|
+
};
|
|
203
|
+
var Prestat = class _Prestat {
|
|
204
|
+
static dir(name) {
|
|
205
|
+
const prestat = new _Prestat();
|
|
206
|
+
prestat.tag = PREOPENTYPE_DIR;
|
|
207
|
+
prestat.inner = new PrestatDir(name);
|
|
208
|
+
return prestat;
|
|
209
|
+
}
|
|
210
|
+
write_bytes(view, ptr) {
|
|
211
|
+
view.setUint32(ptr, this.tag, true);
|
|
212
|
+
this.inner.write_bytes(view, ptr + 4);
|
|
213
|
+
}
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
// node_modules/@bjorn3/browser_wasi_shim/dist/debug.js
|
|
217
|
+
var Debug = class Debug2 {
|
|
218
|
+
enable(enabled) {
|
|
219
|
+
this.log = createLogger(enabled === void 0 ? true : enabled, this.prefix);
|
|
220
|
+
}
|
|
221
|
+
get enabled() {
|
|
222
|
+
return this.isEnabled;
|
|
223
|
+
}
|
|
224
|
+
constructor(isEnabled) {
|
|
225
|
+
this.isEnabled = isEnabled;
|
|
226
|
+
this.prefix = "wasi:";
|
|
227
|
+
this.enable(isEnabled);
|
|
228
|
+
}
|
|
229
|
+
};
|
|
230
|
+
function createLogger(enabled, prefix) {
|
|
231
|
+
if (enabled) {
|
|
232
|
+
const a = console.log.bind(console, "%c%s", "color: #265BA0", prefix);
|
|
233
|
+
return a;
|
|
234
|
+
} else {
|
|
235
|
+
return () => {
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
var debug = new Debug(false);
|
|
240
|
+
|
|
241
|
+
// node_modules/@bjorn3/browser_wasi_shim/dist/wasi.js
|
|
242
|
+
var WASIProcExit = class extends Error {
|
|
243
|
+
constructor(code) {
|
|
244
|
+
super("exit with exit code " + code);
|
|
245
|
+
this.code = code;
|
|
246
|
+
}
|
|
247
|
+
};
|
|
248
|
+
var WASI = class WASI2 {
|
|
249
|
+
start(instance) {
|
|
250
|
+
this.inst = instance;
|
|
251
|
+
try {
|
|
252
|
+
instance.exports._start();
|
|
253
|
+
return 0;
|
|
254
|
+
} catch (e) {
|
|
255
|
+
if (e instanceof WASIProcExit) {
|
|
256
|
+
return e.code;
|
|
257
|
+
} else {
|
|
258
|
+
throw e;
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
initialize(instance) {
|
|
263
|
+
this.inst = instance;
|
|
264
|
+
if (instance.exports._initialize) {
|
|
265
|
+
instance.exports._initialize();
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
constructor(args, env, fds, options = {}) {
|
|
269
|
+
this.args = [];
|
|
270
|
+
this.env = [];
|
|
271
|
+
this.fds = [];
|
|
272
|
+
debug.enable(options.debug);
|
|
273
|
+
this.args = args;
|
|
274
|
+
this.env = env;
|
|
275
|
+
this.fds = fds;
|
|
276
|
+
const self2 = this;
|
|
277
|
+
this.wasiImport = { args_sizes_get(argc, argv_buf_size) {
|
|
278
|
+
const buffer = new DataView(self2.inst.exports.memory.buffer);
|
|
279
|
+
buffer.setUint32(argc, self2.args.length, true);
|
|
280
|
+
let buf_size = 0;
|
|
281
|
+
for (const arg of self2.args) {
|
|
282
|
+
buf_size += arg.length + 1;
|
|
283
|
+
}
|
|
284
|
+
buffer.setUint32(argv_buf_size, buf_size, true);
|
|
285
|
+
debug.log(buffer.getUint32(argc, true), buffer.getUint32(argv_buf_size, true));
|
|
286
|
+
return 0;
|
|
287
|
+
}, args_get(argv, argv_buf) {
|
|
288
|
+
const buffer = new DataView(self2.inst.exports.memory.buffer);
|
|
289
|
+
const buffer8 = new Uint8Array(self2.inst.exports.memory.buffer);
|
|
290
|
+
const orig_argv_buf = argv_buf;
|
|
291
|
+
for (let i = 0; i < self2.args.length; i++) {
|
|
292
|
+
buffer.setUint32(argv, argv_buf, true);
|
|
293
|
+
argv += 4;
|
|
294
|
+
const arg = new TextEncoder().encode(self2.args[i]);
|
|
295
|
+
buffer8.set(arg, argv_buf);
|
|
296
|
+
buffer.setUint8(argv_buf + arg.length, 0);
|
|
297
|
+
argv_buf += arg.length + 1;
|
|
298
|
+
}
|
|
299
|
+
if (debug.enabled) {
|
|
300
|
+
debug.log(new TextDecoder("utf-8").decode(buffer8.slice(orig_argv_buf, argv_buf)));
|
|
301
|
+
}
|
|
302
|
+
return 0;
|
|
303
|
+
}, environ_sizes_get(environ_count, environ_size) {
|
|
304
|
+
const buffer = new DataView(self2.inst.exports.memory.buffer);
|
|
305
|
+
buffer.setUint32(environ_count, self2.env.length, true);
|
|
306
|
+
let buf_size = 0;
|
|
307
|
+
for (const environ of self2.env) {
|
|
308
|
+
buf_size += new TextEncoder().encode(environ).length + 1;
|
|
309
|
+
}
|
|
310
|
+
buffer.setUint32(environ_size, buf_size, true);
|
|
311
|
+
debug.log(buffer.getUint32(environ_count, true), buffer.getUint32(environ_size, true));
|
|
312
|
+
return 0;
|
|
313
|
+
}, environ_get(environ, environ_buf) {
|
|
314
|
+
const buffer = new DataView(self2.inst.exports.memory.buffer);
|
|
315
|
+
const buffer8 = new Uint8Array(self2.inst.exports.memory.buffer);
|
|
316
|
+
const orig_environ_buf = environ_buf;
|
|
317
|
+
for (let i = 0; i < self2.env.length; i++) {
|
|
318
|
+
buffer.setUint32(environ, environ_buf, true);
|
|
319
|
+
environ += 4;
|
|
320
|
+
const e = new TextEncoder().encode(self2.env[i]);
|
|
321
|
+
buffer8.set(e, environ_buf);
|
|
322
|
+
buffer.setUint8(environ_buf + e.length, 0);
|
|
323
|
+
environ_buf += e.length + 1;
|
|
324
|
+
}
|
|
325
|
+
if (debug.enabled) {
|
|
326
|
+
debug.log(new TextDecoder("utf-8").decode(buffer8.slice(orig_environ_buf, environ_buf)));
|
|
327
|
+
}
|
|
328
|
+
return 0;
|
|
329
|
+
}, clock_res_get(id, res_ptr) {
|
|
330
|
+
let resolutionValue;
|
|
331
|
+
switch (id) {
|
|
332
|
+
case CLOCKID_MONOTONIC: {
|
|
333
|
+
resolutionValue = 5000n;
|
|
334
|
+
break;
|
|
335
|
+
}
|
|
336
|
+
case CLOCKID_REALTIME: {
|
|
337
|
+
resolutionValue = 1000000n;
|
|
338
|
+
break;
|
|
339
|
+
}
|
|
340
|
+
default:
|
|
341
|
+
return ERRNO_NOSYS;
|
|
342
|
+
}
|
|
343
|
+
const view = new DataView(self2.inst.exports.memory.buffer);
|
|
344
|
+
view.setBigUint64(res_ptr, resolutionValue, true);
|
|
345
|
+
return ERRNO_SUCCESS;
|
|
346
|
+
}, clock_time_get(id, precision, time) {
|
|
347
|
+
const buffer = new DataView(self2.inst.exports.memory.buffer);
|
|
348
|
+
if (id === CLOCKID_REALTIME) {
|
|
349
|
+
buffer.setBigUint64(time, BigInt((/* @__PURE__ */ new Date()).getTime()) * 1000000n, true);
|
|
350
|
+
} else if (id == CLOCKID_MONOTONIC) {
|
|
351
|
+
let monotonic_time;
|
|
352
|
+
try {
|
|
353
|
+
monotonic_time = BigInt(Math.round(performance.now() * 1e6));
|
|
354
|
+
} catch (e) {
|
|
355
|
+
monotonic_time = 0n;
|
|
356
|
+
}
|
|
357
|
+
buffer.setBigUint64(time, monotonic_time, true);
|
|
358
|
+
} else {
|
|
359
|
+
buffer.setBigUint64(time, 0n, true);
|
|
360
|
+
}
|
|
361
|
+
return 0;
|
|
362
|
+
}, fd_advise(fd, offset, len, advice) {
|
|
363
|
+
if (self2.fds[fd] != void 0) {
|
|
364
|
+
return ERRNO_SUCCESS;
|
|
365
|
+
} else {
|
|
366
|
+
return ERRNO_BADF;
|
|
367
|
+
}
|
|
368
|
+
}, fd_allocate(fd, offset, len) {
|
|
369
|
+
if (self2.fds[fd] != void 0) {
|
|
370
|
+
return self2.fds[fd].fd_allocate(offset, len);
|
|
371
|
+
} else {
|
|
372
|
+
return ERRNO_BADF;
|
|
373
|
+
}
|
|
374
|
+
}, fd_close(fd) {
|
|
375
|
+
if (self2.fds[fd] != void 0) {
|
|
376
|
+
const ret = self2.fds[fd].fd_close();
|
|
377
|
+
self2.fds[fd] = void 0;
|
|
378
|
+
return ret;
|
|
379
|
+
} else {
|
|
380
|
+
return ERRNO_BADF;
|
|
381
|
+
}
|
|
382
|
+
}, fd_datasync(fd) {
|
|
383
|
+
if (self2.fds[fd] != void 0) {
|
|
384
|
+
return self2.fds[fd].fd_sync();
|
|
385
|
+
} else {
|
|
386
|
+
return ERRNO_BADF;
|
|
387
|
+
}
|
|
388
|
+
}, fd_fdstat_get(fd, fdstat_ptr) {
|
|
389
|
+
if (self2.fds[fd] != void 0) {
|
|
390
|
+
const { ret, fdstat } = self2.fds[fd].fd_fdstat_get();
|
|
391
|
+
if (fdstat != null) {
|
|
392
|
+
fdstat.write_bytes(new DataView(self2.inst.exports.memory.buffer), fdstat_ptr);
|
|
393
|
+
}
|
|
394
|
+
return ret;
|
|
395
|
+
} else {
|
|
396
|
+
return ERRNO_BADF;
|
|
397
|
+
}
|
|
398
|
+
}, fd_fdstat_set_flags(fd, flags) {
|
|
399
|
+
if (self2.fds[fd] != void 0) {
|
|
400
|
+
return self2.fds[fd].fd_fdstat_set_flags(flags);
|
|
401
|
+
} else {
|
|
402
|
+
return ERRNO_BADF;
|
|
403
|
+
}
|
|
404
|
+
}, fd_fdstat_set_rights(fd, fs_rights_base, fs_rights_inheriting) {
|
|
405
|
+
if (self2.fds[fd] != void 0) {
|
|
406
|
+
return self2.fds[fd].fd_fdstat_set_rights(fs_rights_base, fs_rights_inheriting);
|
|
407
|
+
} else {
|
|
408
|
+
return ERRNO_BADF;
|
|
409
|
+
}
|
|
410
|
+
}, fd_filestat_get(fd, filestat_ptr) {
|
|
411
|
+
if (self2.fds[fd] != void 0) {
|
|
412
|
+
const { ret, filestat } = self2.fds[fd].fd_filestat_get();
|
|
413
|
+
if (filestat != null) {
|
|
414
|
+
filestat.write_bytes(new DataView(self2.inst.exports.memory.buffer), filestat_ptr);
|
|
415
|
+
}
|
|
416
|
+
return ret;
|
|
417
|
+
} else {
|
|
418
|
+
return ERRNO_BADF;
|
|
419
|
+
}
|
|
420
|
+
}, fd_filestat_set_size(fd, size) {
|
|
421
|
+
if (self2.fds[fd] != void 0) {
|
|
422
|
+
return self2.fds[fd].fd_filestat_set_size(size);
|
|
423
|
+
} else {
|
|
424
|
+
return ERRNO_BADF;
|
|
425
|
+
}
|
|
426
|
+
}, fd_filestat_set_times(fd, atim, mtim, fst_flags) {
|
|
427
|
+
if (self2.fds[fd] != void 0) {
|
|
428
|
+
return self2.fds[fd].fd_filestat_set_times(atim, mtim, fst_flags);
|
|
429
|
+
} else {
|
|
430
|
+
return ERRNO_BADF;
|
|
431
|
+
}
|
|
432
|
+
}, fd_pread(fd, iovs_ptr, iovs_len, offset, nread_ptr) {
|
|
433
|
+
const buffer = new DataView(self2.inst.exports.memory.buffer);
|
|
434
|
+
const buffer8 = new Uint8Array(self2.inst.exports.memory.buffer);
|
|
435
|
+
if (self2.fds[fd] != void 0) {
|
|
436
|
+
const iovecs = Iovec.read_bytes_array(buffer, iovs_ptr, iovs_len);
|
|
437
|
+
let nread = 0;
|
|
438
|
+
for (const iovec of iovecs) {
|
|
439
|
+
const { ret, data } = self2.fds[fd].fd_pread(iovec.buf_len, offset);
|
|
440
|
+
if (ret != ERRNO_SUCCESS) {
|
|
441
|
+
buffer.setUint32(nread_ptr, nread, true);
|
|
442
|
+
return ret;
|
|
443
|
+
}
|
|
444
|
+
buffer8.set(data, iovec.buf);
|
|
445
|
+
nread += data.length;
|
|
446
|
+
offset += BigInt(data.length);
|
|
447
|
+
if (data.length != iovec.buf_len) {
|
|
448
|
+
break;
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
buffer.setUint32(nread_ptr, nread, true);
|
|
452
|
+
return ERRNO_SUCCESS;
|
|
453
|
+
} else {
|
|
454
|
+
return ERRNO_BADF;
|
|
455
|
+
}
|
|
456
|
+
}, fd_prestat_get(fd, buf_ptr) {
|
|
457
|
+
const buffer = new DataView(self2.inst.exports.memory.buffer);
|
|
458
|
+
if (self2.fds[fd] != void 0) {
|
|
459
|
+
const { ret, prestat } = self2.fds[fd].fd_prestat_get();
|
|
460
|
+
if (prestat != null) {
|
|
461
|
+
prestat.write_bytes(buffer, buf_ptr);
|
|
462
|
+
}
|
|
463
|
+
return ret;
|
|
464
|
+
} else {
|
|
465
|
+
return ERRNO_BADF;
|
|
466
|
+
}
|
|
467
|
+
}, fd_prestat_dir_name(fd, path_ptr, path_len) {
|
|
468
|
+
if (self2.fds[fd] != void 0) {
|
|
469
|
+
const { ret, prestat } = self2.fds[fd].fd_prestat_get();
|
|
470
|
+
if (prestat == null) {
|
|
471
|
+
return ret;
|
|
472
|
+
}
|
|
473
|
+
const prestat_dir_name = prestat.inner.pr_name;
|
|
474
|
+
const buffer8 = new Uint8Array(self2.inst.exports.memory.buffer);
|
|
475
|
+
buffer8.set(prestat_dir_name.slice(0, path_len), path_ptr);
|
|
476
|
+
return prestat_dir_name.byteLength > path_len ? ERRNO_NAMETOOLONG : ERRNO_SUCCESS;
|
|
477
|
+
} else {
|
|
478
|
+
return ERRNO_BADF;
|
|
479
|
+
}
|
|
480
|
+
}, fd_pwrite(fd, iovs_ptr, iovs_len, offset, nwritten_ptr) {
|
|
481
|
+
const buffer = new DataView(self2.inst.exports.memory.buffer);
|
|
482
|
+
const buffer8 = new Uint8Array(self2.inst.exports.memory.buffer);
|
|
483
|
+
if (self2.fds[fd] != void 0) {
|
|
484
|
+
const iovecs = Ciovec.read_bytes_array(buffer, iovs_ptr, iovs_len);
|
|
485
|
+
let nwritten = 0;
|
|
486
|
+
for (const iovec of iovecs) {
|
|
487
|
+
const data = buffer8.slice(iovec.buf, iovec.buf + iovec.buf_len);
|
|
488
|
+
const { ret, nwritten: nwritten_part } = self2.fds[fd].fd_pwrite(data, offset);
|
|
489
|
+
if (ret != ERRNO_SUCCESS) {
|
|
490
|
+
buffer.setUint32(nwritten_ptr, nwritten, true);
|
|
491
|
+
return ret;
|
|
492
|
+
}
|
|
493
|
+
nwritten += nwritten_part;
|
|
494
|
+
offset += BigInt(nwritten_part);
|
|
495
|
+
if (nwritten_part != data.byteLength) {
|
|
496
|
+
break;
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
buffer.setUint32(nwritten_ptr, nwritten, true);
|
|
500
|
+
return ERRNO_SUCCESS;
|
|
501
|
+
} else {
|
|
502
|
+
return ERRNO_BADF;
|
|
503
|
+
}
|
|
504
|
+
}, fd_read(fd, iovs_ptr, iovs_len, nread_ptr) {
|
|
505
|
+
const buffer = new DataView(self2.inst.exports.memory.buffer);
|
|
506
|
+
const buffer8 = new Uint8Array(self2.inst.exports.memory.buffer);
|
|
507
|
+
if (self2.fds[fd] != void 0) {
|
|
508
|
+
const iovecs = Iovec.read_bytes_array(buffer, iovs_ptr, iovs_len);
|
|
509
|
+
let nread = 0;
|
|
510
|
+
for (const iovec of iovecs) {
|
|
511
|
+
const { ret, data } = self2.fds[fd].fd_read(iovec.buf_len);
|
|
512
|
+
if (ret != ERRNO_SUCCESS) {
|
|
513
|
+
buffer.setUint32(nread_ptr, nread, true);
|
|
514
|
+
return ret;
|
|
515
|
+
}
|
|
516
|
+
buffer8.set(data, iovec.buf);
|
|
517
|
+
nread += data.length;
|
|
518
|
+
if (data.length != iovec.buf_len) {
|
|
519
|
+
break;
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
buffer.setUint32(nread_ptr, nread, true);
|
|
523
|
+
return ERRNO_SUCCESS;
|
|
524
|
+
} else {
|
|
525
|
+
return ERRNO_BADF;
|
|
526
|
+
}
|
|
527
|
+
}, fd_readdir(fd, buf, buf_len, cookie, bufused_ptr) {
|
|
528
|
+
const buffer = new DataView(self2.inst.exports.memory.buffer);
|
|
529
|
+
const buffer8 = new Uint8Array(self2.inst.exports.memory.buffer);
|
|
530
|
+
if (self2.fds[fd] != void 0) {
|
|
531
|
+
let bufused = 0;
|
|
532
|
+
while (true) {
|
|
533
|
+
const { ret, dirent } = self2.fds[fd].fd_readdir_single(cookie);
|
|
534
|
+
if (ret != 0) {
|
|
535
|
+
buffer.setUint32(bufused_ptr, bufused, true);
|
|
536
|
+
return ret;
|
|
537
|
+
}
|
|
538
|
+
if (dirent == null) {
|
|
539
|
+
break;
|
|
540
|
+
}
|
|
541
|
+
if (buf_len - bufused < dirent.head_length()) {
|
|
542
|
+
bufused = buf_len;
|
|
543
|
+
break;
|
|
544
|
+
}
|
|
545
|
+
const head_bytes = new ArrayBuffer(dirent.head_length());
|
|
546
|
+
dirent.write_head_bytes(new DataView(head_bytes), 0);
|
|
547
|
+
buffer8.set(new Uint8Array(head_bytes).slice(0, Math.min(head_bytes.byteLength, buf_len - bufused)), buf);
|
|
548
|
+
buf += dirent.head_length();
|
|
549
|
+
bufused += dirent.head_length();
|
|
550
|
+
if (buf_len - bufused < dirent.name_length()) {
|
|
551
|
+
bufused = buf_len;
|
|
552
|
+
break;
|
|
553
|
+
}
|
|
554
|
+
dirent.write_name_bytes(buffer8, buf, buf_len - bufused);
|
|
555
|
+
buf += dirent.name_length();
|
|
556
|
+
bufused += dirent.name_length();
|
|
557
|
+
cookie = dirent.d_next;
|
|
558
|
+
}
|
|
559
|
+
buffer.setUint32(bufused_ptr, bufused, true);
|
|
560
|
+
return 0;
|
|
561
|
+
} else {
|
|
562
|
+
return ERRNO_BADF;
|
|
563
|
+
}
|
|
564
|
+
}, fd_renumber(fd, to) {
|
|
565
|
+
if (self2.fds[fd] != void 0 && self2.fds[to] != void 0) {
|
|
566
|
+
const ret = self2.fds[to].fd_close();
|
|
567
|
+
if (ret != 0) {
|
|
568
|
+
return ret;
|
|
569
|
+
}
|
|
570
|
+
self2.fds[to] = self2.fds[fd];
|
|
571
|
+
self2.fds[fd] = void 0;
|
|
572
|
+
return 0;
|
|
573
|
+
} else {
|
|
574
|
+
return ERRNO_BADF;
|
|
575
|
+
}
|
|
576
|
+
}, fd_seek(fd, offset, whence, offset_out_ptr) {
|
|
577
|
+
const buffer = new DataView(self2.inst.exports.memory.buffer);
|
|
578
|
+
if (self2.fds[fd] != void 0) {
|
|
579
|
+
const { ret, offset: offset_out } = self2.fds[fd].fd_seek(offset, whence);
|
|
580
|
+
buffer.setBigInt64(offset_out_ptr, offset_out, true);
|
|
581
|
+
return ret;
|
|
582
|
+
} else {
|
|
583
|
+
return ERRNO_BADF;
|
|
584
|
+
}
|
|
585
|
+
}, fd_sync(fd) {
|
|
586
|
+
if (self2.fds[fd] != void 0) {
|
|
587
|
+
return self2.fds[fd].fd_sync();
|
|
588
|
+
} else {
|
|
589
|
+
return ERRNO_BADF;
|
|
590
|
+
}
|
|
591
|
+
}, fd_tell(fd, offset_ptr) {
|
|
592
|
+
const buffer = new DataView(self2.inst.exports.memory.buffer);
|
|
593
|
+
if (self2.fds[fd] != void 0) {
|
|
594
|
+
const { ret, offset } = self2.fds[fd].fd_tell();
|
|
595
|
+
buffer.setBigUint64(offset_ptr, offset, true);
|
|
596
|
+
return ret;
|
|
597
|
+
} else {
|
|
598
|
+
return ERRNO_BADF;
|
|
599
|
+
}
|
|
600
|
+
}, fd_write(fd, iovs_ptr, iovs_len, nwritten_ptr) {
|
|
601
|
+
const buffer = new DataView(self2.inst.exports.memory.buffer);
|
|
602
|
+
const buffer8 = new Uint8Array(self2.inst.exports.memory.buffer);
|
|
603
|
+
if (self2.fds[fd] != void 0) {
|
|
604
|
+
const iovecs = Ciovec.read_bytes_array(buffer, iovs_ptr, iovs_len);
|
|
605
|
+
let nwritten = 0;
|
|
606
|
+
for (const iovec of iovecs) {
|
|
607
|
+
const data = buffer8.slice(iovec.buf, iovec.buf + iovec.buf_len);
|
|
608
|
+
const { ret, nwritten: nwritten_part } = self2.fds[fd].fd_write(data);
|
|
609
|
+
if (ret != ERRNO_SUCCESS) {
|
|
610
|
+
buffer.setUint32(nwritten_ptr, nwritten, true);
|
|
611
|
+
return ret;
|
|
612
|
+
}
|
|
613
|
+
nwritten += nwritten_part;
|
|
614
|
+
if (nwritten_part != data.byteLength) {
|
|
615
|
+
break;
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
buffer.setUint32(nwritten_ptr, nwritten, true);
|
|
619
|
+
return ERRNO_SUCCESS;
|
|
620
|
+
} else {
|
|
621
|
+
return ERRNO_BADF;
|
|
622
|
+
}
|
|
623
|
+
}, path_create_directory(fd, path_ptr, path_len) {
|
|
624
|
+
const buffer8 = new Uint8Array(self2.inst.exports.memory.buffer);
|
|
625
|
+
if (self2.fds[fd] != void 0) {
|
|
626
|
+
const path = new TextDecoder("utf-8").decode(buffer8.slice(path_ptr, path_ptr + path_len));
|
|
627
|
+
return self2.fds[fd].path_create_directory(path);
|
|
628
|
+
} else {
|
|
629
|
+
return ERRNO_BADF;
|
|
630
|
+
}
|
|
631
|
+
}, path_filestat_get(fd, flags, path_ptr, path_len, filestat_ptr) {
|
|
632
|
+
const buffer = new DataView(self2.inst.exports.memory.buffer);
|
|
633
|
+
const buffer8 = new Uint8Array(self2.inst.exports.memory.buffer);
|
|
634
|
+
if (self2.fds[fd] != void 0) {
|
|
635
|
+
const path = new TextDecoder("utf-8").decode(buffer8.slice(path_ptr, path_ptr + path_len));
|
|
636
|
+
const { ret, filestat } = self2.fds[fd].path_filestat_get(flags, path);
|
|
637
|
+
if (filestat != null) {
|
|
638
|
+
filestat.write_bytes(buffer, filestat_ptr);
|
|
639
|
+
}
|
|
640
|
+
return ret;
|
|
641
|
+
} else {
|
|
642
|
+
return ERRNO_BADF;
|
|
643
|
+
}
|
|
644
|
+
}, path_filestat_set_times(fd, flags, path_ptr, path_len, atim, mtim, fst_flags) {
|
|
645
|
+
const buffer8 = new Uint8Array(self2.inst.exports.memory.buffer);
|
|
646
|
+
if (self2.fds[fd] != void 0) {
|
|
647
|
+
const path = new TextDecoder("utf-8").decode(buffer8.slice(path_ptr, path_ptr + path_len));
|
|
648
|
+
return self2.fds[fd].path_filestat_set_times(flags, path, atim, mtim, fst_flags);
|
|
649
|
+
} else {
|
|
650
|
+
return ERRNO_BADF;
|
|
651
|
+
}
|
|
652
|
+
}, path_link(old_fd, old_flags, old_path_ptr, old_path_len, new_fd, new_path_ptr, new_path_len) {
|
|
653
|
+
const buffer8 = new Uint8Array(self2.inst.exports.memory.buffer);
|
|
654
|
+
if (self2.fds[old_fd] != void 0 && self2.fds[new_fd] != void 0) {
|
|
655
|
+
const old_path = new TextDecoder("utf-8").decode(buffer8.slice(old_path_ptr, old_path_ptr + old_path_len));
|
|
656
|
+
const new_path = new TextDecoder("utf-8").decode(buffer8.slice(new_path_ptr, new_path_ptr + new_path_len));
|
|
657
|
+
const { ret, inode_obj } = self2.fds[old_fd].path_lookup(old_path, old_flags);
|
|
658
|
+
if (inode_obj == null) {
|
|
659
|
+
return ret;
|
|
660
|
+
}
|
|
661
|
+
return self2.fds[new_fd].path_link(new_path, inode_obj, false);
|
|
662
|
+
} else {
|
|
663
|
+
return ERRNO_BADF;
|
|
664
|
+
}
|
|
665
|
+
}, path_open(fd, dirflags, path_ptr, path_len, oflags, fs_rights_base, fs_rights_inheriting, fd_flags, opened_fd_ptr) {
|
|
666
|
+
const buffer = new DataView(self2.inst.exports.memory.buffer);
|
|
667
|
+
const buffer8 = new Uint8Array(self2.inst.exports.memory.buffer);
|
|
668
|
+
if (self2.fds[fd] != void 0) {
|
|
669
|
+
const path = new TextDecoder("utf-8").decode(buffer8.slice(path_ptr, path_ptr + path_len));
|
|
670
|
+
debug.log(path);
|
|
671
|
+
const { ret, fd_obj } = self2.fds[fd].path_open(dirflags, path, oflags, fs_rights_base, fs_rights_inheriting, fd_flags);
|
|
672
|
+
if (ret != 0) {
|
|
673
|
+
return ret;
|
|
674
|
+
}
|
|
675
|
+
self2.fds.push(fd_obj);
|
|
676
|
+
const opened_fd = self2.fds.length - 1;
|
|
677
|
+
buffer.setUint32(opened_fd_ptr, opened_fd, true);
|
|
678
|
+
return 0;
|
|
679
|
+
} else {
|
|
680
|
+
return ERRNO_BADF;
|
|
681
|
+
}
|
|
682
|
+
}, path_readlink(fd, path_ptr, path_len, buf_ptr, buf_len, nread_ptr) {
|
|
683
|
+
const buffer = new DataView(self2.inst.exports.memory.buffer);
|
|
684
|
+
const buffer8 = new Uint8Array(self2.inst.exports.memory.buffer);
|
|
685
|
+
if (self2.fds[fd] != void 0) {
|
|
686
|
+
const path = new TextDecoder("utf-8").decode(buffer8.slice(path_ptr, path_ptr + path_len));
|
|
687
|
+
debug.log(path);
|
|
688
|
+
const { ret, data } = self2.fds[fd].path_readlink(path);
|
|
689
|
+
if (data != null) {
|
|
690
|
+
const data_buf = new TextEncoder().encode(data);
|
|
691
|
+
if (data_buf.length > buf_len) {
|
|
692
|
+
buffer.setUint32(nread_ptr, 0, true);
|
|
693
|
+
return ERRNO_BADF;
|
|
694
|
+
}
|
|
695
|
+
buffer8.set(data_buf, buf_ptr);
|
|
696
|
+
buffer.setUint32(nread_ptr, data_buf.length, true);
|
|
697
|
+
}
|
|
698
|
+
return ret;
|
|
699
|
+
} else {
|
|
700
|
+
return ERRNO_BADF;
|
|
701
|
+
}
|
|
702
|
+
}, path_remove_directory(fd, path_ptr, path_len) {
|
|
703
|
+
const buffer8 = new Uint8Array(self2.inst.exports.memory.buffer);
|
|
704
|
+
if (self2.fds[fd] != void 0) {
|
|
705
|
+
const path = new TextDecoder("utf-8").decode(buffer8.slice(path_ptr, path_ptr + path_len));
|
|
706
|
+
return self2.fds[fd].path_remove_directory(path);
|
|
707
|
+
} else {
|
|
708
|
+
return ERRNO_BADF;
|
|
709
|
+
}
|
|
710
|
+
}, path_rename(fd, old_path_ptr, old_path_len, new_fd, new_path_ptr, new_path_len) {
|
|
711
|
+
const buffer8 = new Uint8Array(self2.inst.exports.memory.buffer);
|
|
712
|
+
if (self2.fds[fd] != void 0 && self2.fds[new_fd] != void 0) {
|
|
713
|
+
const old_path = new TextDecoder("utf-8").decode(buffer8.slice(old_path_ptr, old_path_ptr + old_path_len));
|
|
714
|
+
const new_path = new TextDecoder("utf-8").decode(buffer8.slice(new_path_ptr, new_path_ptr + new_path_len));
|
|
715
|
+
let { ret, inode_obj } = self2.fds[fd].path_unlink(old_path);
|
|
716
|
+
if (inode_obj == null) {
|
|
717
|
+
return ret;
|
|
718
|
+
}
|
|
719
|
+
ret = self2.fds[new_fd].path_link(new_path, inode_obj, true);
|
|
720
|
+
if (ret != ERRNO_SUCCESS) {
|
|
721
|
+
if (self2.fds[fd].path_link(old_path, inode_obj, true) != ERRNO_SUCCESS) {
|
|
722
|
+
throw "path_link should always return success when relinking an inode back to the original place";
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
return ret;
|
|
726
|
+
} else {
|
|
727
|
+
return ERRNO_BADF;
|
|
728
|
+
}
|
|
729
|
+
}, path_symlink(old_path_ptr, old_path_len, fd, new_path_ptr, new_path_len) {
|
|
730
|
+
const buffer8 = new Uint8Array(self2.inst.exports.memory.buffer);
|
|
731
|
+
if (self2.fds[fd] != void 0) {
|
|
732
|
+
const old_path = new TextDecoder("utf-8").decode(buffer8.slice(old_path_ptr, old_path_ptr + old_path_len));
|
|
733
|
+
const new_path = new TextDecoder("utf-8").decode(buffer8.slice(new_path_ptr, new_path_ptr + new_path_len));
|
|
734
|
+
return ERRNO_NOTSUP;
|
|
735
|
+
} else {
|
|
736
|
+
return ERRNO_BADF;
|
|
737
|
+
}
|
|
738
|
+
}, path_unlink_file(fd, path_ptr, path_len) {
|
|
739
|
+
const buffer8 = new Uint8Array(self2.inst.exports.memory.buffer);
|
|
740
|
+
if (self2.fds[fd] != void 0) {
|
|
741
|
+
const path = new TextDecoder("utf-8").decode(buffer8.slice(path_ptr, path_ptr + path_len));
|
|
742
|
+
return self2.fds[fd].path_unlink_file(path);
|
|
743
|
+
} else {
|
|
744
|
+
return ERRNO_BADF;
|
|
745
|
+
}
|
|
746
|
+
}, poll_oneoff(in_ptr, out_ptr, nsubscriptions) {
|
|
747
|
+
if (nsubscriptions === 0) {
|
|
748
|
+
return ERRNO_INVAL;
|
|
749
|
+
}
|
|
750
|
+
if (nsubscriptions > 1) {
|
|
751
|
+
debug.log("poll_oneoff: only a single subscription is supported");
|
|
752
|
+
return ERRNO_NOTSUP;
|
|
753
|
+
}
|
|
754
|
+
const buffer = new DataView(self2.inst.exports.memory.buffer);
|
|
755
|
+
const s = Subscription.read_bytes(buffer, in_ptr);
|
|
756
|
+
const eventtype = s.eventtype;
|
|
757
|
+
const clockid = s.clockid;
|
|
758
|
+
const timeout = s.timeout;
|
|
759
|
+
if (eventtype !== EVENTTYPE_CLOCK) {
|
|
760
|
+
debug.log("poll_oneoff: only clock subscriptions are supported");
|
|
761
|
+
return ERRNO_NOTSUP;
|
|
762
|
+
}
|
|
763
|
+
let getNow = void 0;
|
|
764
|
+
if (clockid === CLOCKID_MONOTONIC) {
|
|
765
|
+
getNow = () => BigInt(Math.round(performance.now() * 1e6));
|
|
766
|
+
} else if (clockid === CLOCKID_REALTIME) {
|
|
767
|
+
getNow = () => BigInt((/* @__PURE__ */ new Date()).getTime()) * 1000000n;
|
|
768
|
+
} else {
|
|
769
|
+
return ERRNO_INVAL;
|
|
770
|
+
}
|
|
771
|
+
const endTime = (s.flags & SUBCLOCKFLAGS_SUBSCRIPTION_CLOCK_ABSTIME) !== 0 ? timeout : getNow() + timeout;
|
|
772
|
+
while (endTime > getNow()) {
|
|
773
|
+
}
|
|
774
|
+
const event = new Event(s.userdata, ERRNO_SUCCESS, eventtype);
|
|
775
|
+
event.write_bytes(buffer, out_ptr);
|
|
776
|
+
return ERRNO_SUCCESS;
|
|
777
|
+
}, proc_exit(exit_code) {
|
|
778
|
+
throw new WASIProcExit(exit_code);
|
|
779
|
+
}, proc_raise(sig) {
|
|
780
|
+
throw "raised signal " + sig;
|
|
781
|
+
}, sched_yield() {
|
|
782
|
+
}, random_get(buf, buf_len) {
|
|
783
|
+
const buffer8 = new Uint8Array(self2.inst.exports.memory.buffer).subarray(buf, buf + buf_len);
|
|
784
|
+
if ("crypto" in globalThis && (typeof SharedArrayBuffer === "undefined" || !(self2.inst.exports.memory.buffer instanceof SharedArrayBuffer))) {
|
|
785
|
+
for (let i = 0; i < buf_len; i += 65536) {
|
|
786
|
+
crypto.getRandomValues(buffer8.subarray(i, i + 65536));
|
|
787
|
+
}
|
|
788
|
+
} else {
|
|
789
|
+
for (let i = 0; i < buf_len; i++) {
|
|
790
|
+
buffer8[i] = Math.random() * 256 | 0;
|
|
791
|
+
}
|
|
792
|
+
}
|
|
793
|
+
}, sock_recv(fd, ri_data, ri_flags) {
|
|
794
|
+
throw "sockets not supported";
|
|
795
|
+
}, sock_send(fd, si_data, si_flags) {
|
|
796
|
+
throw "sockets not supported";
|
|
797
|
+
}, sock_shutdown(fd, how) {
|
|
798
|
+
throw "sockets not supported";
|
|
799
|
+
}, sock_accept(fd, flags) {
|
|
800
|
+
throw "sockets not supported";
|
|
801
|
+
} };
|
|
802
|
+
}
|
|
803
|
+
};
|
|
804
|
+
|
|
805
|
+
// node_modules/@bjorn3/browser_wasi_shim/dist/fd.js
|
|
806
|
+
var Fd = class {
|
|
807
|
+
fd_allocate(offset, len) {
|
|
808
|
+
return ERRNO_NOTSUP;
|
|
809
|
+
}
|
|
810
|
+
fd_close() {
|
|
811
|
+
return 0;
|
|
812
|
+
}
|
|
813
|
+
fd_fdstat_get() {
|
|
814
|
+
return { ret: ERRNO_NOTSUP, fdstat: null };
|
|
815
|
+
}
|
|
816
|
+
fd_fdstat_set_flags(flags) {
|
|
817
|
+
return ERRNO_NOTSUP;
|
|
818
|
+
}
|
|
819
|
+
fd_fdstat_set_rights(fs_rights_base, fs_rights_inheriting) {
|
|
820
|
+
return ERRNO_NOTSUP;
|
|
821
|
+
}
|
|
822
|
+
fd_filestat_get() {
|
|
823
|
+
return { ret: ERRNO_NOTSUP, filestat: null };
|
|
824
|
+
}
|
|
825
|
+
fd_filestat_set_size(size) {
|
|
826
|
+
return ERRNO_NOTSUP;
|
|
827
|
+
}
|
|
828
|
+
fd_filestat_set_times(atim, mtim, fst_flags) {
|
|
829
|
+
return ERRNO_NOTSUP;
|
|
830
|
+
}
|
|
831
|
+
fd_pread(size, offset) {
|
|
832
|
+
return { ret: ERRNO_NOTSUP, data: new Uint8Array() };
|
|
833
|
+
}
|
|
834
|
+
fd_prestat_get() {
|
|
835
|
+
return { ret: ERRNO_NOTSUP, prestat: null };
|
|
836
|
+
}
|
|
837
|
+
fd_pwrite(data, offset) {
|
|
838
|
+
return { ret: ERRNO_NOTSUP, nwritten: 0 };
|
|
839
|
+
}
|
|
840
|
+
fd_read(size) {
|
|
841
|
+
return { ret: ERRNO_NOTSUP, data: new Uint8Array() };
|
|
842
|
+
}
|
|
843
|
+
fd_readdir_single(cookie) {
|
|
844
|
+
return { ret: ERRNO_NOTSUP, dirent: null };
|
|
845
|
+
}
|
|
846
|
+
fd_seek(offset, whence) {
|
|
847
|
+
return { ret: ERRNO_NOTSUP, offset: 0n };
|
|
848
|
+
}
|
|
849
|
+
fd_sync() {
|
|
850
|
+
return 0;
|
|
851
|
+
}
|
|
852
|
+
fd_tell() {
|
|
853
|
+
return { ret: ERRNO_NOTSUP, offset: 0n };
|
|
854
|
+
}
|
|
855
|
+
fd_write(data) {
|
|
856
|
+
return { ret: ERRNO_NOTSUP, nwritten: 0 };
|
|
857
|
+
}
|
|
858
|
+
path_create_directory(path) {
|
|
859
|
+
return ERRNO_NOTSUP;
|
|
860
|
+
}
|
|
861
|
+
path_filestat_get(flags, path) {
|
|
862
|
+
return { ret: ERRNO_NOTSUP, filestat: null };
|
|
863
|
+
}
|
|
864
|
+
path_filestat_set_times(flags, path, atim, mtim, fst_flags) {
|
|
865
|
+
return ERRNO_NOTSUP;
|
|
866
|
+
}
|
|
867
|
+
path_link(path, inode, allow_dir) {
|
|
868
|
+
return ERRNO_NOTSUP;
|
|
869
|
+
}
|
|
870
|
+
path_unlink(path) {
|
|
871
|
+
return { ret: ERRNO_NOTSUP, inode_obj: null };
|
|
872
|
+
}
|
|
873
|
+
path_lookup(path, dirflags) {
|
|
874
|
+
return { ret: ERRNO_NOTSUP, inode_obj: null };
|
|
875
|
+
}
|
|
876
|
+
path_open(dirflags, path, oflags, fs_rights_base, fs_rights_inheriting, fd_flags) {
|
|
877
|
+
return { ret: ERRNO_NOTDIR, fd_obj: null };
|
|
878
|
+
}
|
|
879
|
+
path_readlink(path) {
|
|
880
|
+
return { ret: ERRNO_NOTSUP, data: null };
|
|
881
|
+
}
|
|
882
|
+
path_remove_directory(path) {
|
|
883
|
+
return ERRNO_NOTSUP;
|
|
884
|
+
}
|
|
885
|
+
path_rename(old_path, new_fd, new_path) {
|
|
886
|
+
return ERRNO_NOTSUP;
|
|
887
|
+
}
|
|
888
|
+
path_unlink_file(path) {
|
|
889
|
+
return ERRNO_NOTSUP;
|
|
890
|
+
}
|
|
891
|
+
};
|
|
892
|
+
var Inode = class _Inode {
|
|
893
|
+
static issue_ino() {
|
|
894
|
+
return _Inode.next_ino++;
|
|
895
|
+
}
|
|
896
|
+
static root_ino() {
|
|
897
|
+
return 0n;
|
|
898
|
+
}
|
|
899
|
+
constructor() {
|
|
900
|
+
this.ino = _Inode.issue_ino();
|
|
901
|
+
}
|
|
902
|
+
};
|
|
903
|
+
Inode.next_ino = 1n;
|
|
904
|
+
|
|
905
|
+
// node_modules/@bjorn3/browser_wasi_shim/dist/fs_mem.js
|
|
906
|
+
var OpenFile = class extends Fd {
|
|
907
|
+
fd_allocate(offset, len) {
|
|
908
|
+
if (this.file.size > offset + len) {
|
|
909
|
+
} else {
|
|
910
|
+
const new_data = new Uint8Array(Number(offset + len));
|
|
911
|
+
new_data.set(this.file.data, 0);
|
|
912
|
+
this.file.data = new_data;
|
|
913
|
+
}
|
|
914
|
+
return ERRNO_SUCCESS;
|
|
915
|
+
}
|
|
916
|
+
fd_fdstat_get() {
|
|
917
|
+
return { ret: 0, fdstat: new Fdstat(FILETYPE_REGULAR_FILE, 0) };
|
|
918
|
+
}
|
|
919
|
+
fd_filestat_set_size(size) {
|
|
920
|
+
if (this.file.size > size) {
|
|
921
|
+
this.file.data = new Uint8Array(this.file.data.buffer.slice(0, Number(size)));
|
|
922
|
+
} else {
|
|
923
|
+
const new_data = new Uint8Array(Number(size));
|
|
924
|
+
new_data.set(this.file.data, 0);
|
|
925
|
+
this.file.data = new_data;
|
|
926
|
+
}
|
|
927
|
+
return ERRNO_SUCCESS;
|
|
928
|
+
}
|
|
929
|
+
fd_read(size) {
|
|
930
|
+
const slice = this.file.data.slice(Number(this.file_pos), Number(this.file_pos + BigInt(size)));
|
|
931
|
+
this.file_pos += BigInt(slice.length);
|
|
932
|
+
return { ret: 0, data: slice };
|
|
933
|
+
}
|
|
934
|
+
fd_pread(size, offset) {
|
|
935
|
+
const slice = this.file.data.slice(Number(offset), Number(offset + BigInt(size)));
|
|
936
|
+
return { ret: 0, data: slice };
|
|
937
|
+
}
|
|
938
|
+
fd_seek(offset, whence) {
|
|
939
|
+
let calculated_offset;
|
|
940
|
+
switch (whence) {
|
|
941
|
+
case WHENCE_SET:
|
|
942
|
+
calculated_offset = offset;
|
|
943
|
+
break;
|
|
944
|
+
case WHENCE_CUR:
|
|
945
|
+
calculated_offset = this.file_pos + offset;
|
|
946
|
+
break;
|
|
947
|
+
case WHENCE_END:
|
|
948
|
+
calculated_offset = BigInt(this.file.data.byteLength) + offset;
|
|
949
|
+
break;
|
|
950
|
+
default:
|
|
951
|
+
return { ret: ERRNO_INVAL, offset: 0n };
|
|
952
|
+
}
|
|
953
|
+
if (calculated_offset < 0) {
|
|
954
|
+
return { ret: ERRNO_INVAL, offset: 0n };
|
|
955
|
+
}
|
|
956
|
+
this.file_pos = calculated_offset;
|
|
957
|
+
return { ret: 0, offset: this.file_pos };
|
|
958
|
+
}
|
|
959
|
+
fd_tell() {
|
|
960
|
+
return { ret: 0, offset: this.file_pos };
|
|
961
|
+
}
|
|
962
|
+
fd_write(data) {
|
|
963
|
+
if (this.file.readonly) return { ret: ERRNO_BADF, nwritten: 0 };
|
|
964
|
+
if (this.file_pos + BigInt(data.byteLength) > this.file.size) {
|
|
965
|
+
const old = this.file.data;
|
|
966
|
+
this.file.data = new Uint8Array(Number(this.file_pos + BigInt(data.byteLength)));
|
|
967
|
+
this.file.data.set(old);
|
|
968
|
+
}
|
|
969
|
+
this.file.data.set(data, Number(this.file_pos));
|
|
970
|
+
this.file_pos += BigInt(data.byteLength);
|
|
971
|
+
return { ret: 0, nwritten: data.byteLength };
|
|
972
|
+
}
|
|
973
|
+
fd_pwrite(data, offset) {
|
|
974
|
+
if (this.file.readonly) return { ret: ERRNO_BADF, nwritten: 0 };
|
|
975
|
+
if (offset + BigInt(data.byteLength) > this.file.size) {
|
|
976
|
+
const old = this.file.data;
|
|
977
|
+
this.file.data = new Uint8Array(Number(offset + BigInt(data.byteLength)));
|
|
978
|
+
this.file.data.set(old);
|
|
979
|
+
}
|
|
980
|
+
this.file.data.set(data, Number(offset));
|
|
981
|
+
return { ret: 0, nwritten: data.byteLength };
|
|
982
|
+
}
|
|
983
|
+
fd_filestat_get() {
|
|
984
|
+
return { ret: 0, filestat: this.file.stat() };
|
|
985
|
+
}
|
|
986
|
+
constructor(file) {
|
|
987
|
+
super();
|
|
988
|
+
this.file_pos = 0n;
|
|
989
|
+
this.file = file;
|
|
990
|
+
}
|
|
991
|
+
};
|
|
992
|
+
var OpenDirectory = class extends Fd {
|
|
993
|
+
fd_seek(offset, whence) {
|
|
994
|
+
return { ret: ERRNO_BADF, offset: 0n };
|
|
995
|
+
}
|
|
996
|
+
fd_tell() {
|
|
997
|
+
return { ret: ERRNO_BADF, offset: 0n };
|
|
998
|
+
}
|
|
999
|
+
fd_allocate(offset, len) {
|
|
1000
|
+
return ERRNO_BADF;
|
|
1001
|
+
}
|
|
1002
|
+
fd_fdstat_get() {
|
|
1003
|
+
return { ret: 0, fdstat: new Fdstat(FILETYPE_DIRECTORY, 0) };
|
|
1004
|
+
}
|
|
1005
|
+
fd_readdir_single(cookie) {
|
|
1006
|
+
if (debug.enabled) {
|
|
1007
|
+
debug.log("readdir_single", cookie);
|
|
1008
|
+
debug.log(cookie, this.dir.contents.keys());
|
|
1009
|
+
}
|
|
1010
|
+
if (cookie == 0n) {
|
|
1011
|
+
return { ret: ERRNO_SUCCESS, dirent: new Dirent(1n, this.dir.ino, ".", FILETYPE_DIRECTORY) };
|
|
1012
|
+
} else if (cookie == 1n) {
|
|
1013
|
+
return { ret: ERRNO_SUCCESS, dirent: new Dirent(2n, this.dir.parent_ino(), "..", FILETYPE_DIRECTORY) };
|
|
1014
|
+
}
|
|
1015
|
+
if (cookie >= BigInt(this.dir.contents.size) + 2n) {
|
|
1016
|
+
return { ret: 0, dirent: null };
|
|
1017
|
+
}
|
|
1018
|
+
const [name, entry] = Array.from(this.dir.contents.entries())[Number(cookie - 2n)];
|
|
1019
|
+
return { ret: 0, dirent: new Dirent(cookie + 1n, entry.ino, name, entry.stat().filetype) };
|
|
1020
|
+
}
|
|
1021
|
+
path_filestat_get(flags, path_str) {
|
|
1022
|
+
const { ret: path_err, path } = Path.from(path_str);
|
|
1023
|
+
if (path == null) {
|
|
1024
|
+
return { ret: path_err, filestat: null };
|
|
1025
|
+
}
|
|
1026
|
+
const { ret, entry } = this.dir.get_entry_for_path(path);
|
|
1027
|
+
if (entry == null) {
|
|
1028
|
+
return { ret, filestat: null };
|
|
1029
|
+
}
|
|
1030
|
+
return { ret: 0, filestat: entry.stat() };
|
|
1031
|
+
}
|
|
1032
|
+
path_lookup(path_str, dirflags) {
|
|
1033
|
+
const { ret: path_ret, path } = Path.from(path_str);
|
|
1034
|
+
if (path == null) {
|
|
1035
|
+
return { ret: path_ret, inode_obj: null };
|
|
1036
|
+
}
|
|
1037
|
+
const { ret, entry } = this.dir.get_entry_for_path(path);
|
|
1038
|
+
if (entry == null) {
|
|
1039
|
+
return { ret, inode_obj: null };
|
|
1040
|
+
}
|
|
1041
|
+
return { ret: ERRNO_SUCCESS, inode_obj: entry };
|
|
1042
|
+
}
|
|
1043
|
+
path_open(dirflags, path_str, oflags, fs_rights_base, fs_rights_inheriting, fd_flags) {
|
|
1044
|
+
const { ret: path_ret, path } = Path.from(path_str);
|
|
1045
|
+
if (path == null) {
|
|
1046
|
+
return { ret: path_ret, fd_obj: null };
|
|
1047
|
+
}
|
|
1048
|
+
let { ret, entry } = this.dir.get_entry_for_path(path);
|
|
1049
|
+
if (entry == null) {
|
|
1050
|
+
if (ret != ERRNO_NOENT) {
|
|
1051
|
+
return { ret, fd_obj: null };
|
|
1052
|
+
}
|
|
1053
|
+
if ((oflags & OFLAGS_CREAT) == OFLAGS_CREAT) {
|
|
1054
|
+
const { ret: ret2, entry: new_entry } = this.dir.create_entry_for_path(path_str, (oflags & OFLAGS_DIRECTORY) == OFLAGS_DIRECTORY);
|
|
1055
|
+
if (new_entry == null) {
|
|
1056
|
+
return { ret: ret2, fd_obj: null };
|
|
1057
|
+
}
|
|
1058
|
+
entry = new_entry;
|
|
1059
|
+
} else {
|
|
1060
|
+
return { ret: ERRNO_NOENT, fd_obj: null };
|
|
1061
|
+
}
|
|
1062
|
+
} else if ((oflags & OFLAGS_EXCL) == OFLAGS_EXCL) {
|
|
1063
|
+
return { ret: ERRNO_EXIST, fd_obj: null };
|
|
1064
|
+
}
|
|
1065
|
+
if ((oflags & OFLAGS_DIRECTORY) == OFLAGS_DIRECTORY && entry.stat().filetype !== FILETYPE_DIRECTORY) {
|
|
1066
|
+
return { ret: ERRNO_NOTDIR, fd_obj: null };
|
|
1067
|
+
}
|
|
1068
|
+
return entry.path_open(oflags, fs_rights_base, fd_flags);
|
|
1069
|
+
}
|
|
1070
|
+
path_create_directory(path) {
|
|
1071
|
+
return this.path_open(0, path, OFLAGS_CREAT | OFLAGS_DIRECTORY, 0n, 0n, 0).ret;
|
|
1072
|
+
}
|
|
1073
|
+
path_link(path_str, inode, allow_dir) {
|
|
1074
|
+
const { ret: path_ret, path } = Path.from(path_str);
|
|
1075
|
+
if (path == null) {
|
|
1076
|
+
return path_ret;
|
|
1077
|
+
}
|
|
1078
|
+
if (path.is_dir) {
|
|
1079
|
+
return ERRNO_NOENT;
|
|
1080
|
+
}
|
|
1081
|
+
const { ret: parent_ret, parent_entry, filename, entry } = this.dir.get_parent_dir_and_entry_for_path(path, true);
|
|
1082
|
+
if (parent_entry == null || filename == null) {
|
|
1083
|
+
return parent_ret;
|
|
1084
|
+
}
|
|
1085
|
+
if (entry != null) {
|
|
1086
|
+
const source_is_dir = inode.stat().filetype == FILETYPE_DIRECTORY;
|
|
1087
|
+
const target_is_dir = entry.stat().filetype == FILETYPE_DIRECTORY;
|
|
1088
|
+
if (source_is_dir && target_is_dir) {
|
|
1089
|
+
if (allow_dir && entry instanceof Directory) {
|
|
1090
|
+
if (entry.contents.size == 0) {
|
|
1091
|
+
} else {
|
|
1092
|
+
return ERRNO_NOTEMPTY;
|
|
1093
|
+
}
|
|
1094
|
+
} else {
|
|
1095
|
+
return ERRNO_EXIST;
|
|
1096
|
+
}
|
|
1097
|
+
} else if (source_is_dir && !target_is_dir) {
|
|
1098
|
+
return ERRNO_NOTDIR;
|
|
1099
|
+
} else if (!source_is_dir && target_is_dir) {
|
|
1100
|
+
return ERRNO_ISDIR;
|
|
1101
|
+
} else if (inode.stat().filetype == FILETYPE_REGULAR_FILE && entry.stat().filetype == FILETYPE_REGULAR_FILE) {
|
|
1102
|
+
} else {
|
|
1103
|
+
return ERRNO_EXIST;
|
|
1104
|
+
}
|
|
1105
|
+
}
|
|
1106
|
+
if (!allow_dir && inode.stat().filetype == FILETYPE_DIRECTORY) {
|
|
1107
|
+
return ERRNO_PERM;
|
|
1108
|
+
}
|
|
1109
|
+
parent_entry.contents.set(filename, inode);
|
|
1110
|
+
return ERRNO_SUCCESS;
|
|
1111
|
+
}
|
|
1112
|
+
path_unlink(path_str) {
|
|
1113
|
+
const { ret: path_ret, path } = Path.from(path_str);
|
|
1114
|
+
if (path == null) {
|
|
1115
|
+
return { ret: path_ret, inode_obj: null };
|
|
1116
|
+
}
|
|
1117
|
+
const { ret: parent_ret, parent_entry, filename, entry } = this.dir.get_parent_dir_and_entry_for_path(path, true);
|
|
1118
|
+
if (parent_entry == null || filename == null) {
|
|
1119
|
+
return { ret: parent_ret, inode_obj: null };
|
|
1120
|
+
}
|
|
1121
|
+
if (entry == null) {
|
|
1122
|
+
return { ret: ERRNO_NOENT, inode_obj: null };
|
|
1123
|
+
}
|
|
1124
|
+
parent_entry.contents.delete(filename);
|
|
1125
|
+
return { ret: ERRNO_SUCCESS, inode_obj: entry };
|
|
1126
|
+
}
|
|
1127
|
+
path_unlink_file(path_str) {
|
|
1128
|
+
const { ret: path_ret, path } = Path.from(path_str);
|
|
1129
|
+
if (path == null) {
|
|
1130
|
+
return path_ret;
|
|
1131
|
+
}
|
|
1132
|
+
const { ret: parent_ret, parent_entry, filename, entry } = this.dir.get_parent_dir_and_entry_for_path(path, false);
|
|
1133
|
+
if (parent_entry == null || filename == null || entry == null) {
|
|
1134
|
+
return parent_ret;
|
|
1135
|
+
}
|
|
1136
|
+
if (entry.stat().filetype === FILETYPE_DIRECTORY) {
|
|
1137
|
+
return ERRNO_ISDIR;
|
|
1138
|
+
}
|
|
1139
|
+
parent_entry.contents.delete(filename);
|
|
1140
|
+
return ERRNO_SUCCESS;
|
|
1141
|
+
}
|
|
1142
|
+
path_remove_directory(path_str) {
|
|
1143
|
+
const { ret: path_ret, path } = Path.from(path_str);
|
|
1144
|
+
if (path == null) {
|
|
1145
|
+
return path_ret;
|
|
1146
|
+
}
|
|
1147
|
+
const { ret: parent_ret, parent_entry, filename, entry } = this.dir.get_parent_dir_and_entry_for_path(path, false);
|
|
1148
|
+
if (parent_entry == null || filename == null || entry == null) {
|
|
1149
|
+
return parent_ret;
|
|
1150
|
+
}
|
|
1151
|
+
if (!(entry instanceof Directory) || entry.stat().filetype !== FILETYPE_DIRECTORY) {
|
|
1152
|
+
return ERRNO_NOTDIR;
|
|
1153
|
+
}
|
|
1154
|
+
if (entry.contents.size !== 0) {
|
|
1155
|
+
return ERRNO_NOTEMPTY;
|
|
1156
|
+
}
|
|
1157
|
+
if (!parent_entry.contents.delete(filename)) {
|
|
1158
|
+
return ERRNO_NOENT;
|
|
1159
|
+
}
|
|
1160
|
+
return ERRNO_SUCCESS;
|
|
1161
|
+
}
|
|
1162
|
+
fd_filestat_get() {
|
|
1163
|
+
return { ret: 0, filestat: this.dir.stat() };
|
|
1164
|
+
}
|
|
1165
|
+
fd_filestat_set_size(size) {
|
|
1166
|
+
return ERRNO_BADF;
|
|
1167
|
+
}
|
|
1168
|
+
fd_read(size) {
|
|
1169
|
+
return { ret: ERRNO_BADF, data: new Uint8Array() };
|
|
1170
|
+
}
|
|
1171
|
+
fd_pread(size, offset) {
|
|
1172
|
+
return { ret: ERRNO_BADF, data: new Uint8Array() };
|
|
1173
|
+
}
|
|
1174
|
+
fd_write(data) {
|
|
1175
|
+
return { ret: ERRNO_BADF, nwritten: 0 };
|
|
1176
|
+
}
|
|
1177
|
+
fd_pwrite(data, offset) {
|
|
1178
|
+
return { ret: ERRNO_BADF, nwritten: 0 };
|
|
1179
|
+
}
|
|
1180
|
+
constructor(dir) {
|
|
1181
|
+
super();
|
|
1182
|
+
this.dir = dir;
|
|
1183
|
+
}
|
|
1184
|
+
};
|
|
1185
|
+
var PreopenDirectory = class extends OpenDirectory {
|
|
1186
|
+
fd_prestat_get() {
|
|
1187
|
+
return { ret: 0, prestat: Prestat.dir(this.prestat_name) };
|
|
1188
|
+
}
|
|
1189
|
+
constructor(name, contents) {
|
|
1190
|
+
super(new Directory(contents));
|
|
1191
|
+
this.prestat_name = name;
|
|
1192
|
+
}
|
|
1193
|
+
};
|
|
1194
|
+
var File = class extends Inode {
|
|
1195
|
+
path_open(oflags, fs_rights_base, fd_flags) {
|
|
1196
|
+
if (this.readonly && (fs_rights_base & BigInt(RIGHTS_FD_WRITE)) == BigInt(RIGHTS_FD_WRITE)) {
|
|
1197
|
+
return { ret: ERRNO_PERM, fd_obj: null };
|
|
1198
|
+
}
|
|
1199
|
+
if ((oflags & OFLAGS_TRUNC) == OFLAGS_TRUNC) {
|
|
1200
|
+
if (this.readonly) return { ret: ERRNO_PERM, fd_obj: null };
|
|
1201
|
+
this.data = new Uint8Array([]);
|
|
1202
|
+
}
|
|
1203
|
+
const file = new OpenFile(this);
|
|
1204
|
+
if (fd_flags & FDFLAGS_APPEND) file.fd_seek(0n, WHENCE_END);
|
|
1205
|
+
return { ret: ERRNO_SUCCESS, fd_obj: file };
|
|
1206
|
+
}
|
|
1207
|
+
get size() {
|
|
1208
|
+
return BigInt(this.data.byteLength);
|
|
1209
|
+
}
|
|
1210
|
+
stat() {
|
|
1211
|
+
return new Filestat(this.ino, FILETYPE_REGULAR_FILE, this.size);
|
|
1212
|
+
}
|
|
1213
|
+
constructor(data, options) {
|
|
1214
|
+
super();
|
|
1215
|
+
this.data = new Uint8Array(data);
|
|
1216
|
+
this.readonly = !!options?.readonly;
|
|
1217
|
+
}
|
|
1218
|
+
};
|
|
1219
|
+
var Path = class Path2 {
|
|
1220
|
+
static from(path) {
|
|
1221
|
+
const self2 = new Path2();
|
|
1222
|
+
self2.is_dir = path.endsWith("/");
|
|
1223
|
+
if (path.startsWith("/")) {
|
|
1224
|
+
return { ret: ERRNO_NOTCAPABLE, path: null };
|
|
1225
|
+
}
|
|
1226
|
+
if (path.includes("\0")) {
|
|
1227
|
+
return { ret: ERRNO_INVAL, path: null };
|
|
1228
|
+
}
|
|
1229
|
+
for (const component of path.split("/")) {
|
|
1230
|
+
if (component === "" || component === ".") {
|
|
1231
|
+
continue;
|
|
1232
|
+
}
|
|
1233
|
+
if (component === "..") {
|
|
1234
|
+
if (self2.parts.pop() == void 0) {
|
|
1235
|
+
return { ret: ERRNO_NOTCAPABLE, path: null };
|
|
1236
|
+
}
|
|
1237
|
+
continue;
|
|
1238
|
+
}
|
|
1239
|
+
self2.parts.push(component);
|
|
1240
|
+
}
|
|
1241
|
+
return { ret: ERRNO_SUCCESS, path: self2 };
|
|
1242
|
+
}
|
|
1243
|
+
to_path_string() {
|
|
1244
|
+
let s = this.parts.join("/");
|
|
1245
|
+
if (this.is_dir) {
|
|
1246
|
+
s += "/";
|
|
1247
|
+
}
|
|
1248
|
+
return s;
|
|
1249
|
+
}
|
|
1250
|
+
constructor() {
|
|
1251
|
+
this.parts = [];
|
|
1252
|
+
this.is_dir = false;
|
|
1253
|
+
}
|
|
1254
|
+
};
|
|
1255
|
+
var Directory = class _Directory extends Inode {
|
|
1256
|
+
parent_ino() {
|
|
1257
|
+
if (this.parent == null) {
|
|
1258
|
+
return Inode.root_ino();
|
|
1259
|
+
}
|
|
1260
|
+
return this.parent.ino;
|
|
1261
|
+
}
|
|
1262
|
+
path_open(oflags, fs_rights_base, fd_flags) {
|
|
1263
|
+
return { ret: ERRNO_SUCCESS, fd_obj: new OpenDirectory(this) };
|
|
1264
|
+
}
|
|
1265
|
+
stat() {
|
|
1266
|
+
return new Filestat(this.ino, FILETYPE_DIRECTORY, 0n);
|
|
1267
|
+
}
|
|
1268
|
+
get_entry_for_path(path) {
|
|
1269
|
+
let entry = this;
|
|
1270
|
+
for (const component of path.parts) {
|
|
1271
|
+
if (!(entry instanceof _Directory)) {
|
|
1272
|
+
return { ret: ERRNO_NOTDIR, entry: null };
|
|
1273
|
+
}
|
|
1274
|
+
const child = entry.contents.get(component);
|
|
1275
|
+
if (child !== void 0) {
|
|
1276
|
+
entry = child;
|
|
1277
|
+
} else {
|
|
1278
|
+
debug.log(component);
|
|
1279
|
+
return { ret: ERRNO_NOENT, entry: null };
|
|
1280
|
+
}
|
|
1281
|
+
}
|
|
1282
|
+
if (path.is_dir) {
|
|
1283
|
+
if (entry.stat().filetype != FILETYPE_DIRECTORY) {
|
|
1284
|
+
return { ret: ERRNO_NOTDIR, entry: null };
|
|
1285
|
+
}
|
|
1286
|
+
}
|
|
1287
|
+
return { ret: ERRNO_SUCCESS, entry };
|
|
1288
|
+
}
|
|
1289
|
+
get_parent_dir_and_entry_for_path(path, allow_undefined) {
|
|
1290
|
+
const filename = path.parts.pop();
|
|
1291
|
+
if (filename === void 0) {
|
|
1292
|
+
return { ret: ERRNO_INVAL, parent_entry: null, filename: null, entry: null };
|
|
1293
|
+
}
|
|
1294
|
+
const { ret: entry_ret, entry: parent_entry } = this.get_entry_for_path(path);
|
|
1295
|
+
if (parent_entry == null) {
|
|
1296
|
+
return { ret: entry_ret, parent_entry: null, filename: null, entry: null };
|
|
1297
|
+
}
|
|
1298
|
+
if (!(parent_entry instanceof _Directory)) {
|
|
1299
|
+
return { ret: ERRNO_NOTDIR, parent_entry: null, filename: null, entry: null };
|
|
1300
|
+
}
|
|
1301
|
+
const entry = parent_entry.contents.get(filename);
|
|
1302
|
+
if (entry === void 0) {
|
|
1303
|
+
if (!allow_undefined) {
|
|
1304
|
+
return { ret: ERRNO_NOENT, parent_entry: null, filename: null, entry: null };
|
|
1305
|
+
} else {
|
|
1306
|
+
return { ret: ERRNO_SUCCESS, parent_entry, filename, entry: null };
|
|
1307
|
+
}
|
|
1308
|
+
}
|
|
1309
|
+
if (path.is_dir) {
|
|
1310
|
+
if (entry.stat().filetype != FILETYPE_DIRECTORY) {
|
|
1311
|
+
return { ret: ERRNO_NOTDIR, parent_entry: null, filename: null, entry: null };
|
|
1312
|
+
}
|
|
1313
|
+
}
|
|
1314
|
+
return { ret: ERRNO_SUCCESS, parent_entry, filename, entry };
|
|
1315
|
+
}
|
|
1316
|
+
create_entry_for_path(path_str, is_dir) {
|
|
1317
|
+
const { ret: path_ret, path } = Path.from(path_str);
|
|
1318
|
+
if (path == null) {
|
|
1319
|
+
return { ret: path_ret, entry: null };
|
|
1320
|
+
}
|
|
1321
|
+
let { ret: parent_ret, parent_entry, filename, entry } = this.get_parent_dir_and_entry_for_path(path, true);
|
|
1322
|
+
if (parent_entry == null || filename == null) {
|
|
1323
|
+
return { ret: parent_ret, entry: null };
|
|
1324
|
+
}
|
|
1325
|
+
if (entry != null) {
|
|
1326
|
+
return { ret: ERRNO_EXIST, entry: null };
|
|
1327
|
+
}
|
|
1328
|
+
debug.log("create", path);
|
|
1329
|
+
let new_child;
|
|
1330
|
+
if (!is_dir) {
|
|
1331
|
+
new_child = new File(new ArrayBuffer(0));
|
|
1332
|
+
} else {
|
|
1333
|
+
new_child = new _Directory(/* @__PURE__ */ new Map());
|
|
1334
|
+
}
|
|
1335
|
+
parent_entry.contents.set(filename, new_child);
|
|
1336
|
+
entry = new_child;
|
|
1337
|
+
return { ret: ERRNO_SUCCESS, entry };
|
|
1338
|
+
}
|
|
1339
|
+
constructor(contents) {
|
|
1340
|
+
super();
|
|
1341
|
+
this.parent = null;
|
|
1342
|
+
if (contents instanceof Array) {
|
|
1343
|
+
this.contents = new Map(contents);
|
|
1344
|
+
} else {
|
|
1345
|
+
this.contents = contents;
|
|
1346
|
+
}
|
|
1347
|
+
for (const entry of this.contents.values()) {
|
|
1348
|
+
if (entry instanceof _Directory) {
|
|
1349
|
+
entry.parent = this;
|
|
1350
|
+
}
|
|
1351
|
+
}
|
|
1352
|
+
}
|
|
1353
|
+
};
|
|
1354
|
+
var ConsoleStdout = class _ConsoleStdout extends Fd {
|
|
1355
|
+
fd_filestat_get() {
|
|
1356
|
+
const filestat = new Filestat(this.ino, FILETYPE_CHARACTER_DEVICE, BigInt(0));
|
|
1357
|
+
return { ret: 0, filestat };
|
|
1358
|
+
}
|
|
1359
|
+
fd_fdstat_get() {
|
|
1360
|
+
const fdstat = new Fdstat(FILETYPE_CHARACTER_DEVICE, 0);
|
|
1361
|
+
fdstat.fs_rights_base = BigInt(RIGHTS_FD_WRITE);
|
|
1362
|
+
return { ret: 0, fdstat };
|
|
1363
|
+
}
|
|
1364
|
+
fd_write(data) {
|
|
1365
|
+
this.write(data);
|
|
1366
|
+
return { ret: 0, nwritten: data.byteLength };
|
|
1367
|
+
}
|
|
1368
|
+
static lineBuffered(write) {
|
|
1369
|
+
const dec = new TextDecoder("utf-8", { fatal: false });
|
|
1370
|
+
let line_buf = "";
|
|
1371
|
+
return new _ConsoleStdout((buffer) => {
|
|
1372
|
+
line_buf += dec.decode(buffer, { stream: true });
|
|
1373
|
+
const lines = line_buf.split("\n");
|
|
1374
|
+
for (const [i, line] of lines.entries()) {
|
|
1375
|
+
if (i < lines.length - 1) {
|
|
1376
|
+
write(line);
|
|
1377
|
+
} else {
|
|
1378
|
+
line_buf = line;
|
|
1379
|
+
}
|
|
1380
|
+
}
|
|
1381
|
+
});
|
|
1382
|
+
}
|
|
1383
|
+
constructor(write) {
|
|
1384
|
+
super();
|
|
1385
|
+
this.ino = Inode.issue_ino();
|
|
1386
|
+
this.write = write;
|
|
1387
|
+
}
|
|
1388
|
+
};
|
|
1389
|
+
|
|
1390
|
+
// src/engine-runner.js
|
|
1391
|
+
async function runEngine(job) {
|
|
1392
|
+
try {
|
|
1393
|
+
const root = new PreopenDirectory(".", /* @__PURE__ */ new Map());
|
|
1394
|
+
const put = (path, data) => {
|
|
1395
|
+
const parts = path.split("/");
|
|
1396
|
+
let directory = root.dir;
|
|
1397
|
+
for (const part of parts.slice(0, -1)) {
|
|
1398
|
+
if (!directory.contents.has(part)) directory.contents.set(part, new Directory(/* @__PURE__ */ new Map()));
|
|
1399
|
+
directory = directory.contents.get(part);
|
|
1400
|
+
}
|
|
1401
|
+
directory.contents.set(parts.at(-1), new File(data));
|
|
1402
|
+
};
|
|
1403
|
+
const encoder = new TextEncoder();
|
|
1404
|
+
put("input.html", encoder.encode(job.html));
|
|
1405
|
+
put("style.css", encoder.encode(job.css));
|
|
1406
|
+
for (const file of [...job.fonts, ...job.assets]) put(file.name, file.data);
|
|
1407
|
+
let log = "";
|
|
1408
|
+
const collect = (line) => {
|
|
1409
|
+
if (log.length < 4e3) log += String(line).slice(0, 4e3 - log.length) + "\n";
|
|
1410
|
+
};
|
|
1411
|
+
const wasi = new WASI(["fullbleed", String(job.maxPages), String(job.previewDpi), job.allowMissingGlyphs ? "allow" : "reject", ...job.fonts.map((f) => f.name)], [], [
|
|
1412
|
+
new OpenFile(new File([])),
|
|
1413
|
+
ConsoleStdout.lineBuffered(collect),
|
|
1414
|
+
ConsoleStdout.lineBuffered(collect),
|
|
1415
|
+
root
|
|
1416
|
+
], { debug: false });
|
|
1417
|
+
const instance = await WebAssembly.instantiate(job.module, { wasi_snapshot_preview1: wasi.wasiImport });
|
|
1418
|
+
const status = wasi.start(instance);
|
|
1419
|
+
if (status !== 0) {
|
|
1420
|
+
const code = ["PAGE_LIMIT", "MISSING_GLYPHS", "PREVIEW_FAILED"].find((c) => log.includes(c + ":")) ?? "RENDER_FAILED";
|
|
1421
|
+
return { ok: false, code, message: log.trim() || `The engine exited with code ${status}.` };
|
|
1422
|
+
} else {
|
|
1423
|
+
const read = (name) => {
|
|
1424
|
+
const file = root.dir.contents.get(name);
|
|
1425
|
+
if (!(file instanceof File)) throw new Error(`Missing engine output: ${name}`);
|
|
1426
|
+
return Uint8Array.from(file.data);
|
|
1427
|
+
};
|
|
1428
|
+
const report = JSON.parse(new TextDecoder().decode(read("result.json")));
|
|
1429
|
+
const pdf = read("document.pdf");
|
|
1430
|
+
if (new TextDecoder().decode(pdf.slice(0, 5)) !== "%PDF-") throw new Error("Engine output is not a PDF.");
|
|
1431
|
+
const previews = job.previewDpi ? Array.from({ length: report.pages }, (_, i) => read(`preview-${i + 1}.png`)) : [];
|
|
1432
|
+
return { ok: true, pdf, previews, ...report };
|
|
1433
|
+
}
|
|
1434
|
+
} catch (cause) {
|
|
1435
|
+
const code = cause instanceof WebAssembly.RuntimeError || cause instanceof RangeError ? "ENGINE_LIMIT" : "RENDER_FAILED";
|
|
1436
|
+
return { ok: false, code, message: cause.message || String(cause) };
|
|
1437
|
+
}
|
|
1438
|
+
}
|
|
1439
|
+
|
|
1440
|
+
// src/browser-worker.js
|
|
1441
|
+
var version = "0.3.1";
|
|
1442
|
+
var engineVersion = "2.5.10";
|
|
1443
|
+
var files = define_FULLBLEED_RUNTIME_FILES_default;
|
|
1444
|
+
var fontNames = define_FULLBLEED_FONT_NAMES_default;
|
|
1445
|
+
var hex = (bytes) => Array.from(new Uint8Array(bytes), (value) => value.toString(16).padStart(2, "0")).join("");
|
|
1446
|
+
async function load(name) {
|
|
1447
|
+
const url = new URL(name, self.location.href);
|
|
1448
|
+
url.searchParams.set("v", version);
|
|
1449
|
+
const response = await fetch(url, { credentials: "omit", redirect: "error" });
|
|
1450
|
+
if (!response.ok) throw new Error(`Could not load ${name} (HTTP ${response.status}).`);
|
|
1451
|
+
const bytes = new Uint8Array(await response.arrayBuffer());
|
|
1452
|
+
if (bytes.length !== files[name].bytes || hex(await crypto.subtle.digest("SHA-256", bytes)) !== files[name].sha256) {
|
|
1453
|
+
throw new Error(`Bundled asset failed verification: ${name}.`);
|
|
1454
|
+
}
|
|
1455
|
+
return bytes;
|
|
1456
|
+
}
|
|
1457
|
+
self.addEventListener("message", async ({ data }) => {
|
|
1458
|
+
let result;
|
|
1459
|
+
try {
|
|
1460
|
+
if (data?.type !== "render") throw new Error("Invalid render request.");
|
|
1461
|
+
const [wasm, ...fontBytes] = await Promise.all([load("engine.wasm"), ...fontNames.map((name) => load("fonts/" + name))]);
|
|
1462
|
+
const module = await WebAssembly.compile(wasm);
|
|
1463
|
+
if (!WebAssembly.Module.imports(module).every((item) => item.module === "wasi_snapshot_preview1" && !item.name.startsWith("sock_"))) {
|
|
1464
|
+
throw new Error("Unexpected WebAssembly host imports.");
|
|
1465
|
+
}
|
|
1466
|
+
result = await runEngine({
|
|
1467
|
+
...data.job,
|
|
1468
|
+
module,
|
|
1469
|
+
fonts: [...fontNames.map((name, i) => ({ name: "fonts/" + name, data: fontBytes[i] })), ...data.job.fonts]
|
|
1470
|
+
});
|
|
1471
|
+
} catch (cause) {
|
|
1472
|
+
result = { ok: false, code: "ENGINE_LOAD_FAILED", message: "Could not load the bundled Fullbleed engine: " + cause.message };
|
|
1473
|
+
}
|
|
1474
|
+
self.postMessage({ type: "result", engineVersion, ...result }, result.ok ? [result.pdf.buffer, ...result.previews.map((page) => page.buffer)] : []);
|
|
1475
|
+
self.close();
|
|
1476
|
+
}, { once: true });
|
|
1477
|
+
self.postMessage({ type: "ready", protocol: 1, version, engineVersion });
|