@ai-ecoverse/slicc-kernel 1.64.2 → 1.65.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 +7 -1
- package/dist/index.js.map +2 -2
- package/dist/kernel-worker.js +179 -37
- package/dist/kernel-worker.js.map +4 -4
- package/dist/node-process-worker.js +362 -187
- package/dist/node-process-worker.js.map +4 -4
- package/dist/node.js +179 -37
- package/dist/node.js.map +4 -4
- package/dist/process-worker.js +362 -187
- package/dist/process-worker.js.map +4 -4
- package/package.json +1 -1
package/dist/process-worker.js
CHANGED
|
@@ -661,16 +661,16 @@ var init_wasi_errno = __esm({
|
|
|
661
661
|
});
|
|
662
662
|
|
|
663
663
|
// src/realm/sync-fs-wire.ts
|
|
664
|
-
function parseSyncFsUsage(
|
|
665
|
-
const u =
|
|
664
|
+
function parseSyncFsUsage(json2) {
|
|
665
|
+
const u = json2;
|
|
666
666
|
if (!u || typeof u.quota !== "number" || typeof u.usage !== "number") return null;
|
|
667
667
|
return { quota: u.quota, usage: u.usage };
|
|
668
668
|
}
|
|
669
669
|
function syncError(code2, label) {
|
|
670
670
|
return Object.assign(new Error(`${code2}: ${label}`), { code: code2 });
|
|
671
671
|
}
|
|
672
|
-
function parseSyncFsStat(
|
|
673
|
-
const s =
|
|
672
|
+
function parseSyncFsStat(json2) {
|
|
673
|
+
const s = json2;
|
|
674
674
|
if (!s || typeof s.isFile !== "boolean" || typeof s.isDirectory !== "boolean" || typeof s.size !== "number") {
|
|
675
675
|
return null;
|
|
676
676
|
}
|
|
@@ -1786,7 +1786,7 @@ function createSyncFsSabBridge(transport, opts = {}) {
|
|
|
1786
1786
|
if (r.ok && r.kind === "bytes") return r.bytes;
|
|
1787
1787
|
throw errnoError("EIO", path);
|
|
1788
1788
|
}
|
|
1789
|
-
function
|
|
1789
|
+
function json2(req, path) {
|
|
1790
1790
|
const r = run(req, path);
|
|
1791
1791
|
if (r.ok && r.kind === "json") return r.json;
|
|
1792
1792
|
throw errnoError("EIO", path);
|
|
@@ -1814,31 +1814,31 @@ function createSyncFsSabBridge(transport, opts = {}) {
|
|
|
1814
1814
|
return {
|
|
1815
1815
|
...io({}),
|
|
1816
1816
|
pinned: (handle) => io({ handle }),
|
|
1817
|
-
kept: (handle) =>
|
|
1817
|
+
kept: (handle) => json2({ op: "kept", path: "/", handle }, "/") === true,
|
|
1818
1818
|
keptStat: (handle) => {
|
|
1819
|
-
const s = parseSyncFsStat(
|
|
1819
|
+
const s = parseSyncFsStat(json2({ op: "stat", path: "/", handle }, "/"));
|
|
1820
1820
|
if (!s) throw errnoError("EIO", "/");
|
|
1821
1821
|
return s;
|
|
1822
1822
|
},
|
|
1823
1823
|
stat: (path) => {
|
|
1824
|
-
const s = parseSyncFsStat(
|
|
1824
|
+
const s = parseSyncFsStat(json2({ op: "stat", path }, path));
|
|
1825
1825
|
if (!s) throw errnoError("EIO", path);
|
|
1826
1826
|
return s;
|
|
1827
1827
|
},
|
|
1828
1828
|
lstat: (path) => {
|
|
1829
|
-
const s = parseSyncFsStat(
|
|
1829
|
+
const s = parseSyncFsStat(json2({ op: "lstat", path }, path));
|
|
1830
1830
|
if (!s) throw errnoError("EIO", path);
|
|
1831
1831
|
return s;
|
|
1832
1832
|
},
|
|
1833
1833
|
readdir: (path) => {
|
|
1834
|
-
const list =
|
|
1834
|
+
const list = json2({ op: "readdir", path }, path);
|
|
1835
1835
|
if (!Array.isArray(list) || !list.every((s) => typeof s === "string")) {
|
|
1836
1836
|
throw errnoError("EIO", path);
|
|
1837
1837
|
}
|
|
1838
1838
|
return list;
|
|
1839
1839
|
},
|
|
1840
1840
|
readdirStat: (path) => {
|
|
1841
|
-
const list =
|
|
1841
|
+
const list = json2({ op: "readdir-stat", path }, path);
|
|
1842
1842
|
if (!Array.isArray(list)) throw errnoError("EIO", path);
|
|
1843
1843
|
return list.map((entry) => {
|
|
1844
1844
|
if (!Array.isArray(entry) || typeof entry[0] !== "string") throw errnoError("EIO", path);
|
|
@@ -1849,7 +1849,7 @@ function createSyncFsSabBridge(transport, opts = {}) {
|
|
|
1849
1849
|
});
|
|
1850
1850
|
},
|
|
1851
1851
|
exists: (path) => {
|
|
1852
|
-
const v =
|
|
1852
|
+
const v = json2({ op: "exists", path }, path);
|
|
1853
1853
|
if (typeof v !== "boolean") throw errnoError("EIO", path);
|
|
1854
1854
|
return v;
|
|
1855
1855
|
},
|
|
@@ -1875,7 +1875,7 @@ function createSyncFsSabBridge(transport, opts = {}) {
|
|
|
1875
1875
|
run({ op: "symlink", path: linkPath, arg2: target }, linkPath);
|
|
1876
1876
|
},
|
|
1877
1877
|
readlink: (path) => {
|
|
1878
|
-
const target =
|
|
1878
|
+
const target = json2({ op: "readlink", path }, path);
|
|
1879
1879
|
if (typeof target !== "string") throw errnoError("EIO", path);
|
|
1880
1880
|
return target;
|
|
1881
1881
|
},
|
|
@@ -1905,11 +1905,11 @@ function createSyncFsSabBridge(transport, opts = {}) {
|
|
|
1905
1905
|
},
|
|
1906
1906
|
hold: (path, held, open, handle, want = 0) => {
|
|
1907
1907
|
const mode = (held ? 1 : 0) | (open ? 2 : 0);
|
|
1908
|
-
if (mode === 3) return
|
|
1908
|
+
if (mode === 3) return json2({ op: "hold", path, mode: mode | want }, path);
|
|
1909
1909
|
run({ op: "hold", path, mode, ...handle !== void 0 ? { handle } : {} }, path);
|
|
1910
1910
|
return void 0;
|
|
1911
1911
|
},
|
|
1912
|
-
statfs: (path = "/") => parseSyncFsUsage(
|
|
1912
|
+
statfs: (path = "/") => parseSyncFsUsage(json2({ op: "statfs", path }, path))
|
|
1913
1913
|
};
|
|
1914
1914
|
}
|
|
1915
1915
|
var init_sync_sab_bridge = __esm({
|
|
@@ -3721,7 +3721,7 @@ function createSocketKernel(deps) {
|
|
|
3721
3721
|
if (!r.ok) throw new SyscallError(r.errno);
|
|
3722
3722
|
return r;
|
|
3723
3723
|
};
|
|
3724
|
-
const
|
|
3724
|
+
const json2 = (req) => {
|
|
3725
3725
|
const r = call2(req);
|
|
3726
3726
|
return r.ok && r.kind === "json" ? r.json : void 0;
|
|
3727
3727
|
};
|
|
@@ -3761,9 +3761,9 @@ function createSocketKernel(deps) {
|
|
|
3761
3761
|
return stream.fd;
|
|
3762
3762
|
};
|
|
3763
3763
|
return {
|
|
3764
|
-
socket: (domain, nonblock, cloexec) => guard(() => install(
|
|
3764
|
+
socket: (domain, nonblock, cloexec) => guard(() => install(json2({ op: "sock-open", domain }), nonblock, cloexec)),
|
|
3765
3765
|
socketpair: (domain, nonblock, cloexec) => guard(() => {
|
|
3766
|
-
const [a, b] =
|
|
3766
|
+
const [a, b] = json2({ op: "sock-pair", domain });
|
|
3767
3767
|
let first;
|
|
3768
3768
|
try {
|
|
3769
3769
|
first = install(a, nonblock, cloexec);
|
|
@@ -3798,7 +3798,7 @@ function createSocketKernel(deps) {
|
|
|
3798
3798
|
fd: listener.sliccKernelFd,
|
|
3799
3799
|
nonblock: (listener.flags & O_NONBLOCK) !== 0
|
|
3800
3800
|
};
|
|
3801
|
-
const got =
|
|
3801
|
+
const got = json2(req);
|
|
3802
3802
|
return { fd: install(got.fd, nonblock, cloexec), peer: got.peer };
|
|
3803
3803
|
}),
|
|
3804
3804
|
connect: (fd, addr) => guard(() => {
|
|
@@ -3812,10 +3812,10 @@ function createSocketKernel(deps) {
|
|
|
3812
3812
|
});
|
|
3813
3813
|
}),
|
|
3814
3814
|
shutdown: (fd, how) => guard(() => done({ op: "sock-shutdown", fd: kfd(fd), how })),
|
|
3815
|
-
name: (fd, peer) => guard(() =>
|
|
3816
|
-
getopt: (fd, level, name2) => guard(() => ({ value:
|
|
3815
|
+
name: (fd, peer) => guard(() => json2({ op: "sock-name", fd: kfd(fd), peer })),
|
|
3816
|
+
getopt: (fd, level, name2) => guard(() => ({ value: json2({ op: "sock-getopt", fd: kfd(fd), level, name: name2 }) })),
|
|
3817
3817
|
setopt: (fd, level, name2, value2) => guard(() => done({ op: "sock-setopt", fd: kfd(fd), level, name: name2, value: value2 })),
|
|
3818
|
-
resolve: (name2, family = 4) => guard(() =>
|
|
3818
|
+
resolve: (name2, family = 4) => guard(() => json2({ op: "sock-resolve", name: name2, family })),
|
|
3819
3819
|
send: (fd, bytes, flags) => guard(() => {
|
|
3820
3820
|
const stream = socketAt(fd);
|
|
3821
3821
|
const nonblock = flags.dontwait === true || (stream.flags & O_NONBLOCK) !== 0;
|
|
@@ -4252,7 +4252,7 @@ function kernelSys(transport) {
|
|
|
4252
4252
|
if (!r.ok) throw new SyscallError(r.errno);
|
|
4253
4253
|
return r;
|
|
4254
4254
|
};
|
|
4255
|
-
const
|
|
4255
|
+
const json2 = (r) => r.ok && r.kind === "json" ? r.json : void 0;
|
|
4256
4256
|
return {
|
|
4257
4257
|
read(fd, max, opts) {
|
|
4258
4258
|
const flags = {
|
|
@@ -4269,20 +4269,20 @@ function kernelSys(transport) {
|
|
|
4269
4269
|
body: bytes,
|
|
4270
4270
|
...opts?.nonblock ? { nonblock: true } : {}
|
|
4271
4271
|
};
|
|
4272
|
-
const n =
|
|
4272
|
+
const n = json2(call2(req, `fd-write ${fd}`));
|
|
4273
4273
|
return typeof n === "number" ? n : bytes.length;
|
|
4274
4274
|
},
|
|
4275
4275
|
close(fd) {
|
|
4276
4276
|
call2({ op: "fd-close", fd }, `fd-close ${fd}`);
|
|
4277
4277
|
},
|
|
4278
4278
|
pipe() {
|
|
4279
|
-
return
|
|
4279
|
+
return json2(call2({ op: "fd-pipe" }, "fd-pipe"));
|
|
4280
4280
|
},
|
|
4281
4281
|
poll(fd) {
|
|
4282
|
-
return
|
|
4282
|
+
return json2(call2({ op: "fd-poll", fd }, `fd-poll ${fd}`));
|
|
4283
4283
|
},
|
|
4284
4284
|
openVfs(path, flags, position, opts) {
|
|
4285
|
-
return
|
|
4285
|
+
return json2(
|
|
4286
4286
|
call2(
|
|
4287
4287
|
{
|
|
4288
4288
|
op: "fd-open-vfs",
|
|
@@ -4302,7 +4302,7 @@ function kernelSys(transport) {
|
|
|
4302
4302
|
);
|
|
4303
4303
|
},
|
|
4304
4304
|
seek(fd, offset, whence) {
|
|
4305
|
-
return
|
|
4305
|
+
return json2(call2({ op: "fd-seek", fd, offset, whence }, `fd-seek ${fd}`));
|
|
4306
4306
|
},
|
|
4307
4307
|
flush(fd) {
|
|
4308
4308
|
call2({ op: "fd-flush", fd }, `fd-flush ${fd}`);
|
|
@@ -4312,64 +4312,64 @@ function kernelSys(transport) {
|
|
|
4312
4312
|
return r.ok && r.kind === "bytes" ? r.bytes : new Uint8Array(0);
|
|
4313
4313
|
},
|
|
4314
4314
|
pwrite(fd, bytes, at) {
|
|
4315
|
-
return
|
|
4315
|
+
return json2(
|
|
4316
4316
|
call2({ op: "fd-pwrite", fd, offset: at, body: bytes }, `fd-pwrite ${fd}`)
|
|
4317
4317
|
);
|
|
4318
4318
|
},
|
|
4319
4319
|
isatty(fd) {
|
|
4320
|
-
return
|
|
4320
|
+
return json2(call2({ op: "fd-info", fd }, `fd-info ${fd}`))?.tty === true;
|
|
4321
4321
|
},
|
|
4322
4322
|
ttyName(fd) {
|
|
4323
|
-
return
|
|
4323
|
+
return json2(call2({ op: "fd-info", fd }, `fd-info ${fd}`))?.name;
|
|
4324
4324
|
},
|
|
4325
4325
|
kind(fd) {
|
|
4326
|
-
return
|
|
4326
|
+
return json2(call2({ op: "fd-info", fd }, `fd-info ${fd}`))?.kind;
|
|
4327
4327
|
},
|
|
4328
4328
|
heldMeta(fd) {
|
|
4329
|
-
return
|
|
4329
|
+
return json2(call2({ op: "fd-info", fd }, `fd-info ${fd}`)).meta;
|
|
4330
4330
|
},
|
|
4331
4331
|
access(fd) {
|
|
4332
|
-
return
|
|
4332
|
+
return json2(call2({ op: "fd-info", fd }, `fd-info ${fd}`)).access;
|
|
4333
4333
|
},
|
|
4334
4334
|
size(fd) {
|
|
4335
|
-
return
|
|
4335
|
+
return json2(call2({ op: "fd-vfs-stat", fd }, `fd-vfs-stat ${fd}`)).size;
|
|
4336
4336
|
},
|
|
4337
4337
|
ttyNames() {
|
|
4338
|
-
return
|
|
4338
|
+
return json2(call2({ op: "fd-tty-names" }, "fd-tty-names"));
|
|
4339
4339
|
},
|
|
4340
4340
|
ttyOwner(name2) {
|
|
4341
|
-
return
|
|
4341
|
+
return json2(call2({ op: "fd-tty-owner", name: name2 }, `fd-tty-owner ${name2}`));
|
|
4342
4342
|
},
|
|
4343
4343
|
openTty(name2) {
|
|
4344
4344
|
const req = name2 === void 0 ? { op: "fd-open-tty" } : { op: "fd-open-tty", name: name2 };
|
|
4345
|
-
return
|
|
4345
|
+
return json2(call2(req, `fd-open-tty ${name2 ?? ""}`));
|
|
4346
4346
|
},
|
|
4347
4347
|
tcgets(fd) {
|
|
4348
|
-
return
|
|
4348
|
+
return json2(call2({ op: "tty-get", fd }, `tty-get ${fd}`));
|
|
4349
4349
|
},
|
|
4350
4350
|
tcsets(fd, termios, flush) {
|
|
4351
4351
|
call2({ op: "tty-set", fd, termios, ...flush ? { flush } : {} }, `tty-set ${fd}`);
|
|
4352
4352
|
},
|
|
4353
4353
|
winsize(fd) {
|
|
4354
|
-
return
|
|
4354
|
+
return json2(call2({ op: "tty-winsz", fd }, `tty-winsz ${fd}`));
|
|
4355
4355
|
},
|
|
4356
4356
|
openPty() {
|
|
4357
|
-
return
|
|
4357
|
+
return json2(call2({ op: "pty-open" }, "pty-open"));
|
|
4358
4358
|
},
|
|
4359
4359
|
openPts(n, noctty) {
|
|
4360
|
-
return
|
|
4360
|
+
return json2(call2({ op: "pty-slave-open", n, noctty }, `pty-slave-open ${n}`));
|
|
4361
4361
|
},
|
|
4362
4362
|
ptyNumbers() {
|
|
4363
|
-
return
|
|
4363
|
+
return json2(call2({ op: "pty-list" }, "pty-list"));
|
|
4364
4364
|
},
|
|
4365
4365
|
procList() {
|
|
4366
|
-
return
|
|
4366
|
+
return json2(call2({ op: "proc-list" }, "proc-list"));
|
|
4367
4367
|
},
|
|
4368
4368
|
mountList() {
|
|
4369
|
-
return
|
|
4369
|
+
return json2(call2({ op: "mount-list" }, "mount-list"));
|
|
4370
4370
|
},
|
|
4371
4371
|
ptyNumber(fd) {
|
|
4372
|
-
return
|
|
4372
|
+
return json2(call2({ op: "pty-number", fd }, `pty-number ${fd}`));
|
|
4373
4373
|
},
|
|
4374
4374
|
ptyLock(fd, lock) {
|
|
4375
4375
|
call2({ op: "pty-lock", fd, lock }, `pty-lock ${fd}`);
|
|
@@ -4493,8 +4493,8 @@ async function runWasmProcess(init, port2, deps = {}) {
|
|
|
4493
4493
|
}
|
|
4494
4494
|
};
|
|
4495
4495
|
const sys = kernelSys(transport);
|
|
4496
|
-
const
|
|
4497
|
-
const say = (fd) => (text) => sys.write(fd,
|
|
4496
|
+
const encoder5 = new TextEncoder();
|
|
4497
|
+
const say = (fd) => (text) => sys.write(fd, encoder5.encode(`${text}
|
|
4498
4498
|
`));
|
|
4499
4499
|
let ready;
|
|
4500
4500
|
let failed5;
|
|
@@ -6134,11 +6134,11 @@ var init_wasi_memory = __esm({
|
|
|
6134
6134
|
return at;
|
|
6135
6135
|
}
|
|
6136
6136
|
putStrings(list, ptrs, buf) {
|
|
6137
|
-
const
|
|
6137
|
+
const encoder5 = new TextEncoder();
|
|
6138
6138
|
const v = this.view();
|
|
6139
6139
|
let at = buf;
|
|
6140
6140
|
list.forEach((s, i) => {
|
|
6141
|
-
const b =
|
|
6141
|
+
const b = encoder5.encode(s);
|
|
6142
6142
|
v.setUint32(ptrs + i * 4, at, true);
|
|
6143
6143
|
this.bytes(at, b.length).set(b);
|
|
6144
6144
|
v.setUint8(at + b.length, 0);
|
|
@@ -6146,12 +6146,12 @@ var init_wasi_memory = __esm({
|
|
|
6146
6146
|
});
|
|
6147
6147
|
}
|
|
6148
6148
|
putSizes(list, countPtr, sizePtr) {
|
|
6149
|
-
const
|
|
6149
|
+
const encoder5 = new TextEncoder();
|
|
6150
6150
|
const v = this.view();
|
|
6151
6151
|
v.setUint32(countPtr, list.length, true);
|
|
6152
6152
|
v.setUint32(
|
|
6153
6153
|
sizePtr,
|
|
6154
|
-
list.reduce((n, s) => n +
|
|
6154
|
+
list.reduce((n, s) => n + encoder5.encode(s).length + 1, 0),
|
|
6155
6155
|
true
|
|
6156
6156
|
);
|
|
6157
6157
|
}
|
|
@@ -10738,14 +10738,32 @@ var init_js_kernel = __esm({
|
|
|
10738
10738
|
const result = await this.call(req);
|
|
10739
10739
|
return result.ok && result.kind === "bytes" ? result.bytes : new Uint8Array(0);
|
|
10740
10740
|
}
|
|
10741
|
-
async blocking(req, signal) {
|
|
10741
|
+
async blocking(req, signal, track) {
|
|
10742
10742
|
for (; ; ) {
|
|
10743
|
-
const id = await this.
|
|
10743
|
+
const id = await this.submit(req, track);
|
|
10744
10744
|
const result = await this.settled(id, signal);
|
|
10745
10745
|
if (result.ok) return result;
|
|
10746
10746
|
if (result.errno !== "EINTR") throw new JsCallError(result.errno, req.op);
|
|
10747
10747
|
}
|
|
10748
10748
|
}
|
|
10749
|
+
acks = [];
|
|
10750
|
+
ack(id) {
|
|
10751
|
+
this.acks.push(id);
|
|
10752
|
+
}
|
|
10753
|
+
async submit(req, track) {
|
|
10754
|
+
const ack = this.acks;
|
|
10755
|
+
this.acks = [];
|
|
10756
|
+
const r = await this.transport.call({
|
|
10757
|
+
op: "async-submit",
|
|
10758
|
+
req,
|
|
10759
|
+
...ack.length > 0 ? { ack } : {}
|
|
10760
|
+
});
|
|
10761
|
+
const id = r.ok && r.kind === "json" ? r.json : void 0;
|
|
10762
|
+
if (id !== void 0) track?.(id);
|
|
10763
|
+
this.deliver();
|
|
10764
|
+
if (id === void 0) throw new JsCallError(r.ok ? "EIO" : r.errno, "async-submit");
|
|
10765
|
+
return id;
|
|
10766
|
+
}
|
|
10749
10767
|
async settled(id, signal) {
|
|
10750
10768
|
for (; ; ) {
|
|
10751
10769
|
const seen = Atomics.load(this.header, SAB_I_ASYNC);
|
|
@@ -10947,6 +10965,165 @@ var init_js_children = __esm({
|
|
|
10947
10965
|
}
|
|
10948
10966
|
});
|
|
10949
10967
|
|
|
10968
|
+
// src/process/js/js-io.ts
|
|
10969
|
+
function typeOf(info) {
|
|
10970
|
+
if (info.meta && "dir" in info.meta) return "directory";
|
|
10971
|
+
if (info.meta && "device" in info.meta) return "device";
|
|
10972
|
+
if (info.tty || info.kind === "tty") return "tty";
|
|
10973
|
+
if (info.kind === "socket") return "socket";
|
|
10974
|
+
return info.kind === "file" ? "file" : "pipe";
|
|
10975
|
+
}
|
|
10976
|
+
function device(info) {
|
|
10977
|
+
return info.meta && "device" in info.meta ? info.meta : void 0;
|
|
10978
|
+
}
|
|
10979
|
+
function readDevice(info, max, random) {
|
|
10980
|
+
if (typeOf(info) === "directory") throw new JsCallError("EISDIR", "read");
|
|
10981
|
+
const dev = device(info);
|
|
10982
|
+
if (!dev) return void 0;
|
|
10983
|
+
if (dev.access === "write") throw new JsCallError("EBADF", "read");
|
|
10984
|
+
if (dev.device === "null") return new Uint8Array(0);
|
|
10985
|
+
const out = new Uint8Array(Math.min(max, CHUNK));
|
|
10986
|
+
if (dev.device === "urandom") random(out);
|
|
10987
|
+
return out;
|
|
10988
|
+
}
|
|
10989
|
+
function writeDevice(info) {
|
|
10990
|
+
if (typeOf(info) === "directory") throw new JsCallError("EISDIR", "write");
|
|
10991
|
+
const dev = device(info);
|
|
10992
|
+
if (!dev) return false;
|
|
10993
|
+
if (dev.access === "read") throw new JsCallError("EBADF", "write");
|
|
10994
|
+
if (dev.device === "full") throw new JsCallError("ENOSPC", "write");
|
|
10995
|
+
return true;
|
|
10996
|
+
}
|
|
10997
|
+
function brokenPipe(err, info) {
|
|
10998
|
+
return err instanceof JsCallError && err.code === "EPIPE" && typeOf(info) !== "socket";
|
|
10999
|
+
}
|
|
11000
|
+
function written(r, fallback) {
|
|
11001
|
+
return r.ok && r.kind === "json" && typeof r.json === "number" ? r.json : fallback;
|
|
11002
|
+
}
|
|
11003
|
+
function joined(parts, length) {
|
|
11004
|
+
if (parts.length === 1) return parts[0];
|
|
11005
|
+
const out = new Uint8Array(length);
|
|
11006
|
+
let at = 0;
|
|
11007
|
+
for (const part of parts) {
|
|
11008
|
+
out.set(part, at);
|
|
11009
|
+
at += part.length;
|
|
11010
|
+
}
|
|
11011
|
+
return out;
|
|
11012
|
+
}
|
|
11013
|
+
function fileWrite(fd, append, offset, body) {
|
|
11014
|
+
return append ? { op: "fd-write", fd, body } : { op: "fd-pwrite", fd, offset, body };
|
|
11015
|
+
}
|
|
11016
|
+
function isExclusive(o) {
|
|
11017
|
+
return o.create === true && o.exclusive === true;
|
|
11018
|
+
}
|
|
11019
|
+
function absent(err) {
|
|
11020
|
+
if (err instanceof JsCallError && err.code === "ENOENT") return void 0;
|
|
11021
|
+
throw err;
|
|
11022
|
+
}
|
|
11023
|
+
function checkOpen(abs, o, existing) {
|
|
11024
|
+
if (existing && isExclusive(o)) throw new JsCallError("EEXIST", abs);
|
|
11025
|
+
if (!existing && !o.create) throw new JsCallError("ENOENT", abs);
|
|
11026
|
+
if (existing?.isDirectory) throw new JsCallError("EISDIR", abs);
|
|
11027
|
+
}
|
|
11028
|
+
function flagsOf(o) {
|
|
11029
|
+
const write2 = o.write || o.append || o.truncate;
|
|
11030
|
+
const access = write2 ? o.read ? O_RDWR6 : O_WRONLY6 : 0;
|
|
11031
|
+
return access | (o.append ? O_APPEND3 : 0);
|
|
11032
|
+
}
|
|
11033
|
+
function openRequest(abs, o) {
|
|
11034
|
+
return {
|
|
11035
|
+
op: "fd-open-vfs",
|
|
11036
|
+
path: abs,
|
|
11037
|
+
flags: flagsOf(o),
|
|
11038
|
+
position: 0,
|
|
11039
|
+
...isExclusive(o) ? { exclusive: true } : o.create ? { create: true } : { existing: true },
|
|
11040
|
+
...o.truncate ? { truncate: true } : {}
|
|
11041
|
+
};
|
|
11042
|
+
}
|
|
11043
|
+
function index2(n, what) {
|
|
11044
|
+
if (!Number.isSafeInteger(n) || n < 0) throw new JsCallError("EINVAL", what);
|
|
11045
|
+
}
|
|
11046
|
+
var CHUNK, MAX_IO, O_WRONLY6, O_RDWR6, O_APPEND3;
|
|
11047
|
+
var init_js_io = __esm({
|
|
11048
|
+
"src/process/js/js-io.ts"() {
|
|
11049
|
+
"use strict";
|
|
11050
|
+
init_js_kernel();
|
|
11051
|
+
CHUNK = 64 * 1024;
|
|
11052
|
+
MAX_IO = 1024 * 1024;
|
|
11053
|
+
O_WRONLY6 = 1;
|
|
11054
|
+
O_RDWR6 = 2;
|
|
11055
|
+
O_APPEND3 = 1024;
|
|
11056
|
+
}
|
|
11057
|
+
});
|
|
11058
|
+
|
|
11059
|
+
// src/process/js/js-exit.ts
|
|
11060
|
+
function json(r) {
|
|
11061
|
+
return r.ok && r.kind === "json" ? r.json : void 0;
|
|
11062
|
+
}
|
|
11063
|
+
function restoreMode(lane, { terminal, fd, termios }) {
|
|
11064
|
+
const open = json(lane({ op: "fd-list" })) ?? [];
|
|
11065
|
+
const on = open.filter((entry) => entry.terminal === terminal);
|
|
11066
|
+
const at = (on.find((entry) => entry.fd === fd) ?? on[0])?.fd;
|
|
11067
|
+
if (at !== void 0) {
|
|
11068
|
+
lane({ op: "tty-set", fd: at, termios });
|
|
11069
|
+
return;
|
|
11070
|
+
}
|
|
11071
|
+
const opened = json(lane({ op: "fd-open-tty", name: terminal }));
|
|
11072
|
+
if (typeof opened !== "number") return;
|
|
11073
|
+
lane({ op: "tty-set", fd: opened, termios });
|
|
11074
|
+
lane({ op: "fd-close", fd: opened });
|
|
11075
|
+
}
|
|
11076
|
+
function writeOut(lane, fd, data) {
|
|
11077
|
+
let at = 0;
|
|
11078
|
+
while (at < data.length) {
|
|
11079
|
+
const body = data.subarray(at, at + MAX_IO);
|
|
11080
|
+
const r = lane({ op: "fd-write", fd, body });
|
|
11081
|
+
if (!r.ok && r.errno === "EINTR") continue;
|
|
11082
|
+
if (!r.ok) return false;
|
|
11083
|
+
const n = written(r, body.length);
|
|
11084
|
+
if (n <= 0) return false;
|
|
11085
|
+
at += n;
|
|
11086
|
+
}
|
|
11087
|
+
return true;
|
|
11088
|
+
}
|
|
11089
|
+
function progress(result, len) {
|
|
11090
|
+
if (!result) return len;
|
|
11091
|
+
if (result.ok) return written(result, len);
|
|
11092
|
+
return result.errno === "EINTR" ? 0 : -1;
|
|
11093
|
+
}
|
|
11094
|
+
function settled(lane, writes) {
|
|
11095
|
+
const inFlight = writes.filter((w) => w.op !== void 0);
|
|
11096
|
+
const out = /* @__PURE__ */ new Map();
|
|
11097
|
+
if (inFlight.length === 0) return out;
|
|
11098
|
+
const r = lane({ op: "async-settle", ids: inFlight.map((w) => w.op) });
|
|
11099
|
+
const results = r.ok && r.kind === "json" ? r.json : [];
|
|
11100
|
+
inFlight.forEach((w, i) => {
|
|
11101
|
+
const result = results[i];
|
|
11102
|
+
out.set(w, progress(result, w.len));
|
|
11103
|
+
});
|
|
11104
|
+
return out;
|
|
11105
|
+
}
|
|
11106
|
+
function exitAtOnce(lane, writes, modes, status2) {
|
|
11107
|
+
const done = settled(lane, writes);
|
|
11108
|
+
const broken = /* @__PURE__ */ new Set();
|
|
11109
|
+
for (const w of writes) {
|
|
11110
|
+
const sent = done.get(w);
|
|
11111
|
+
if (sent === -1) broken.add(w.fd);
|
|
11112
|
+
if (broken.has(w.fd)) continue;
|
|
11113
|
+
if (!writeOut(lane, w.fd, w.data.subarray(w.at + (sent ?? 0)))) broken.add(w.fd);
|
|
11114
|
+
}
|
|
11115
|
+
for (const mode of modes) restoreMode(lane, mode);
|
|
11116
|
+
lane({ op: "proc-exit", status: status2 & 255 });
|
|
11117
|
+
const parked = new Int32Array(new SharedArrayBuffer(4));
|
|
11118
|
+
for (; ; ) Atomics.wait(parked, 0, 0);
|
|
11119
|
+
}
|
|
11120
|
+
var init_js_exit = __esm({
|
|
11121
|
+
"src/process/js/js-exit.ts"() {
|
|
11122
|
+
"use strict";
|
|
11123
|
+
init_js_io();
|
|
11124
|
+
}
|
|
11125
|
+
});
|
|
11126
|
+
|
|
10950
11127
|
// src/process/js/js-fetch.ts
|
|
10951
11128
|
function withoutFragment(url) {
|
|
10952
11129
|
url.hash = "";
|
|
@@ -11179,7 +11356,7 @@ function fetchOp(kernel) {
|
|
|
11179
11356
|
let r;
|
|
11180
11357
|
try {
|
|
11181
11358
|
signal.throwIfAborted();
|
|
11182
|
-
r = await kernel.blocking({ op: "net-read", handle, max:
|
|
11359
|
+
r = await kernel.blocking({ op: "net-read", handle, max: CHUNK2 }, signal);
|
|
11183
11360
|
} catch (err) {
|
|
11184
11361
|
settle();
|
|
11185
11362
|
await close(handle);
|
|
@@ -11268,12 +11445,12 @@ function fetchOp(kernel) {
|
|
|
11268
11445
|
}
|
|
11269
11446
|
};
|
|
11270
11447
|
}
|
|
11271
|
-
var
|
|
11448
|
+
var CHUNK2, MAX_REDIRECTS, NULL_BODY, REDIRECTS, BODY_HEADERS, DECODED, CREDENTIALS, OVER, TOKEN, QUOTABLE, SPACE, BASE64, SLICE;
|
|
11272
11449
|
var init_js_fetch = __esm({
|
|
11273
11450
|
"src/process/js/js-fetch.ts"() {
|
|
11274
11451
|
"use strict";
|
|
11275
11452
|
init_js_kernel();
|
|
11276
|
-
|
|
11453
|
+
CHUNK2 = 64 * 1024;
|
|
11277
11454
|
MAX_REDIRECTS = 20;
|
|
11278
11455
|
NULL_BODY = /* @__PURE__ */ new Set([101, 103, 204, 205, 304]);
|
|
11279
11456
|
REDIRECTS = /* @__PURE__ */ new Set([301, 302, 303, 307, 308]);
|
|
@@ -11295,97 +11472,6 @@ var init_js_fetch = __esm({
|
|
|
11295
11472
|
}
|
|
11296
11473
|
});
|
|
11297
11474
|
|
|
11298
|
-
// src/process/js/js-io.ts
|
|
11299
|
-
function typeOf(info) {
|
|
11300
|
-
if (info.meta && "dir" in info.meta) return "directory";
|
|
11301
|
-
if (info.meta && "device" in info.meta) return "device";
|
|
11302
|
-
if (info.tty || info.kind === "tty") return "tty";
|
|
11303
|
-
if (info.kind === "socket") return "socket";
|
|
11304
|
-
return info.kind === "file" ? "file" : "pipe";
|
|
11305
|
-
}
|
|
11306
|
-
function device(info) {
|
|
11307
|
-
return info.meta && "device" in info.meta ? info.meta : void 0;
|
|
11308
|
-
}
|
|
11309
|
-
function readDevice(info, max, random) {
|
|
11310
|
-
if (typeOf(info) === "directory") throw new JsCallError("EISDIR", "read");
|
|
11311
|
-
const dev = device(info);
|
|
11312
|
-
if (!dev) return void 0;
|
|
11313
|
-
if (dev.access === "write") throw new JsCallError("EBADF", "read");
|
|
11314
|
-
if (dev.device === "null") return new Uint8Array(0);
|
|
11315
|
-
const out = new Uint8Array(Math.min(max, CHUNK2));
|
|
11316
|
-
if (dev.device === "urandom") random(out);
|
|
11317
|
-
return out;
|
|
11318
|
-
}
|
|
11319
|
-
function writeDevice(info) {
|
|
11320
|
-
if (typeOf(info) === "directory") throw new JsCallError("EISDIR", "write");
|
|
11321
|
-
const dev = device(info);
|
|
11322
|
-
if (!dev) return false;
|
|
11323
|
-
if (dev.access === "read") throw new JsCallError("EBADF", "write");
|
|
11324
|
-
if (dev.device === "full") throw new JsCallError("ENOSPC", "write");
|
|
11325
|
-
return true;
|
|
11326
|
-
}
|
|
11327
|
-
function brokenPipe(err, info) {
|
|
11328
|
-
return err instanceof JsCallError && err.code === "EPIPE" && typeOf(info) !== "socket";
|
|
11329
|
-
}
|
|
11330
|
-
function written(r, fallback) {
|
|
11331
|
-
return r.ok && r.kind === "json" && typeof r.json === "number" ? r.json : fallback;
|
|
11332
|
-
}
|
|
11333
|
-
function joined(parts, length) {
|
|
11334
|
-
if (parts.length === 1) return parts[0];
|
|
11335
|
-
const out = new Uint8Array(length);
|
|
11336
|
-
let at = 0;
|
|
11337
|
-
for (const part of parts) {
|
|
11338
|
-
out.set(part, at);
|
|
11339
|
-
at += part.length;
|
|
11340
|
-
}
|
|
11341
|
-
return out;
|
|
11342
|
-
}
|
|
11343
|
-
function fileWrite(fd, append, offset, body) {
|
|
11344
|
-
return append ? { op: "fd-write", fd, body } : { op: "fd-pwrite", fd, offset, body };
|
|
11345
|
-
}
|
|
11346
|
-
function isExclusive(o) {
|
|
11347
|
-
return o.create === true && o.exclusive === true;
|
|
11348
|
-
}
|
|
11349
|
-
function absent(err) {
|
|
11350
|
-
if (err instanceof JsCallError && err.code === "ENOENT") return void 0;
|
|
11351
|
-
throw err;
|
|
11352
|
-
}
|
|
11353
|
-
function checkOpen(abs, o, existing) {
|
|
11354
|
-
if (existing && isExclusive(o)) throw new JsCallError("EEXIST", abs);
|
|
11355
|
-
if (!existing && !o.create) throw new JsCallError("ENOENT", abs);
|
|
11356
|
-
if (existing?.isDirectory) throw new JsCallError("EISDIR", abs);
|
|
11357
|
-
}
|
|
11358
|
-
function flagsOf(o) {
|
|
11359
|
-
const write2 = o.write || o.append || o.truncate;
|
|
11360
|
-
const access = write2 ? o.read ? O_RDWR6 : O_WRONLY6 : 0;
|
|
11361
|
-
return access | (o.append ? O_APPEND3 : 0);
|
|
11362
|
-
}
|
|
11363
|
-
function openRequest(abs, o) {
|
|
11364
|
-
return {
|
|
11365
|
-
op: "fd-open-vfs",
|
|
11366
|
-
path: abs,
|
|
11367
|
-
flags: flagsOf(o),
|
|
11368
|
-
position: 0,
|
|
11369
|
-
...isExclusive(o) ? { exclusive: true } : o.create ? { create: true } : { existing: true },
|
|
11370
|
-
...o.truncate ? { truncate: true } : {}
|
|
11371
|
-
};
|
|
11372
|
-
}
|
|
11373
|
-
function index2(n, what) {
|
|
11374
|
-
if (!Number.isSafeInteger(n) || n < 0) throw new JsCallError("EINVAL", what);
|
|
11375
|
-
}
|
|
11376
|
-
var CHUNK2, MAX_IO, O_WRONLY6, O_RDWR6, O_APPEND3;
|
|
11377
|
-
var init_js_io = __esm({
|
|
11378
|
-
"src/process/js/js-io.ts"() {
|
|
11379
|
-
"use strict";
|
|
11380
|
-
init_js_kernel();
|
|
11381
|
-
CHUNK2 = 64 * 1024;
|
|
11382
|
-
MAX_IO = 1024 * 1024;
|
|
11383
|
-
O_WRONLY6 = 1;
|
|
11384
|
-
O_RDWR6 = 2;
|
|
11385
|
-
O_APPEND3 = 1024;
|
|
11386
|
-
}
|
|
11387
|
-
});
|
|
11388
|
-
|
|
11389
11475
|
// src/process/js/js-net.ts
|
|
11390
11476
|
function errnoName(errno2) {
|
|
11391
11477
|
const found = Object.entries(E).find(([, n]) => n === errno2);
|
|
@@ -11527,6 +11613,67 @@ var init_js_net = __esm({
|
|
|
11527
11613
|
}
|
|
11528
11614
|
});
|
|
11529
11615
|
|
|
11616
|
+
// src/process/js/js-run.ts
|
|
11617
|
+
function stdioOf(how) {
|
|
11618
|
+
if (how === void 0) return "pipe";
|
|
11619
|
+
if (!STDIO3.has(how)) throw new JsCallError("EINVAL", "run");
|
|
11620
|
+
return how;
|
|
11621
|
+
}
|
|
11622
|
+
function limit(value2) {
|
|
11623
|
+
if (value2 === void 0 || value2 === Number.POSITIVE_INFINITY) return value2;
|
|
11624
|
+
if (!(value2 >= 0)) throw new JsCallError("EINVAL", "run");
|
|
11625
|
+
return value2;
|
|
11626
|
+
}
|
|
11627
|
+
function decodeRun(bytes, stdout, stderr) {
|
|
11628
|
+
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
11629
|
+
const size = view.getUint32(0, true);
|
|
11630
|
+
const outcome = JSON.parse(new TextDecoder().decode(bytes.subarray(4, 4 + size)));
|
|
11631
|
+
const out = bytes.slice(4 + size, 4 + size + outcome.out);
|
|
11632
|
+
const err = bytes.slice(4 + size + outcome.out, 4 + size + outcome.out + outcome.err);
|
|
11633
|
+
return {
|
|
11634
|
+
pid: outcome.pid,
|
|
11635
|
+
status: outcome.status,
|
|
11636
|
+
...outcome.signal !== void 0 ? { signal: outcome.signal } : {},
|
|
11637
|
+
...stdout === "pipe" ? { stdout: out } : {},
|
|
11638
|
+
...stderr === "pipe" ? { stderr: err } : {},
|
|
11639
|
+
...outcome.error ? { error: outcome.error } : {}
|
|
11640
|
+
};
|
|
11641
|
+
}
|
|
11642
|
+
function runSync(kernel, d, o) {
|
|
11643
|
+
const [file] = o.argv;
|
|
11644
|
+
if (file === void 0) throw new JsCallError("EINVAL", "run");
|
|
11645
|
+
const stdout = stdioOf(o.stdout);
|
|
11646
|
+
const stderr = stdioOf(o.stderr);
|
|
11647
|
+
const input = typeof o.input === "string" ? encoder2.encode(o.input) : o.input;
|
|
11648
|
+
const maxBuffer = limit(o.maxBuffer);
|
|
11649
|
+
const timeout = limit(o.timeout);
|
|
11650
|
+
const bytes = kernel.bytes({
|
|
11651
|
+
op: "proc-run",
|
|
11652
|
+
file,
|
|
11653
|
+
argv: [...o.argv],
|
|
11654
|
+
env: { ...o.env ?? d.env },
|
|
11655
|
+
cwd: o.cwd === void 0 ? d.cwd : d.resolve(o.cwd),
|
|
11656
|
+
stdin: stdioOf(o.stdin),
|
|
11657
|
+
...input ? { input } : {},
|
|
11658
|
+
stdout,
|
|
11659
|
+
stderr,
|
|
11660
|
+
...maxBuffer !== void 0 && maxBuffer !== Number.POSITIVE_INFINITY ? { maxBuffer } : {},
|
|
11661
|
+
...maxBuffer === Number.POSITIVE_INFINITY ? { maxBuffer: Number.MAX_SAFE_INTEGER } : {},
|
|
11662
|
+
...timeout !== void 0 && timeout !== Number.POSITIVE_INFINITY ? { timeoutMs: timeout } : {},
|
|
11663
|
+
killSignal: d.signal(o.killSignal ?? "SIGTERM")
|
|
11664
|
+
});
|
|
11665
|
+
return decodeRun(bytes, stdout, stderr);
|
|
11666
|
+
}
|
|
11667
|
+
var encoder2, STDIO3;
|
|
11668
|
+
var init_js_run = __esm({
|
|
11669
|
+
"src/process/js/js-run.ts"() {
|
|
11670
|
+
"use strict";
|
|
11671
|
+
init_js_kernel();
|
|
11672
|
+
encoder2 = new TextEncoder();
|
|
11673
|
+
STDIO3 = /* @__PURE__ */ new Set(["pipe", "ignore", "inherit"]);
|
|
11674
|
+
}
|
|
11675
|
+
});
|
|
11676
|
+
|
|
11530
11677
|
// src/process/js/js-sync.ts
|
|
11531
11678
|
function laneOf(lane) {
|
|
11532
11679
|
if (!lane) return () => ({ ok: false, errno: "ENOSYS", message: "no sync lane" });
|
|
@@ -11542,7 +11689,7 @@ function syncOps(kernel, shared) {
|
|
|
11542
11689
|
infos.set(fd, got);
|
|
11543
11690
|
return got;
|
|
11544
11691
|
};
|
|
11545
|
-
const read2 = (fd, max =
|
|
11692
|
+
const read2 = (fd, max = CHUNK) => {
|
|
11546
11693
|
index2(max, "read");
|
|
11547
11694
|
const emulated = readDevice(info(fd), max, shared.random);
|
|
11548
11695
|
if (emulated) return emulated;
|
|
@@ -11550,7 +11697,7 @@ function syncOps(kernel, shared) {
|
|
|
11550
11697
|
return r.ok && r.kind === "bytes" ? r.bytes : new Uint8Array(0);
|
|
11551
11698
|
};
|
|
11552
11699
|
const write2 = (fd, data) => {
|
|
11553
|
-
const bytes = typeof data === "string" ?
|
|
11700
|
+
const bytes = typeof data === "string" ? encoder3.encode(data) : data;
|
|
11554
11701
|
const i = info(fd);
|
|
11555
11702
|
if (writeDevice(i)) return;
|
|
11556
11703
|
let at = 0;
|
|
@@ -11693,14 +11840,14 @@ function syncPathOps(kernel, resolve, statOf, open) {
|
|
|
11693
11840
|
writeFile(path, data) {
|
|
11694
11841
|
const file = open(path, { write: true, create: true, truncate: true });
|
|
11695
11842
|
try {
|
|
11696
|
-
file.write(0, typeof data === "string" ?
|
|
11843
|
+
file.write(0, typeof data === "string" ? encoder3.encode(data) : data);
|
|
11697
11844
|
} finally {
|
|
11698
11845
|
file.close();
|
|
11699
11846
|
}
|
|
11700
11847
|
}
|
|
11701
11848
|
};
|
|
11702
11849
|
}
|
|
11703
|
-
var
|
|
11850
|
+
var encoder3, JsSyncKernel;
|
|
11704
11851
|
var init_js_sync = __esm({
|
|
11705
11852
|
"src/process/js/js-sync.ts"() {
|
|
11706
11853
|
"use strict";
|
|
@@ -11709,7 +11856,7 @@ var init_js_sync = __esm({
|
|
|
11709
11856
|
init_sync_sab_bridge();
|
|
11710
11857
|
init_js_io();
|
|
11711
11858
|
init_js_kernel();
|
|
11712
|
-
|
|
11859
|
+
encoder3 = new TextEncoder();
|
|
11713
11860
|
JsSyncKernel = class {
|
|
11714
11861
|
lane;
|
|
11715
11862
|
kernel;
|
|
@@ -11817,7 +11964,8 @@ function ttyOps(kernel) {
|
|
|
11817
11964
|
await back.catch(() => void 0);
|
|
11818
11965
|
}
|
|
11819
11966
|
};
|
|
11820
|
-
|
|
11967
|
+
const modes = () => [...saved].reverse().map(([terminal, { fd, termios }]) => ({ terminal, fd, termios }));
|
|
11968
|
+
return { tty, restore, modes };
|
|
11821
11969
|
}
|
|
11822
11970
|
var BRKINT, INPCK, ISTRIP, ICRNL, IXON, ONLCR, CS8, ISIG, ICANON2, ECHO2, IEXTEN, VTIME, VMIN;
|
|
11823
11971
|
var init_js_tty = __esm({
|
|
@@ -11908,14 +12056,14 @@ function websocketOp(kernel) {
|
|
|
11908
12056
|
finish();
|
|
11909
12057
|
};
|
|
11910
12058
|
signal.addEventListener("abort", onAbort, { once: true });
|
|
11911
|
-
let
|
|
12059
|
+
let settled2 = false;
|
|
11912
12060
|
let readDone = false;
|
|
11913
12061
|
const release = () => {
|
|
11914
|
-
if (!
|
|
12062
|
+
if (!settled2 || !readDone || freed) return;
|
|
11915
12063
|
finish();
|
|
11916
12064
|
};
|
|
11917
12065
|
kernel.blocking({ op: "net-ws-wait", handle }, stop.signal).then((r) => {
|
|
11918
|
-
|
|
12066
|
+
settled2 = true;
|
|
11919
12067
|
settle(r.json);
|
|
11920
12068
|
release();
|
|
11921
12069
|
}).catch(lose);
|
|
@@ -11963,7 +12111,7 @@ function websocketOp(kernel) {
|
|
|
11963
12111
|
async write(chunk, controller) {
|
|
11964
12112
|
stop.signal.throwIfAborted();
|
|
11965
12113
|
const send = async (body) => {
|
|
11966
|
-
if (
|
|
12114
|
+
if (settled2) throw new JsCallError("EPIPE", "the websocket is closed");
|
|
11967
12115
|
return await kernel.json({ op: "net-ws-send", handle, ...body });
|
|
11968
12116
|
};
|
|
11969
12117
|
let buffered = await send(typeof chunk === "string" ? { text: chunk } : { body: chunk });
|
|
@@ -12023,6 +12171,41 @@ function resolvePath(cwd, path) {
|
|
|
12023
12171
|
}
|
|
12024
12172
|
return `/${parts.join("/")}`;
|
|
12025
12173
|
}
|
|
12174
|
+
function writer(kernel, info, pid) {
|
|
12175
|
+
const writes = /* @__PURE__ */ new Set();
|
|
12176
|
+
const sendAll = async (fd, data, i, w, signal) => {
|
|
12177
|
+
while (w.at < data.length) {
|
|
12178
|
+
const body = data.subarray(w.at, w.at + MAX_IO);
|
|
12179
|
+
w.len = body.length;
|
|
12180
|
+
try {
|
|
12181
|
+
w.at += signal ? await sendSome(kernel, fd, body, signal) : written(
|
|
12182
|
+
await kernel.blocking({ op: "fd-write", fd, body }, void 0, (id) => {
|
|
12183
|
+
if (w.op !== void 0) kernel.ack(w.op);
|
|
12184
|
+
w.op = id;
|
|
12185
|
+
}),
|
|
12186
|
+
body.length
|
|
12187
|
+
);
|
|
12188
|
+
if (w.op !== void 0) kernel.ack(w.op);
|
|
12189
|
+
w.op = void 0;
|
|
12190
|
+
} catch (err) {
|
|
12191
|
+
if (brokenPipe(err, i)) await kernel.call({ op: "proc-kill", pid, sig: SIG.PIPE });
|
|
12192
|
+
throw err;
|
|
12193
|
+
}
|
|
12194
|
+
}
|
|
12195
|
+
};
|
|
12196
|
+
const writeAll = async (fd, data, signal) => {
|
|
12197
|
+
const w = { fd, data, at: 0, len: 0 };
|
|
12198
|
+
if (!signal) writes.add(w);
|
|
12199
|
+
try {
|
|
12200
|
+
const i = await info(fd);
|
|
12201
|
+
if (writeDevice(i)) return;
|
|
12202
|
+
await sendAll(fd, data, i, w, signal);
|
|
12203
|
+
} finally {
|
|
12204
|
+
writes.delete(w);
|
|
12205
|
+
}
|
|
12206
|
+
};
|
|
12207
|
+
return { writes, writeAll };
|
|
12208
|
+
}
|
|
12026
12209
|
function createContext(o) {
|
|
12027
12210
|
const { kernel } = o;
|
|
12028
12211
|
const infos = /* @__PURE__ */ new Map();
|
|
@@ -12047,36 +12230,23 @@ function createContext(o) {
|
|
|
12047
12230
|
infos.set(fd, got);
|
|
12048
12231
|
return got;
|
|
12049
12232
|
};
|
|
12050
|
-
const read2 = async (fd, max =
|
|
12233
|
+
const read2 = async (fd, max = CHUNK, signal) => {
|
|
12051
12234
|
index2(max, "read");
|
|
12052
12235
|
const emulated = readDevice(await info(fd), max, random);
|
|
12053
12236
|
if (emulated) return emulated;
|
|
12054
12237
|
return readPipe(kernel, fd, Math.min(max, MAX_IO), signal);
|
|
12055
12238
|
};
|
|
12056
|
-
const writeAll =
|
|
12057
|
-
const i = await info(fd);
|
|
12058
|
-
if (writeDevice(i)) return;
|
|
12059
|
-
let at = 0;
|
|
12060
|
-
while (at < data.length) {
|
|
12061
|
-
const body = data.subarray(at, at + MAX_IO);
|
|
12062
|
-
try {
|
|
12063
|
-
at += signal ? await sendSome(kernel, fd, body, signal) : written(await kernel.blocking({ op: "fd-write", fd, body }), body.length);
|
|
12064
|
-
} catch (err) {
|
|
12065
|
-
if (brokenPipe(err, i)) await kernel.call({ op: "proc-kill", pid: o.pid, sig: SIG.PIPE });
|
|
12066
|
-
throw err;
|
|
12067
|
-
}
|
|
12068
|
-
}
|
|
12069
|
-
};
|
|
12239
|
+
const { writes, writeAll } = writer(kernel, info, o.pid);
|
|
12070
12240
|
const write2 = (fd, data) => {
|
|
12071
|
-
const bytes = typeof data === "string" ?
|
|
12241
|
+
const bytes = typeof data === "string" ? encoder4.encode(data) : data;
|
|
12072
12242
|
let settle;
|
|
12073
|
-
const
|
|
12074
|
-
pending.add(
|
|
12243
|
+
const settled2 = new Promise((resolve2) => settle = resolve2);
|
|
12244
|
+
pending.add(settled2);
|
|
12075
12245
|
return (async () => {
|
|
12076
12246
|
try {
|
|
12077
12247
|
await writeAll(fd, bytes);
|
|
12078
12248
|
} finally {
|
|
12079
|
-
pending.delete(
|
|
12249
|
+
pending.delete(settled2);
|
|
12080
12250
|
settle();
|
|
12081
12251
|
}
|
|
12082
12252
|
})();
|
|
@@ -12109,14 +12279,17 @@ function createContext(o) {
|
|
|
12109
12279
|
return handle.file;
|
|
12110
12280
|
};
|
|
12111
12281
|
const fs = pathOps(kernel, resolve, statOf, open);
|
|
12112
|
-
const
|
|
12113
|
-
|
|
12114
|
-
resolve,
|
|
12115
|
-
random,
|
|
12116
|
-
infos,
|
|
12117
|
-
handles
|
|
12118
|
-
});
|
|
12282
|
+
const lane = o.lane ?? laneOf(void 0);
|
|
12283
|
+
const syncKernel = new JsSyncKernel(lane, kernel, unwind);
|
|
12119
12284
|
const terminal = ttyOps(kernel);
|
|
12285
|
+
const sync = {
|
|
12286
|
+
...syncOps(syncKernel, { pid: o.pid, resolve, random, infos, handles }),
|
|
12287
|
+
run: (options) => runSync(syncKernel, { env: o.env, cwd: o.cwd, resolve, signal: signalNumber }, options),
|
|
12288
|
+
exit: (status2 = 0) => {
|
|
12289
|
+
exiting ??= status2 & 255;
|
|
12290
|
+
return exitAtOnce(lane, [...writes], terminal.modes(), exiting);
|
|
12291
|
+
}
|
|
12292
|
+
};
|
|
12120
12293
|
const io = { read: read2, send: writeAll, close: (fd) => ctx.close(fd) };
|
|
12121
12294
|
const children = childOps(kernel, io, { env: o.env, cwd: o.cwd, signal: signalNumber });
|
|
12122
12295
|
const strays = o.strays ?? { exception: /* @__PURE__ */ new Set(), rejection: /* @__PURE__ */ new Set() };
|
|
@@ -12290,24 +12463,26 @@ function pathOps(kernel, resolve, statOf, open) {
|
|
|
12290
12463
|
async writeFile(path, data) {
|
|
12291
12464
|
const file = await open(path, { write: true, create: true, truncate: true });
|
|
12292
12465
|
try {
|
|
12293
|
-
await file.write(0, typeof data === "string" ?
|
|
12466
|
+
await file.write(0, typeof data === "string" ? encoder4.encode(data) : data);
|
|
12294
12467
|
} finally {
|
|
12295
12468
|
await file.close();
|
|
12296
12469
|
}
|
|
12297
12470
|
}
|
|
12298
12471
|
};
|
|
12299
12472
|
}
|
|
12300
|
-
var JsExit,
|
|
12473
|
+
var JsExit, encoder4;
|
|
12301
12474
|
var init_js_context = __esm({
|
|
12302
12475
|
"src/process/js/js-context.ts"() {
|
|
12303
12476
|
"use strict";
|
|
12304
12477
|
init_signals();
|
|
12305
12478
|
init_sync_fs_wire();
|
|
12306
12479
|
init_js_children();
|
|
12480
|
+
init_js_exit();
|
|
12307
12481
|
init_js_fetch();
|
|
12308
12482
|
init_js_io();
|
|
12309
12483
|
init_js_kernel();
|
|
12310
12484
|
init_js_net();
|
|
12485
|
+
init_js_run();
|
|
12311
12486
|
init_js_sync();
|
|
12312
12487
|
init_js_tty();
|
|
12313
12488
|
init_js_websocket();
|
|
@@ -12319,7 +12494,7 @@ var init_js_context = __esm({
|
|
|
12319
12494
|
this.status = status2;
|
|
12320
12495
|
}
|
|
12321
12496
|
};
|
|
12322
|
-
|
|
12497
|
+
encoder4 = new TextEncoder();
|
|
12323
12498
|
}
|
|
12324
12499
|
});
|
|
12325
12500
|
|