@@ -5,7 +5,7 @@ import path from 'path';
5
5
import process from 'process' ;
6
6
import re2 from 're2' ;
7
7
import { performance } from 'perf_hooks' ;
8
- import { spawn } from 'child_process' ;
8
+ import { spawn as ambientSpawn } from 'child_process' ;
9
9
import { type as osType } from 'os' ;
10
10
import { Worker } from 'worker_threads' ;
11
11
import anylogger from 'anylogger' ;
@@ -46,9 +46,13 @@ function unhandledRejectionHandler(e) {
46
46
47
47
/**
48
48
* @param {{ moduleFormat: string, source: string }[] } bundles
49
- * @param {{ snapstorePath?: string, env: Record<string, string | undefined> } } opts
49
+ * @param {{
50
+ * snapstorePath?: string,
51
+ * spawn: typeof import('child_process').spawn
52
+ * env: Record<string, string | undefined>,
53
+ * }} opts
50
54
*/
51
- export function makeStartXSnap ( bundles , { snapstorePath, env } ) {
55
+ export function makeStartXSnap ( bundles , { snapstorePath, env, spawn } ) {
52
56
/** @type { import('@agoric/xsnap/src/xsnap').XSnapOptions } */
53
57
const xsnapOpts = {
54
58
os : osType ( ) ,
@@ -79,16 +83,18 @@ export function makeStartXSnap(bundles, { snapstorePath, env }) {
79
83
/**
80
84
* @param {string } name
81
85
* @param {(request: Uint8Array) => Promise<Uint8Array> } handleCommand
86
+ * @param { boolean } [metered]
82
87
*/
83
- async function startXSnap ( name , handleCommand ) {
88
+ async function startXSnap ( name , handleCommand , metered ) {
84
89
if ( supervisorHash ) {
85
90
return snapStore . load ( supervisorHash , async snapshot => {
86
91
const xs = xsnap ( { snapshot, name, handleCommand, ...xsnapOpts } ) ;
87
92
await xs . evaluate ( 'null' ) ; // ensure that spawn is done
88
93
return xs ;
89
94
} ) ;
90
95
}
91
- const worker = xsnap ( { handleCommand, name, ...xsnapOpts } ) ;
96
+ const meterOpts = metered ? { } : { meteringLimit : 0 } ;
97
+ const worker = xsnap ( { handleCommand, name, ...meterOpts , ...xsnapOpts } ) ;
92
98
93
99
for ( const bundle of bundles ) {
94
100
assert (
@@ -117,6 +123,7 @@ export function makeStartXSnap(bundles, { snapstorePath, env }) {
117
123
* slogFile?: string,
118
124
* testTrackDecref?: unknown,
119
125
* snapstorePath?: string,
126
+ * spawn?: typeof import('child_process').spawn,
120
127
* env?: Record<string, string | undefined>
121
128
* }} runtimeOptions
122
129
*/
@@ -137,6 +144,7 @@ export async function makeSwingsetController(
137
144
slogCallbacks,
138
145
slogFile,
139
146
snapstorePath,
147
+ spawn = ambientSpawn ,
140
148
} = runtimeOptions ;
141
149
if ( typeof Compartment === 'undefined' ) {
142
150
throw Error ( 'SES must be installed before calling makeSwingsetController' ) ;
@@ -271,7 +279,7 @@ export async function makeSwingsetController(
271
279
// @ts -ignore assume supervisorBundle is set
272
280
JSON . parse ( hostStorage . get ( 'supervisorBundle' ) ) ,
273
281
] ;
274
- const startXSnap = makeStartXSnap ( bundles , { snapstorePath, env } ) ;
282
+ const startXSnap = makeStartXSnap ( bundles , { snapstorePath, env, spawn } ) ;
275
283
276
284
const kernelEndowments = {
277
285
waitUntilQuiescent,
0 commit comments