char/avril

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

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

Charlotte Somrearrange libs into lib and extensions into extsf4a0f5b

main
2.3 KiB75 linesraw
1(async () => {
2  const { process, env, pledge } = await import("avril:std");
3  const assert = (condition, message) => {
4    if (!condition) throw Error(message);
5  };
6  let delivered = false;
7  globalThis.onmessage = (event) => {
8    delivered = event.target === globalThis && event.data === "restored";
9  };
10  dispatchEvent(new MessageEvent("message", { data: "restored" }));
11  globalThis.onmessage = null;
12  assert(delivered, "Restored global event target");
13  assert(Object.isFrozen(process.args), "Mutable process metadata");
14  assert(
15    Object.getOwnPropertyDescriptor(process, "pid").value === process.pid,
16    "PID descriptor",
17  );
18  assert(performance.timeOrigin > 0 && performance.now() >= 0, "Fresh clock");
19  assert(
20    navigator.hardwareConcurrency >= 1 &&
21      navigator.userAgent.startsWith("avril/"),
22    "Navigator",
23  );
24  globalThis.metadata = [
25    process.pid,
26    process.args[0],
27    env.get("SNAPSHOT_VALUE"),
28    globalThis.name ?? "",
29    globalThis.location?.href ?? "",
30    typeof Storage === "function",
31  ];
32  env.set("SNAPSHOT_VALUE", "changed");
33  pledge({ env: false });
34  let denied = false;
35  try {
36    env.get("SNAPSHOT_VALUE");
37  } catch {
38    denied = true;
39  }
40  assert(denied, "Live capability narrowing");
41
42  const value = { bytes: new Uint8Array([65, 66]) };
43  value.self = value;
44  const copy = structuredClone(value);
45  assert(
46    copy !== value && copy.self === copy && copy.bytes[1] === 66,
47    "Structured clone",
48  );
49  const shared = new SharedArrayBuffer(2);
50  new Uint8Array(shared).set([65, 66]);
51  Object.defineProperty(SharedArrayBuffer.prototype, "byteLength", {
52    get() {
53      throw Error("poisoned shared getter");
54    },
55  });
56  assert(
57    new TextDecoder().decode(shared) === "AB",
58    "Captured shared buffer intrinsics",
59  );
60  assert(
61    new URL("../ok", "https://example.invalid/path/file").pathname === "/ok",
62    "URL",
63  );
64  const body = new Response(new Uint8Array([65, 66]));
65  assert(await body.text() === "AB", "Body streams");
66  const wasm = await WebAssembly.compileStreaming(
67    new Response(
68      new Uint8Array([0, 97, 115, 109, 1, 0, 0, 0]),
69      { headers: { "content-type": "application/wasm" } },
70    ),
71  );
72  assert(wasm instanceof WebAssembly.Module, "Wasm streaming");
73  await new Promise((resolve) => setTimeout(resolve, 0));
74  globalThis.snapshotTestComplete = true;
75})();