char/avril

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

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

Charlotte Somsnapshot: capture and restore extension layouts in one artifactd71572b

main
1.5 KiB60 linesraw
1import { state } from "./state.js";
2import { ops, primordials } from "ext:core";
3import { ArrayPrototypePush } from "ext:core/primordials";
4import { onRuntimeStart, startRuntime } from "ext:core/bootstrap";
5import { enqueueMicrotask } from "ext:core/microtasks";
6import { setEventHandlers } from "ext:core/event_hooks";
7import { safePromise } from "ext:core/promises";
8import {
9  asyncSeed,
10  collect,
11  finishWasm,
12  nativeSeed,
13  registerWasm,
14  staticOnly,
15} from "ext:core/ops";
16
17staticOnly();
18if (
19  ops.nativeSeed !== nativeSeed ||
20  primordials.ArrayPrototypePush !== ArrayPrototypePush
21) {
22  throw Error("Core export identity");
23}
24globalThis.events = ["static"];
25globalThis.snapshotState = state;
26globalThis.readNative = nativeSeed;
27globalThis.startAgain = startRuntime;
28globalThis.extensionMeta = import.meta;
29globalThis.extensionDynamic = () => import("./state.js");
30globalThis.seedAsync = () => safePromise(asyncSeed());
31
32await Promise.resolve();
33onRuntimeStart(() => {
34  state.seed = nativeSeed();
35  Object.freeze(state);
36  events.push("live");
37  setEventHandlers(
38    (error) => {
39      events.push(error.message);
40      return true;
41    },
42    (_promise, reason) => {
43      events.push(reason.message);
44      return true;
45    },
46    () => {
47      events.push("handled");
48    },
49  );
50  registerWasm((source, id) => {
51    if (source !== state.seed || id !== 1) throw Error("Stale Wasm registry");
52    finishWasm(id);
53  });
54});
55export function reportMicrotask() {
56  enqueueMicrotask(() => {
57    throw Error("microtask");
58  });
59}
60export { collect, state };