char/avril

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

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

Charlotte Somport web extension to typescript44fe2c6

main
2.5 KiB104 linesraw
1import {
2  AbortController,
3  AbortSignal,
4  CustomEvent,
5  DOMException,
6  ErrorEvent,
7  Event,
8  EventTarget,
9  installGlobalEventTarget,
10  PromiseRejectionEvent,
11  reportErrorValue,
12  reportException,
13  reportRejectionHandled,
14  reportUnhandledRejection,
15} from "./events.js";
16import {
17  ObjectDefineProperty as define,
18  SymbolFor,
19} from "ext:core/primordials";
20import { setEventHandlers } from "ext:core/event_hooks";
21import { onRuntimeStart } from "ext:core/bootstrap";
22import { required } from "./idl.js";
23import { atob, btoa } from "./base64.js";
24import { navigator, NavigatorUAData, WorkerNavigator } from "./navigator.js";
25import { Performance, performance } from "./performance.js";
26import { MessageChannel, MessageEvent, MessagePort } from "./messaging.js";
27import { BroadcastChannel } from "./broadcast.js";
28import { installInterface } from "./interface.js";
29for (
30  const ctor of [
31    DOMException,
32    Event,
33    CustomEvent,
34    ErrorEvent,
35    PromiseRejectionEvent,
36    MessageEvent,
37    MessagePort,
38    MessageChannel,
39    BroadcastChannel,
40    EventTarget,
41    AbortSignal,
42    AbortController,
43    WorkerNavigator,
44    NavigatorUAData,
45    Performance,
46  ]
47) installInterface(ctor.name, ctor);
48
49const global = globalThis;
50onRuntimeStart(() => {
51  // V8 restores a fresh global proxy; its WeakMap brand must be installed live.
52  installGlobalEventTarget(global);
53  setEventHandlers(
54    reportException,
55    reportUnhandledRejection,
56    reportRejectionHandled,
57  );
58});
59const reportError = (...args: unknown[]): void => {
60  required(args.length, 1);
61  reportErrorValue(args[0]);
62};
63define(reportError, "length", { value: 1 });
64define(global, "reportError", {
65  value: reportError,
66  writable: true,
67  enumerable: true,
68  configurable: true,
69});
70for (const fn of [atob, btoa]) {
71  define(global, fn.name, {
72    value: fn,
73    writable: true,
74    enumerable: true,
75    configurable: true,
76  });
77}
78function replaceable(name: string, value: unknown): void {
79  define(global, name, {
80    get: () => value,
81    set: (replacement) =>
82      define(global, name, {
83        value: replacement,
84        writable: true,
85        enumerable: true,
86        configurable: true,
87      }),
88    enumerable: true,
89    configurable: true,
90  });
91}
92replaceable("self", global);
93define(global, SymbolFor("runtime:avril"), {
94  value: true,
95  writable: false,
96  enumerable: false,
97  configurable: false,
98});
99define(global, "navigator", {
100  get: () => navigator,
101  enumerable: true,
102  configurable: true,
103});
104replaceable("performance", performance);