-
Notifications
You must be signed in to change notification settings - Fork 212
/
factory.js
150 lines (138 loc) · 3.66 KB
/
factory.js
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
import { assert, details as X } from '@agoric/assert';
import { assertKnownOptions } from '../../assertOptions';
import { makeLocalVatManagerFactory } from './manager-local';
import { makeNodeWorkerVatManagerFactory } from './manager-nodeworker';
import { makeNodeSubprocessFactory } from './manager-subprocess-node';
import { makeXsSubprocessFactory } from './manager-subprocess-xsnap';
export function makeVatManagerFactory({
allVatPowers,
kernelKeeper,
vatEndowments,
meterManager,
transformMetering,
makeNodeWorker,
startSubprocessWorkerNode,
startXSnap,
gcTools,
defaultManagerType,
kernelSlog,
}) {
const localFactory = makeLocalVatManagerFactory({
allVatPowers,
kernelKeeper,
vatEndowments,
meterManager,
transformMetering,
gcTools,
kernelSlog,
});
const nodeWorkerFactory = makeNodeWorkerVatManagerFactory({
makeNodeWorker,
kernelKeeper,
kernelSlog,
testLog: allVatPowers.testLog,
});
const nodeSubprocessFactory = makeNodeSubprocessFactory({
startSubprocessWorker: startSubprocessWorkerNode,
kernelKeeper,
kernelSlog,
testLog: allVatPowers.testLog,
});
const xsWorkerFactory = makeXsSubprocessFactory({
startXSnap,
kernelKeeper,
kernelSlog,
allVatPowers,
testLog: allVatPowers.testLog,
});
function validateManagerOptions(managerOptions) {
assertKnownOptions(managerOptions, [
'enablePipelining',
'managerType',
'setup',
'bundle',
'metered',
'enableDisavow',
'enableSetup',
'liveSlotsConsole',
'notifyTermination',
'virtualObjectCacheSize',
'vatParameters',
'vatConsole',
'name',
]);
const { setup, bundle, enableSetup = false } = managerOptions;
assert(setup || bundle);
assert(
!bundle || typeof bundle === 'object',
`bundle must be object, not a plain string`,
);
// todo maybe useless
assert(!(setup && !enableSetup), X`setup() provided, but not enabled`);
}
// returns promise for new vatManager
function vatManagerFactory(vatID, managerOptions, vatSyscallHandler) {
validateManagerOptions(managerOptions);
const {
managerType = defaultManagerType,
setup,
bundle,
metered,
enableSetup,
} = managerOptions;
if (metered && managerType !== 'local' && managerType !== 'xs-worker') {
console.warn(
`TODO: support metered with ${managerType}; using local as work-around`,
);
}
if (setup && managerType !== 'local') {
console.warn(
`TODO: stop using setup() with ${managerType}; using local as work-around`,
);
}
if (managerType === 'local' || enableSetup) {
if (setup) {
return localFactory.createFromSetup(
vatID,
setup,
managerOptions,
vatSyscallHandler,
);
}
return localFactory.createFromBundle(
vatID,
bundle,
managerOptions,
vatSyscallHandler,
);
}
if (managerType === 'nodeWorker') {
return nodeWorkerFactory.createFromBundle(
vatID,
bundle,
managerOptions,
vatSyscallHandler,
);
}
if (managerType === 'node-subprocess') {
return nodeSubprocessFactory.createFromBundle(
vatID,
bundle,
managerOptions,
vatSyscallHandler,
);
}
if (managerType === 'xs-worker') {
return xsWorkerFactory.createFromBundle(
vatID,
bundle,
managerOptions,
vatSyscallHandler,
);
}
throw Error(
`unknown type ${managerType}, not local/nodeWorker/node-subprocess`,
);
}
return harden(vatManagerFactory);
}