Files
scriptc/tests/fixtures/node-island/exit-tls.mjs
T
Malte UblandClaude Opus 5.5 55a69232b7 Exit cleanly with Node loaded and keep nested entries on Node's stack (NI-7c, NI-3b)
Node islands stack, part 8 of 11 (scriptc-perf/results/islands-prs/PLAN.md).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-22 18:49:55 -07:00

21 lines
979 B
JavaScript

// Exit while Node has OpenSSL work in flight (node-island-exit.test.ts):
// Node must stop its threads before the process's exit handlers tear
// OpenSSL down. argv[2]: "early" (exit right after Node starts, while it
// loads the system root certificates on a thread of its own with
// NODE_USE_SYSTEM_CA=1), "load" (node:tls loaded, extra certificates
// loading off-thread), "exit" (process.exit with pool work in flight),
// "keys", or "return" (fall off the end). A "-return" suffix ends the
// program by returning instead of process.exit (C exit and its handlers).
import { requireModule } from "@scriptc/node";
const arg = process.argv[2] ?? "exit";
const returns = arg.endsWith("-return") || arg === "return";
const mode = arg.replace(/-return$/, "");
if (mode === "early") {
console.log("roots", requireModule("./helper.cjs") !== null);
} else {
const lib = requireModule("./exit-tls.cjs");
console.log("roots", lib.warm(mode));
}
if (!returns) process.exit(0);