@ai-ecoverse/slicc-kernel 1.164.1 → 1.164.2

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 CHANGED
@@ -427,9 +427,9 @@ The module's default export (or its `main` export) is called with a context and
427
427
  - **What `fn` gets:** a fresh array of V8 CallSites holding only the program's own frames (its modules, `data:` imports, `sync.runScript` scripts and code they `eval`), `node:` frames and native frames. Kernel frames are dropped by script identity, so a script named like a kernel file doesn't let them through, and so are host files. A program's strict frames give `getFunction()` and `getThis()` as `undefined`.
428
428
  - **Fallback:** if `fn` throws or returns a non-string, or an error is formatted while `fn` runs, the default stack is used.
429
429
  - **How it works:** process workers start with `--expose-internals`, so the worker can install the formatter before the lockdown. Host flags a worker refuses are dropped. If the worker still can't start with the flag, the method is absent. Every `internal/*` and `node:internal/*` module stays refused to programs, as do `node:module` and `node:worker_threads`.
430
- - `sync.errorSource(error)` (#1610, slicc-jsh#1082) is Node only, so check it with `typeof ctx.sync.errorSource === 'function'`. It gives `{ sourceLine, lineNumber, startColumn }` (null-prototype and frozen), the source line Node prints over an uncaught error, for an error V8 raised in the program's own code. That includes a direct `eval` of a value that isn't a string literal (`const s = 'null.d'; eval(s)` gives `null.d` and line 1) and a `sync.runScript` script.
430
+ - `sync.errorSource(error)` (#1610, slicc-jsh#1082) is Node only, so check it with `typeof ctx.sync.errorSource === 'function'`. It gives `{ sourceLine, lineNumber, startColumn }` (null-prototype and frozen), the source line Node prints over an uncaught error, for an error in the program's own code. The kernel takes V8's position while the stack is formatted (#1633), so this also works after `.stack` was read, and for a call of a non-function, a ReferenceError, a TDZ error or a thrown `Error`. That includes a direct `eval` of a value that isn't a string literal (`const s = 'null.d'; eval(s)` gives `null.d` and line 1) and a `sync.runScript` script.
431
431
  - **Only the program's own code:** it answers only when the error's top frame is a program frame and the position V8 kept is in that same script and line.
432
- - **`undefined` cases:** kernel-made errors; values that aren't native errors; an error V8 kept no position for (a `new Error()` the program constructs); a script that borrows the kernel worker's name; and an error an own `Error.prepareStackTrace` formats.
432
+ - **`undefined` cases:** kernel-made errors; values that aren't native errors; a script that borrows the kernel worker's name; and an error an own `Error.prepareStackTrace` formats.
433
433
  - **How it works:** it reads V8's message through Node's internal errors binding, which the worker loads at start-up through the same `--expose-internals` as `setStackFormatter`. It prints no warning and needs no inspector.
434
434
  - **Kernel frames in a program's stacks** (#1583): on the Node entry, the process worker's bundle names itself `slicc-kernel:/node-process-worker.js` (a `sourceURL`), so the kernel's own frames in an error a program sees (its own errors, a failed `ctx` call, `runScript`) show that name and not the host directory the kernel is installed in. The same holds in `CallSite.toString()` and `getScriptNameOrSourceURL()`, which a program's own `Error.prepareStackTrace` gets; `getFileName()` still returns the bundle's file URL. Line and column numbers are unchanged, so they still point into `dist/node-process-worker.js`. Don't run an embedder with `--enable-source-maps` if program-visible paths matter: Node then maps the kernel's frames back to the absolute paths of its sources. In a browser the frames keep the bundle's URL, because Chrome ignores `sourceURL` in a module worker loaded by URL.
435
435
  - `module` (#1598, slicc-jsh#566) is a frozen `{ path }` with the command module's own path in the kernel's file system (e.g. `/usr/lib/node_modules/jsh/dist/jsh.mjs`), so a program can read its package's other files through `ctx.fs` on first use. It's the path the kernel found the package under, with symlinks left as they are (a pnpm-style `node_modules/<name>` link stays in it), and reads the same files through `ctx.fs`. It's a kernel path, never a host one, and a thread gets the same. It's absent for the kernel's built-in programs (`sudo`, `crontab`) and for a program run from inline source with no file.
@@ -8444,7 +8444,7 @@ function satisfies(version, range2) {
8444
8444
  }
8445
8445
 
8446
8446
  // src/version.ts
8447
- var KERNEL_VERSION = true ? "1.164.1" : "0.0.0-dev";
8447
+ var KERNEL_VERSION = true ? "1.164.2" : "0.0.0-dev";
8448
8448
  var OS_RELEASE = "6.0.0-slicc";
8449
8449
  function procVersion() {
8450
8450
  return `Linux version ${OS_RELEASE} (slicc-kernel ${KERNEL_VERSION}) #1 SMP PREEMPT_DYNAMIC
@@ -1456,6 +1456,8 @@ var setAdd = Set.prototype.add;
1456
1456
  var mapGet = WeakMap.prototype.get;
1457
1457
  var mapSet = WeakMap.prototype.set;
1458
1458
  var isNativeError = types.isNativeError;
1459
+ var freeze = Object.freeze;
1460
+ var blank = Object.create;
1459
1461
  function internals() {
1460
1462
  try {
1461
1463
  const load = createRequire(import.meta.url);
@@ -1551,11 +1553,20 @@ function keptFrames(trace) {
1551
1553
  }
1552
1554
  var formatter = null;
1553
1555
  var formatting = false;
1554
- var tops = /* @__PURE__ */ new WeakMap();
1555
- function stackDispatcher(fallback) {
1556
+ var seen = /* @__PURE__ */ new WeakMap();
1557
+ function positionsAt(positions, error, site) {
1558
+ if (positions === void 0 || !keptFrame(site)) return void 0;
1559
+ try {
1560
+ return positions(error);
1561
+ } catch {
1562
+ return void 0;
1563
+ }
1564
+ }
1565
+ function stackDispatcher(fallback, positions) {
1556
1566
  return (error, trace) => {
1557
1567
  if (typeof error === "object" && error !== null && trace.length > 0) {
1558
- apply(mapSet, tops, [error, trace[0]]);
1568
+ const site = trace[0];
1569
+ apply(mapSet, seen, [error, { site, at: positionsAt(positions, error, site) }]);
1559
1570
  }
1560
1571
  const fn = formatter;
1561
1572
  if (fn === null || formatting) return apply(fallback, void 0, [error, trace]);
@@ -1571,8 +1582,29 @@ function stackDispatcher(fallback) {
1571
1582
  };
1572
1583
  }
1573
1584
  var found = internals();
1574
- if (found) found.setInternalPrepareStackTrace(stackDispatcher(found.fallback));
1575
- var positions = found?.positions;
1585
+ if (found) found.setInternalPrepareStackTrace(stackDispatcher(found.fallback, found.positions));
1586
+ function errorSourceOf(error) {
1587
+ if (typeof error !== "object" || error === null || !isNativeError(error)) return void 0;
1588
+ try {
1589
+ void error.stack;
1590
+ } catch {
1591
+ return void 0;
1592
+ }
1593
+ const got = apply(mapGet, seen, [error]);
1594
+ if (got === void 0 || !keptFrame(got.site)) return void 0;
1595
+ const { site, at } = got;
1596
+ if (!at || typeof at.sourceLine !== "string" || typeof at.lineNumber !== "number")
1597
+ return void 0;
1598
+ if (apply(setHas, ownNames, [at.scriptResourceName]) === true) return void 0;
1599
+ const file = apply(isEval, site, []) === true ? void 0 : apply(fileOf, site, []);
1600
+ if (at.scriptResourceName !== file || apply(lineOf, site, []) !== at.lineNumber) return void 0;
1601
+ const out = blank(null);
1602
+ out.sourceLine = at.sourceLine;
1603
+ out.lineNumber = at.lineNumber;
1604
+ out.startColumn = typeof at.startColumn === "number" ? at.startColumn : 0;
1605
+ return freeze(out);
1606
+ }
1607
+ var nodeErrorSource = found?.positions ? errorSourceOf : void 0;
1576
1608
 
1577
1609
  // src/process/js/lockdown.ts
1578
1610
  var BLOCKED_GLOBALS = [