@ai-ecoverse/slicc-kernel 1.8.6 → 1.8.8

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.
@@ -1691,11 +1691,24 @@ function persistsItself(stream) {
1691
1691
  const type = stream.node.mount?.type;
1692
1692
  return typeof type?.syncfs === "function";
1693
1693
  }
1694
- function syncFsync(imports, fs) {
1694
+ function namespaces(imports) {
1695
+ const seen = /* @__PURE__ */ new Set();
1695
1696
  for (const namespace of Object.values(imports)) {
1696
- const original = namespace?.fd_sync;
1697
- if (typeof original !== "function" || !original.isAsync) continue;
1698
- namespace.fd_sync = (fd) => {
1697
+ if (namespace && typeof namespace === "object") seen.add(namespace);
1698
+ }
1699
+ return [...seen];
1700
+ }
1701
+ function keyOf(namespace, name, glue) {
1702
+ const own = glue?.[name];
1703
+ const found = typeof own === "function" ? Object.keys(namespace).find((k) => namespace[k] === own) : void 0;
1704
+ return found ?? (typeof namespace[name] === "function" ? name : void 0);
1705
+ }
1706
+ function syncFsync(imports, fs, glue) {
1707
+ for (const namespace of namespaces(imports)) {
1708
+ const key = keyOf(namespace, "fd_sync", glue);
1709
+ const original = key === void 0 ? void 0 : namespace[key];
1710
+ if (key === void 0 || !original?.isAsync) continue;
1711
+ namespace[key] = (fd) => {
1699
1712
  const stream = fs()?.getStream(fd);
1700
1713
  if (!stream) return EBADF;
1701
1714
  if (persistsItself(stream)) return original(fd);
@@ -1751,14 +1764,14 @@ function positioned(original, write, deps) {
1751
1764
  };
1752
1765
  }
1753
1766
  function positionalIo(imports, deps) {
1754
- for (const namespace of Object.values(imports)) {
1767
+ for (const namespace of namespaces(imports)) {
1755
1768
  for (const [name, write] of [
1756
1769
  ["fd_pread", false],
1757
1770
  ["fd_pwrite", true]
1758
1771
  ]) {
1759
- const original = namespace?.[name];
1760
- if (typeof original === "function") {
1761
- namespace[name] = positioned(original, write, deps);
1772
+ const key = keyOf(namespace, name, deps.glue);
1773
+ if (key !== void 0) {
1774
+ namespace[key] = positioned(namespace[key], write, deps);
1762
1775
  }
1763
1776
  }
1764
1777
  }
@@ -2546,8 +2559,10 @@ async function runWasmProcess(init, port, deps = {}) {
2546
2559
  }
2547
2560
  }
2548
2561
  });
2549
- syncFsync(imports, () => ownValue(module, "FS"));
2562
+ const glue = ownValue(module, "sliccFdImports");
2563
+ syncFsync(imports, () => ownValue(module, "FS"), glue);
2550
2564
  positionalIo(imports, {
2565
+ glue,
2551
2566
  fs: () => ownValue(module, "FS"),
2552
2567
  sys,
2553
2568
  memory: () => memory
@@ -2687,6 +2702,11 @@ var init_process_runtime = __esm({
2687
2702
  " ioctl: typeof ___syscall_ioctl === 'function' ? ___syscall_ioctl : undefined,",
2688
2703
  " setitimer: typeof __setitimer_js === 'function' ? __setitimer_js : undefined,",
2689
2704
  "};",
2705
+ "Module.sliccFdImports ??= {",
2706
+ " fd_sync: typeof _fd_sync === 'function' ? _fd_sync : undefined,",
2707
+ " fd_pread: typeof _fd_pread === 'function' ? _fd_pread : undefined,",
2708
+ " fd_pwrite: typeof _fd_pwrite === 'function' ? _fd_pwrite : undefined,",
2709
+ "};",
2690
2710
  "const __sliccUp = () =>",
2691
2711
  " (typeof runtimeInitialized === 'undefined' || runtimeInitialized) &&",
2692
2712
  " !(typeof runtimeExited !== 'undefined' && runtimeExited) &&",