-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathglobals.ts
More file actions
39 lines (36 loc) · 2.21 KB
/
Copy pathglobals.ts
File metadata and controls
39 lines (36 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/**
* @file Safe references to top-level globals that don't fit a larger
* primordials leaf — primitive constructors (`Boolean`, `BigInt`), `Proxy`,
* `SharedArrayBuffer`, language-level constants (`Infinity`, `NaN`,
* `globalThis`), and the encode/decode helpers. Every reference is captured
* once at module load so consumers reading adversarial input never see a
* tampered global.
*/
export const BigIntCtor: BigIntConstructor = BigInt
export const BooleanCtor: BooleanConstructor = Boolean
export const ProxyCtor: ProxyConstructor = Proxy
export const SharedArrayBufferCtor: SharedArrayBufferConstructor =
SharedArrayBuffer
// ─── Global values ─────────────────────────────────────────────────────
// `Infinity` and `NaN` are the language's two non-finite number primitives.
// They are non-writable / non-configurable on globalThis since ES5, so the
// captured value is guaranteed to match the live global. Re-exported here
// for symmetry with `NumberPOSITIVE_INFINITY` / `NumberNaN`.
export const InfinityValue: number = Infinity
export const NaNValue: number = NaN
// Captured `globalThis` reference. Re-exported under the natural name
// `globalThis` so consumers can pull it via the same alias-at-import
// pattern they use for other captured globals:
// `import { globalThis as GlobalThis } from '@socketsecurity/lib/primordials/globals'`
const capturedGlobalThis: typeof globalThis = globalThis
// eslint-disable-next-line no-shadow-restricted-names
export { capturedGlobalThis as globalThis }
// ─── Captured globals (functions / methods) ────────────────────────────
// Base64 + URI codecs are non-method globals; we capture them at module
// load so consumers reading adversarial input never see a tampered
// global. Exports keep their natural names; consumers rename via the
// alias map at import time (e.g. `import { atob as GlobalAtob }`).
export const atob = globalThis.atob
export const btoa = globalThis.btoa
export const decodeURIComponent = globalThis.decodeURIComponent
export const encodeURIComponent = globalThis.encodeURIComponent