import { ArrayPrototypePush, Error, ObjectSetPrototypeOf, TypeError, } from "ext:core/primordials"; // Keep live initializers in the JS heap, but do not run them when building a snapshot. let initializers = ObjectSetPrototypeOf([], null); export function onRuntimeStart(callback) { if (initializers === undefined) throw new Error("Runtime already started"); if (typeof callback !== "function") { throw new TypeError("Expected a runtime initializer"); } ArrayPrototypePush(initializers, callback); } export function startRuntime() { if (initializers === undefined) throw new Error("Runtime already started"); const pending = initializers; initializers = undefined; for (let i = 0; i < pending.length; i++) { const initialize = pending[i]; if (initialize() !== undefined) { throw new TypeError("Runtime initializers must return undefined"); } } }