@@ -9,7 +9,9 @@ let sharedV8RuntimePromise: Promise<V8Runtime> | null = null;
99async function getSharedV8Runtime ( ) : Promise < V8Runtime > {
1010 if ( sharedV8Runtime ) return sharedV8Runtime ;
1111 if ( ! sharedV8RuntimePromise ) {
12- sharedV8RuntimePromise = createV8Runtime ( ) . then ( ( r ) => {
12+ sharedV8RuntimePromise = createV8Runtime ( {
13+ warmupBridgeCode : composeBridgeCodeForWarmup ( ) ,
14+ } ) . then ( ( r ) => {
1315 sharedV8Runtime = r ;
1416 return r ;
1517 } ) ;
@@ -34,6 +36,46 @@ import { createProcessConfigForExecution } from "./bridge-setup.js";
3436
3537export { NodeExecutionDriverOptions } ;
3638
39+ /**
40+ * Compose the default bridge code for snapshot warm-up.
41+ * Uses timingMitigation='none' and default budget values so the snapshot
42+ * is ready for the most common session configuration.
43+ */
44+ export function composeBridgeCodeForWarmup ( ) : string {
45+ const parts : string [ ] = [ ] ;
46+
47+ parts . push ( getIvmCompatShimSource ( ) ) ;
48+
49+ parts . push ( `globalThis._maxTimers = ${ DEFAULT_MAX_TIMERS } ;` ) ;
50+ parts . push ( `globalThis._maxHandles = ${ DEFAULT_MAX_HANDLES } ;` ) ;
51+ parts . push ( `globalThis.__runtimeBridgeSetupConfig = ${ JSON . stringify ( {
52+ initialCwd : DEFAULT_SANDBOX_CWD ,
53+ jsonPayloadLimitBytes : DEFAULT_ISOLATE_JSON_PAYLOAD_BYTES ,
54+ payloadLimitErrorCode : PAYLOAD_LIMIT_ERROR_CODE ,
55+ } ) } ;`) ;
56+
57+ parts . push ( getIsolateRuntimeSource ( "globalExposureHelpers" ) ) ;
58+ parts . push ( getInitialBridgeGlobalsSetupCode ( ) ) ;
59+ parts . push ( getConsoleSetupCode ( ) ) ;
60+ parts . push ( getIsolateRuntimeSource ( "setupFsFacade" ) ) ;
61+ parts . push ( getRawBridgeCode ( ) ) ;
62+ parts . push ( getBridgeAttachCode ( ) ) ;
63+
64+ // Default: no timing mitigation
65+ parts . push ( getIsolateRuntimeSource ( "applyTimingMitigationOff" ) ) ;
66+
67+ parts . push ( getRequireSetupCode ( ) ) ;
68+ parts . push ( getIsolateRuntimeSource ( "initCommonjsModuleGlobals" ) ) ;
69+
70+ parts . push ( `globalThis.__runtimeCustomGlobalPolicy = ${ JSON . stringify ( {
71+ hardenedGlobals : HARDENED_NODE_CUSTOM_GLOBALS ,
72+ mutableGlobals : MUTABLE_NODE_CUSTOM_GLOBALS ,
73+ } ) } ;`) ;
74+ parts . push ( getIsolateRuntimeSource ( "applyCustomGlobalPolicy" ) ) ;
75+
76+ return parts . join ( "\n" ) ;
77+ }
78+
3779const MAX_ERROR_MESSAGE_CHARS = 8192 ;
3880
3981function boundErrorMessage ( message : string ) : string {
0 commit comments