@@ -25,7 +25,10 @@ import {
2525} from "../shared/global-exposure.js" ;
2626
2727
28- // Configuration interface - values are set via globals before bridge loads
28+ /**
29+ * Process configuration injected by the host before the bridge bundle loads.
30+ * Values default to sensible Linux/x64 stubs when unset.
31+ */
2932export interface ProcessConfig {
3033 platform ?: string ;
3134 arch ?: string ;
@@ -87,6 +90,7 @@ const config = {
8790 typeof _processConfig !== "undefined" ? _processConfig . frozenTimeMs : undefined ,
8891} ;
8992
93+ /** Get the current timestamp, returning a frozen value when timing mitigation is active. */
9094function getNowMs ( ) : number {
9195 if (
9296 config . timingMitigation === "freeze" &&
@@ -142,7 +146,10 @@ if (
142146let _exitCode = 0 ;
143147let _exited = false ;
144148
145- // ProcessExitError class for controlled exits
149+ /**
150+ * Thrown by `process.exit()` to unwind the sandbox call stack. The host
151+ * catches this to extract the exit code without killing the isolate.
152+ */
146153export class ProcessExitError extends Error {
147154 code : number ;
148155 constructor ( code : number ) {
@@ -848,7 +855,11 @@ const _queueMicrotask =
848855 Promise . resolve ( ) . then ( fn ) ;
849856 } ;
850857
851- // Timer handle class that mimics Node.js Timeout object
858+ /**
859+ * Timer handle that mimics Node.js Timeout (ref/unref/Symbol.toPrimitive).
860+ * Timers with delay > 0 use the host's `_scheduleTimer` bridge to sleep
861+ * without blocking the isolate's event loop.
862+ */
852863class TimerHandle {
853864 _id : number ;
854865 _destroyed : boolean ;
@@ -1011,7 +1022,11 @@ function throwUnsupportedCryptoApi(api: "getRandomValues" | "randomUUID"): never
10111022 throw new Error ( `crypto.${ api } is not supported in sandbox` ) ;
10121023}
10131024
1014- // Crypto polyfill
1025+ /**
1026+ * Crypto polyfill that delegates to the host for entropy. `getRandomValues`
1027+ * calls the host's `_cryptoRandomFill` bridge to get cryptographically secure
1028+ * random bytes. Subtle crypto operations are unsupported.
1029+ */
10151030export const cryptoPolyfill = {
10161031 getRandomValues < T extends ArrayBufferView > ( array : T ) : T {
10171032 if ( typeof _cryptoRandomFill === "undefined" ) {
@@ -1063,7 +1078,10 @@ export const cryptoPolyfill = {
10631078 } ,
10641079} ;
10651080
1066- // Setup globals function - call this to install polyfills on globalThis
1081+ /**
1082+ * Install all process/timer/URL/Buffer/crypto polyfills onto `globalThis`.
1083+ * Called once during bridge initialization before user code runs.
1084+ */
10671085export function setupGlobals ( ) : void {
10681086 const g = globalThis as Record < string , unknown > ;
10691087
0 commit comments