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
1.6 KiB45 linesraw
1(() => {
2  const result = [];
3  const seen = new Set();
4  function walk(path, object, depth) {
5    if (
6      object === null ||
7      (typeof object !== "object" && typeof object !== "function") ||
8      seen.has(object) || depth > 3
9    ) return;
10    seen.add(object);
11    const prototype = Object.getPrototypeOf(object);
12    result.push(JSON.stringify([
13      path,
14      Object.isExtensible(object),
15      Object.isFrozen(object),
16      prototype === null ? null : prototype.constructor?.name,
17    ]));
18    const keys = Reflect.ownKeys(object).map((key) => [key, String(key)]);
19    keys.sort((a, b) => a[1] < b[1] ? -1 : a[1] > b[1] ? 1 : 0);
20    for (const [key, name] of keys) {
21      const descriptor = Object.getOwnPropertyDescriptor(object, key);
22      const child = `${path}.${name}`;
23      result.push(JSON.stringify([
24        child,
25        descriptor.enumerable,
26        descriptor.configurable,
27        "value" in descriptor
28          ? [
29            descriptor.value === null ? "null" : typeof descriptor.value,
30            descriptor.writable,
31          ]
32          : [typeof descriptor.get, typeof descriptor.set],
33      ]));
34      if ("value" in descriptor) walk(child, descriptor.value, depth + 1);
35    }
36  }
37  walk("globalThis", globalThis, 0);
38  result.push(`globalEventTarget: ${globalThis instanceof EventTarget}`);
39  let dispatched = false;
40  const listener = () => dispatched = true;
41  addEventListener("snapshot-surface", listener, { once: true });
42  dispatchEvent(new Event("snapshot-surface"));
43  result.push(`globalDispatch: ${dispatched}`);
44  return result;
45})();