char/avril

(wip) why'd you have to go and make things so complicaaaaated?

git clone https://git.t4t.associates/char/avril

Charlotte Somsnapshot: prepare typed ops and static/live bootstrap711e4d5

main
896 B29 linesraw
1import {
2  ArrayPrototypePush,
3  Error,
4  ObjectSetPrototypeOf,
5  TypeError,
6} from "ext:core/primordials";
7
8// Keep live initializers in the JS heap, but do not run them when building a snapshot.
9let initializers = ObjectSetPrototypeOf([], null);
10
11export function onRuntimeStart(callback) {
12  if (initializers === undefined) throw new Error("Runtime already started");
13  if (typeof callback !== "function") {
14    throw new TypeError("Expected a runtime initializer");
15  }
16  ArrayPrototypePush(initializers, callback);
17}
18
19export function startRuntime() {
20  if (initializers === undefined) throw new Error("Runtime already started");
21  const pending = initializers;
22  initializers = undefined;
23  for (let i = 0; i < pending.length; i++) {
24    const initialize = pending[i];
25    if (initialize() !== undefined) {
26      throw new TypeError("Runtime initializers must return undefined");
27    }
28  }
29}