char/avril

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

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

Charlotte Somruntime: add native POSIX and Windows path modules92a4f7e

main
5.3 KiB122 linesraw
1(() => {
2  const ReflectApply = Reflect.apply;
3  const FunctionBind = Function.prototype.bind;
4  const FunctionCall = Function.prototype.call;
5  const ObjectGetOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
6  const uncurryThis = (fn) => ReflectApply(FunctionBind, FunctionCall, [fn]);
7  const getter = (prototype, name) =>
8    uncurryThis(ObjectGetOwnPropertyDescriptor(prototype, name).get);
9  const stack = ObjectGetOwnPropertyDescriptor(new Error(), "stack");
10  const ErrorGetStack = stack.get
11    ? uncurryThis(stack.get)
12    : (error) => ObjectGetOwnPropertyDescriptor(error, "stack")?.value;
13  const TypedArrayPrototype = Object.getPrototypeOf(Uint8Array.prototype);
14
15  return Object.freeze(Object.assign(Object.create(null), {
16    Array,
17    ArrayBuffer,
18    ArrayBufferPrototypeGetResizable: getter(
19      ArrayBuffer.prototype,
20      "resizable",
21    ),
22    ArrayFrom: Array.from,
23    ArrayIsArray: Array.isArray,
24    ArrayPrototypeUnshift: uncurryThis(Array.prototype.unshift),
25    ArrayPrototypeMap: uncurryThis(Array.prototype.map),
26    ArrayPrototypeJoin: uncurryThis(Array.prototype.join),
27    ArrayPrototypePop: uncurryThis(Array.prototype.pop),
28    ArrayPrototypePush: uncurryThis(Array.prototype.push),
29    ArrayPrototypeSlice: uncurryThis(Array.prototype.slice),
30    ArrayPrototypeSort: uncurryThis(Array.prototype.sort),
31    ArrayPrototypeSplice: uncurryThis(Array.prototype.splice),
32    IteratorPrototype: Object.getPrototypeOf(
33      Object.getPrototypeOf([][Symbol.iterator]()),
34    ),
35    Error,
36    FinalizationRegistry,
37    ErrorCaptureStackTrace: Error.captureStackTrace,
38    ErrorGetStack,
39    ErrorPrototype: Error.prototype,
40    DatePrototype: Date.prototype,
41    DatePrototypeGetTime: uncurryThis(Date.prototype.getTime),
42    DatePrototypeToISOString: uncurryThis(Date.prototype.toISOString),
43    MapPrototype: Map.prototype,
44    MapPrototypeEntries: uncurryThis(Map.prototype.entries),
45    MapIteratorPrototypeNext: uncurryThis(
46      Object.getPrototypeOf(new Map().entries()).next,
47    ),
48    SetPrototype: Set.prototype,
49    SetPrototypeValues: uncurryThis(Set.prototype.values),
50    SetIteratorPrototypeNext: uncurryThis(
51      Object.getPrototypeOf(new Set().values()).next,
52    ),
53    RegExp,
54    RegExpPrototype: RegExp.prototype,
55    RegExpPrototypeExec: uncurryThis(RegExp.prototype.exec),
56    RegExpPrototypeGetSource: getter(RegExp.prototype, "source"),
57    RegExpPrototypeGetFlags: getter(RegExp.prototype, "flags"),
58    JSONStringify: JSON.stringify,
59    Map,
60    MapPrototypeGet: uncurryThis(Map.prototype.get),
61    MapPrototypeSet: uncurryThis(Map.prototype.set),
62    MapPrototypeHas: uncurryThis(Map.prototype.has),
63    MapPrototypeDelete: uncurryThis(Map.prototype.delete),
64    MapPrototypeClear: uncurryThis(Map.prototype.clear),
65    MapPrototypeForEach: uncurryThis(Map.prototype.forEach),
66    MathMin: Math.min,
67    NumberParseInt: Number.parseInt,
68    NumberParseFloat: Number.parseFloat,
69    NumberPrototypeToFixed: uncurryThis(Number.prototype.toFixed),
70    NumberIsFinite: Number.isFinite,
71    Object,
72    ObjectPrototype: Object.prototype,
73    ObjectSetPrototypeOf: Object.setPrototypeOf,
74    ObjectCreate: Object.create,
75    ObjectDefineProperty: Object.defineProperty,
76    ObjectFreeze: Object.freeze,
77    ObjectGetOwnPropertyDescriptor: Object.getOwnPropertyDescriptor,
78    ObjectGetPrototypeOf: Object.getPrototypeOf,
79    Promise,
80    RangeError,
81    Proxy,
82    ReflectApply,
83    ReflectConstruct: Reflect.construct,
84    ReflectDefineProperty: Reflect.defineProperty,
85    ReflectDeleteProperty: Reflect.deleteProperty,
86    ReflectGet: Reflect.get,
87    ReflectHas: Reflect.has,
88    ReflectSet: Reflect.set,
89    ReflectOwnKeys: Reflect.ownKeys,
90    Set,
91    SetPrototypeAdd: uncurryThis(Set.prototype.add),
92    SetPrototypeDelete: uncurryThis(Set.prototype.delete),
93    SetPrototypeHas: uncurryThis(Set.prototype.has),
94    String,
95    StringPrototypeCharCodeAt: uncurryThis(String.prototype.charCodeAt),
96    StringPrototypeIncludes: uncurryThis(String.prototype.includes),
97    StringPrototypeIndexOf: uncurryThis(String.prototype.indexOf),
98    StringPrototypeLastIndexOf: uncurryThis(String.prototype.lastIndexOf),
99    StringPrototypeRepeat: uncurryThis(String.prototype.repeat),
100    StringPrototypeReplaceAll: uncurryThis(String.prototype.replaceAll),
101    StringPrototypeSlice: uncurryThis(String.prototype.slice),
102    StringPrototypeToLowerCase: uncurryThis(String.prototype.toLowerCase),
103    StringPrototypeIsWellFormed: uncurryThis(String.prototype.isWellFormed),
104    StringPrototypeToWellFormed: uncurryThis(String.prototype.toWellFormed),
105    SymbolIterator: Symbol.iterator,
106    SymbolToStringTag: Symbol.toStringTag,
107    SymbolFor: Symbol.for,
108    TypeError,
109    WeakMap,
110    WeakMapPrototypeGet: uncurryThis(WeakMap.prototype.get),
111    WeakMapPrototypeSet: uncurryThis(WeakMap.prototype.set),
112    Uint8Array,
113    Uint8ArrayPrototypeSet: uncurryThis(Uint8Array.prototype.set),
114    TypedArrayPrototypeGetLength: getter(TypedArrayPrototype, "length"),
115    TypedArrayPrototypeGetBuffer: getter(TypedArrayPrototype, "buffer"),
116    TypedArrayPrototypeGetByteLength: getter(TypedArrayPrototype, "byteLength"),
117    TypedArrayPrototypeGetByteOffset: getter(TypedArrayPrototype, "byteOffset"),
118    TypedArrayPrototypeGetTag: getter(TypedArrayPrototype, Symbol.toStringTag),
119    uncurryThis,
120    getter,
121  }));
122})();