@agoric/swingset-liveslots 0.10.3-dev-ecf2d8e.0 → 0.10.3-other-dev-70beeb7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +61 -0
- package/package.json +17 -20
- package/src/collectionManager.js +66 -135
- package/src/index.js +1 -2
- package/src/liveslots.js +74 -47
- package/src/virtualObjectManager.js +14 -56
- package/src/virtualReferences.js +0 -51
- package/test/liveslots-helpers.js +4 -4
- package/test/mock-gc.js +0 -1
- package/test/storeGC/test-lifecycle.js +1 -1
- package/test/storeGC/test-refcount-management.js +1 -0
- package/test/storeGC/test-scalar-store-kind.js +1 -0
- package/test/storeGC/test-weak-key.js +1 -0
- package/test/test-baggage.js +1 -0
- package/test/test-cache.js +1 -0
- package/test/test-collection-schema-refcount.js +1 -0
- package/test/test-collection-upgrade.js +2 -0
- package/test/test-collections.js +14 -117
- package/test/test-dropped-collection-weakrefs.js +1 -0
- package/test/test-durabilityChecks.js +3 -2
- package/test/test-facetiousness.js +2 -1
- package/test/test-gc-sensitivity.js +1 -1
- package/test/test-handled-promises.js +6 -4
- package/test/test-initial-vrefs.js +2 -1
- package/test/test-liveslots-mock-gc.js +1 -1
- package/test/test-liveslots-real-gc.js +1 -1
- package/test/test-liveslots.js +13 -12
- package/test/test-vo-test-harness.js +1 -0
- package/test/test-vpid-liveslots.js +2 -1
- package/test/util.js +1 -1
- package/test/virtual-objects/test-cease-recognition.js +2 -2
- package/test/virtual-objects/test-cross-facet.js +2 -1
- package/test/virtual-objects/test-empty-data.js +2 -1
- package/test/virtual-objects/test-facets.js +2 -1
- package/test/virtual-objects/test-kind-changes.js +1 -1
- package/test/virtual-objects/test-reachable-vrefs.js +2 -2
- package/test/virtual-objects/test-rep-tostring.js +3 -2
- package/test/virtual-objects/test-retain-remotable.js +1 -1
- package/test/virtual-objects/test-state-shape.js +1 -1
- package/test/virtual-objects/test-virtualObjectGC.js +1 -1
- package/test/virtual-objects/test-virtualObjectManager.js +1 -5
- package/test/virtual-objects/test-vo-real-gc.js +1 -1
- package/test/virtual-objects/test-weakcollections-vref-handling.js +2 -1
- package/src/vatDataTypes.d.ts +0 -230
- package/src/vatDataTypes.js +0 -2
- package/tools/fakeCollectionManager.js +0 -44
- package/tools/fakeVirtualObjectManager.js +0 -60
- package/tools/fakeVirtualSupport.js +0 -375
- package/tools/prepare-test-env.js +0 -13
- package/tools/setup-vat-data.js +0 -54
- package/tools/vo-test-harness.js +0 -143
package/src/vatDataTypes.d.ts
DELETED
|
@@ -1,230 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @file Types for vat-data
|
|
3
|
-
*
|
|
4
|
-
* Facet is a single object with methods.
|
|
5
|
-
* Behavior is a description when defining a kind of what facets it will have.
|
|
6
|
-
* For the non-multi defineKind, there is just one facet so it doesn't have a key.
|
|
7
|
-
*/
|
|
8
|
-
import type { InterfaceGuard, Pattern } from '@endo/patterns';
|
|
9
|
-
import type {
|
|
10
|
-
MapStore,
|
|
11
|
-
SetStore,
|
|
12
|
-
StoreOptions,
|
|
13
|
-
WeakMapStore,
|
|
14
|
-
WeakSetStore,
|
|
15
|
-
} from '@agoric/store';
|
|
16
|
-
|
|
17
|
-
// TODO should be moved into @endo/patterns and eventually imported here
|
|
18
|
-
// instead of this local definition.
|
|
19
|
-
export type InterfaceGuardKit = Record<string, InterfaceGuard>;
|
|
20
|
-
|
|
21
|
-
export type { MapStore, Pattern };
|
|
22
|
-
|
|
23
|
-
// This needs `any` values. If they were `unknown`, code that uses Baggage
|
|
24
|
-
// would need explicit runtime checks or casts for every fetch, which is
|
|
25
|
-
// onerous.
|
|
26
|
-
export type Baggage = MapStore<string, any>;
|
|
27
|
-
|
|
28
|
-
type Tail<T extends any[]> = T extends [head: any, ...rest: infer Rest]
|
|
29
|
-
? Rest
|
|
30
|
-
: [];
|
|
31
|
-
|
|
32
|
-
type MinusContext<
|
|
33
|
-
F extends (context, ...rest: any[]) => any,
|
|
34
|
-
P extends any[] = Parameters<F>, // P: are the parameters of F
|
|
35
|
-
R = ReturnType<F>, // R: the return type of F
|
|
36
|
-
> = (...args: Tail<P>) => R;
|
|
37
|
-
|
|
38
|
-
export type KindFacet<O> = { [K in keyof O]: MinusContext<O[K]> };
|
|
39
|
-
|
|
40
|
-
export type KindFacets<B> = {
|
|
41
|
-
[FacetKey in keyof B]: KindFacet<B[FacetKey]>;
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
export type KindContext<S, F> = { state: S; self: KindFacet<F> };
|
|
45
|
-
export type MultiKindContext<S, B> = { state: S; facets: KindFacets<B> };
|
|
46
|
-
|
|
47
|
-
export type PlusContext<C, M> = (c: C, ...args: Parameters<M>) => ReturnType<M>;
|
|
48
|
-
export type FunctionsPlusContext<C, O> = {
|
|
49
|
-
[K in keyof O]: PlusContext<C, O[K]>;
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
declare class DurableKindHandleClass {
|
|
53
|
-
private descriptionTag: string;
|
|
54
|
-
}
|
|
55
|
-
export type DurableKindHandle = DurableKindHandleClass;
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Grab bag of options that can be provided to `defineDurableKind` and its
|
|
59
|
-
* siblings. Not all options are meaningful in all contexts. See the
|
|
60
|
-
* doc-comments on each option.
|
|
61
|
-
*/
|
|
62
|
-
export type DefineKindOptions<C> = {
|
|
63
|
-
/**
|
|
64
|
-
* If provided, the `finish` function will be called after the instance is
|
|
65
|
-
* made and internally registered, but before it is returned. The finish
|
|
66
|
-
* function is to do any post-intantiation initialization that should be
|
|
67
|
-
* done before exposing the object to its clients.
|
|
68
|
-
*/
|
|
69
|
-
finish?: (context: C) => void;
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Meaningful to `makeScalarBigMapStore` and its siblings. These maker
|
|
73
|
-
* fuctions will make either virtual or durable stores, depending on
|
|
74
|
-
* this flag. Defaults to off, making virtual but not durable collections.
|
|
75
|
-
*
|
|
76
|
-
* Generally, durable collections are provided with `provideDurableMapStore`
|
|
77
|
-
* and its sibling, which use this flag internally. If you do not make
|
|
78
|
-
* durable collections by other means, you can consider this as
|
|
79
|
-
* intended for internal use only.
|
|
80
|
-
*/
|
|
81
|
-
durable?: boolean;
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* If provided, it describes the shape of all state records of instances
|
|
85
|
-
* of this kind.
|
|
86
|
-
*/
|
|
87
|
-
stateShape?: { [name: string]: Pattern };
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* Intended for internal use only.
|
|
91
|
-
* Should the raw methods receive their `context` argument as their first
|
|
92
|
-
* argument or as their `this` binding? For `defineDurableKind` and its
|
|
93
|
-
* siblings (including `prepareSingleton`), this defaults to off, meaning that
|
|
94
|
-
* their behavior methods receive `context` as their first argument.
|
|
95
|
-
* `prepareExoClass` and its siblings (including `prepareExo`) use
|
|
96
|
-
* this flag internally to indicate that their methods receive `context`
|
|
97
|
-
* as their `this` binding.
|
|
98
|
-
*/
|
|
99
|
-
thisfulMethods?: boolean;
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* Intended for internal use only.
|
|
103
|
-
* Only applicable if this is a class kind. A class kit kind should use
|
|
104
|
-
* `interfaceGuardKit` instead.
|
|
105
|
-
*
|
|
106
|
-
* If an `interfaceGuard` is provided, then the raw methods passed alongside
|
|
107
|
-
* it are wrapped by a function that first checks that this method's guard
|
|
108
|
-
* pattern is satisfied before calling the raw method.
|
|
109
|
-
*
|
|
110
|
-
* In `defineDurableKind` and its siblings, this defaults to `undefined`.
|
|
111
|
-
* Exo classes use this internally to protect their raw class methods
|
|
112
|
-
* using the provided interface.
|
|
113
|
-
* In absence, an exo is protected anyway, while a bare kind is
|
|
114
|
-
* not (detected by `!thisfulMethods`),
|
|
115
|
-
*/
|
|
116
|
-
interfaceGuard?: InterfaceGuard;
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* Intended for internal use only.
|
|
120
|
-
* Only applicable if this is a class kit kind. A class kind should use
|
|
121
|
-
* `interfaceGuard` instead.
|
|
122
|
-
*
|
|
123
|
-
* If an `interfaceGuardKit` is provided, then each member of the
|
|
124
|
-
* interfaceGuardKit is used to guard the corresponding facet of the
|
|
125
|
-
* class kit.
|
|
126
|
-
*
|
|
127
|
-
* In `defineDurableKindMulti` and its siblings, this defaults to `undefined`.
|
|
128
|
-
* Exo class kits use this internally to protect their facets.
|
|
129
|
-
* In absence, an exo is protected anyway, while a bare kind is
|
|
130
|
-
* not (detected by `!thisfulMethods`),
|
|
131
|
-
*/
|
|
132
|
-
interfaceGuardKit?: InterfaceGuardKit;
|
|
133
|
-
};
|
|
134
|
-
|
|
135
|
-
export type VatData = {
|
|
136
|
-
// virtual kinds
|
|
137
|
-
/** @deprecated Use defineVirtualExoClass instead */
|
|
138
|
-
defineKind: <P, S, F>(
|
|
139
|
-
tag: string,
|
|
140
|
-
init: (...args: P) => S,
|
|
141
|
-
facet: F,
|
|
142
|
-
options?: DefineKindOptions<KindContext<S, F>>,
|
|
143
|
-
) => (...args: P) => KindFacet<F>;
|
|
144
|
-
|
|
145
|
-
/** @deprecated Use defineVirtualExoClassKit instead */
|
|
146
|
-
defineKindMulti: <P, S, B>(
|
|
147
|
-
tag: string,
|
|
148
|
-
init: (...args: P) => S,
|
|
149
|
-
behavior: B,
|
|
150
|
-
options?: DefineKindOptions<MultiKindContext<S, B>>,
|
|
151
|
-
) => (...args: P) => KindFacets<B>;
|
|
152
|
-
|
|
153
|
-
// durable kinds
|
|
154
|
-
makeKindHandle: (descriptionTag: string) => DurableKindHandle;
|
|
155
|
-
|
|
156
|
-
/** @deprecated Use defineDurableExoClass instead */
|
|
157
|
-
defineDurableKind: <P, S, F>(
|
|
158
|
-
kindHandle: DurableKindHandle,
|
|
159
|
-
init: (...args: P) => S,
|
|
160
|
-
facet: F,
|
|
161
|
-
options?: DefineKindOptions<KindContext<S, F>>,
|
|
162
|
-
) => (...args: P) => KindFacet<F>;
|
|
163
|
-
|
|
164
|
-
/** @deprecated Use defineDurableExoClassKit instead */
|
|
165
|
-
defineDurableKindMulti: <P, S, B>(
|
|
166
|
-
kindHandle: DurableKindHandle,
|
|
167
|
-
init: (...args: P) => S,
|
|
168
|
-
behavior: B,
|
|
169
|
-
options?: DefineKindOptions<MultiKindContext<S, B>>,
|
|
170
|
-
) => (...args: P) => KindFacets<B>;
|
|
171
|
-
|
|
172
|
-
providePromiseWatcher: unknown;
|
|
173
|
-
watchPromise: unknown;
|
|
174
|
-
|
|
175
|
-
makeScalarBigMapStore: <K, V>(
|
|
176
|
-
label: string,
|
|
177
|
-
options?: StoreOptions,
|
|
178
|
-
) => MapStore<K, V>;
|
|
179
|
-
makeScalarBigWeakMapStore: <K, V>(
|
|
180
|
-
label: string,
|
|
181
|
-
options?: StoreOptions,
|
|
182
|
-
) => WeakMapStore<K, V>;
|
|
183
|
-
|
|
184
|
-
makeScalarBigSetStore: <K>(
|
|
185
|
-
label: string,
|
|
186
|
-
options?: StoreOptions,
|
|
187
|
-
) => SetStore<K>;
|
|
188
|
-
makeScalarBigWeakSetStore: <K>(
|
|
189
|
-
label: string,
|
|
190
|
-
options?: StoreOptions,
|
|
191
|
-
) => WeakSetStore<K>;
|
|
192
|
-
canBeDurable: (specimen: unknown) => boolean;
|
|
193
|
-
};
|
|
194
|
-
|
|
195
|
-
// The JSDoc is repeated here and at the function definition so it appears
|
|
196
|
-
// in IDEs where it's used, regardless of type resolution.
|
|
197
|
-
export interface PickFacet {
|
|
198
|
-
/**
|
|
199
|
-
* When making a multi-facet kind, it's common to pick one facet to
|
|
200
|
-
* expose. E.g.,
|
|
201
|
-
*
|
|
202
|
-
* const makeFoo = (a, b, c, d) => makeFooBase(a, b, c, d).self;
|
|
203
|
-
*
|
|
204
|
-
* This helper reduces the duplication:
|
|
205
|
-
*
|
|
206
|
-
* const makeFoo = pickFacet(makeFooBase, 'self');
|
|
207
|
-
*/
|
|
208
|
-
<M extends (...args: any[]) => any, F extends keyof ReturnType<M>>(
|
|
209
|
-
maker: M,
|
|
210
|
-
facetName: F,
|
|
211
|
-
): (...args: Parameters<M>) => ReturnType<M>[F];
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
/** @deprecated Use prepareExoClass instead */
|
|
215
|
-
export type PrepareKind = <P, S, F>(
|
|
216
|
-
baggage: Baggage,
|
|
217
|
-
tag: string,
|
|
218
|
-
init: (...args: P) => S,
|
|
219
|
-
facet: F,
|
|
220
|
-
options?: DefineKindOptions<KindContext<S, F>>,
|
|
221
|
-
) => (...args: P) => KindFacet<F>;
|
|
222
|
-
|
|
223
|
-
/** @deprecated Use prepareExoClassKit instead */
|
|
224
|
-
export type PrepareKindMulti = <P, S, B>(
|
|
225
|
-
baggage: Baggage,
|
|
226
|
-
tag: string,
|
|
227
|
-
init: (...args: P) => S,
|
|
228
|
-
behavior: B,
|
|
229
|
-
options?: DefineKindOptions<MultiKindContext<S, B>>,
|
|
230
|
-
) => (...args: P) => KindFacets<B>;
|
package/src/vatDataTypes.js
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { makeCollectionManager } from '../src/collectionManager.js';
|
|
2
|
-
|
|
3
|
-
export function makeFakeCollectionManager(vrm, fakeStuff, _options = {}) {
|
|
4
|
-
const {
|
|
5
|
-
makeScalarBigMapStore,
|
|
6
|
-
makeScalarBigWeakMapStore,
|
|
7
|
-
makeScalarBigSetStore,
|
|
8
|
-
makeScalarBigWeakSetStore,
|
|
9
|
-
provideBaggage,
|
|
10
|
-
initializeStoreKindInfo,
|
|
11
|
-
flushSchemaCache,
|
|
12
|
-
} = makeCollectionManager(
|
|
13
|
-
fakeStuff.syscall,
|
|
14
|
-
vrm,
|
|
15
|
-
fakeStuff.allocateExportID,
|
|
16
|
-
fakeStuff.allocateCollectionID,
|
|
17
|
-
fakeStuff.convertValToSlot,
|
|
18
|
-
fakeStuff.convertSlotToVal,
|
|
19
|
-
fakeStuff.registerEntry,
|
|
20
|
-
fakeStuff.marshal.serialize,
|
|
21
|
-
fakeStuff.marshal.unserialize,
|
|
22
|
-
fakeStuff.assertAcceptableSyscallCapdataSize,
|
|
23
|
-
);
|
|
24
|
-
initializeStoreKindInfo();
|
|
25
|
-
|
|
26
|
-
const normalCM = {
|
|
27
|
-
makeScalarBigMapStore,
|
|
28
|
-
makeScalarBigWeakMapStore,
|
|
29
|
-
makeScalarBigSetStore,
|
|
30
|
-
makeScalarBigWeakSetStore,
|
|
31
|
-
provideBaggage,
|
|
32
|
-
flushSchemaCache,
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
const debugTools = {
|
|
36
|
-
getValForSlot: fakeStuff.getValForSlot,
|
|
37
|
-
setValForSlot: fakeStuff.setValForSlot,
|
|
38
|
-
registerEntry: fakeStuff.registerEntry,
|
|
39
|
-
deleteEntry: fakeStuff.deleteEntry,
|
|
40
|
-
dumpStore: fakeStuff.dumpStore,
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
return harden({ ...normalCM, ...debugTools });
|
|
44
|
-
}
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { makeVirtualObjectManager } from '../src/virtualObjectManager.js';
|
|
2
|
-
|
|
3
|
-
// Note: `fakeVirtualObjectManager` is something of a misnomer here. The
|
|
4
|
-
// virtual object manager being used to implement this realized by the actual
|
|
5
|
-
// virtual object manager code. What's being faked is everything else the
|
|
6
|
-
// virtual object manager is embedded in, i.e., the kernel and the rest of
|
|
7
|
-
// liveslots. In particular, this module can be (and is, and is intended to be)
|
|
8
|
-
// used for unit tests for the virtual object manager itself. What you get back
|
|
9
|
-
// from `makeFakeVirtualObjectManager` can't be used to program as if you were
|
|
10
|
-
// running in a vat because the rest of the vat environment is not present, but
|
|
11
|
-
// it *will* execute virtual object manager operations in the same way that the
|
|
12
|
-
// real one will because underneath it *is* the real one.
|
|
13
|
-
|
|
14
|
-
export function makeFakeVirtualObjectManager(vrm, fakeStuff) {
|
|
15
|
-
const {
|
|
16
|
-
initializeKindHandleKind,
|
|
17
|
-
defineKind,
|
|
18
|
-
defineKindMulti,
|
|
19
|
-
defineDurableKind,
|
|
20
|
-
defineDurableKindMulti,
|
|
21
|
-
makeKindHandle,
|
|
22
|
-
VirtualObjectAwareWeakMap,
|
|
23
|
-
VirtualObjectAwareWeakSet,
|
|
24
|
-
flushStateCache,
|
|
25
|
-
canBeDurable,
|
|
26
|
-
} = makeVirtualObjectManager(
|
|
27
|
-
fakeStuff.syscall,
|
|
28
|
-
vrm,
|
|
29
|
-
fakeStuff.allocateExportID,
|
|
30
|
-
fakeStuff.getSlotForVal,
|
|
31
|
-
fakeStuff.requiredValForSlot,
|
|
32
|
-
fakeStuff.registerEntry,
|
|
33
|
-
fakeStuff.marshal.serialize,
|
|
34
|
-
fakeStuff.marshal.unserialize,
|
|
35
|
-
fakeStuff.assertAcceptableSyscallCapdataSize,
|
|
36
|
-
);
|
|
37
|
-
|
|
38
|
-
const normalVOM = {
|
|
39
|
-
initializeKindHandleKind,
|
|
40
|
-
defineKind,
|
|
41
|
-
defineKindMulti,
|
|
42
|
-
defineDurableKind,
|
|
43
|
-
defineDurableKindMulti,
|
|
44
|
-
makeKindHandle,
|
|
45
|
-
canBeDurable,
|
|
46
|
-
VirtualObjectAwareWeakMap,
|
|
47
|
-
VirtualObjectAwareWeakSet,
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
const debugTools = {
|
|
51
|
-
getValForSlot: fakeStuff.getValForSlot,
|
|
52
|
-
setValForSlot: fakeStuff.setValForSlot,
|
|
53
|
-
registerEntry: fakeStuff.registerEntry,
|
|
54
|
-
deleteEntry: fakeStuff.deleteEntry,
|
|
55
|
-
flushStateCache,
|
|
56
|
-
dumpStore: fakeStuff.dumpStore,
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
return harden({ ...normalVOM, ...debugTools });
|
|
60
|
-
}
|
|
@@ -1,375 +0,0 @@
|
|
|
1
|
-
/* global globalThis */
|
|
2
|
-
/* eslint-disable max-classes-per-file */
|
|
3
|
-
import { makeMarshal } from '@endo/marshal';
|
|
4
|
-
import { assert } from '@agoric/assert';
|
|
5
|
-
import { parseVatSlot } from '../src/parseVatSlots.js';
|
|
6
|
-
|
|
7
|
-
import { makeVirtualReferenceManager } from '../src/virtualReferences.js';
|
|
8
|
-
import { makeWatchedPromiseManager } from '../src/watchedPromises.js';
|
|
9
|
-
import { makeFakeVirtualObjectManager } from './fakeVirtualObjectManager.js';
|
|
10
|
-
import { makeFakeCollectionManager } from './fakeCollectionManager.js';
|
|
11
|
-
|
|
12
|
-
const { Fail } = assert;
|
|
13
|
-
|
|
14
|
-
const {
|
|
15
|
-
WeakRef: RealWeakRef,
|
|
16
|
-
WeakMap: RealWeakMap,
|
|
17
|
-
WeakSet: RealWeakSet,
|
|
18
|
-
} = globalThis;
|
|
19
|
-
|
|
20
|
-
class FakeFinalizationRegistry {
|
|
21
|
-
// eslint-disable-next-line no-useless-constructor, no-empty-function
|
|
22
|
-
constructor() {}
|
|
23
|
-
|
|
24
|
-
// eslint-disable-next-line class-methods-use-this
|
|
25
|
-
register(_target, _heldValue, _unregisterToken) {}
|
|
26
|
-
|
|
27
|
-
// eslint-disable-next-line class-methods-use-this
|
|
28
|
-
unregister(_unregisterToken) {}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
class FakeWeakRef {
|
|
32
|
-
constructor(target) {
|
|
33
|
-
this.target = target;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
deref() {
|
|
37
|
-
return this.target; // strong ref
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export function makeFakeLiveSlotsStuff(options = {}) {
|
|
42
|
-
let vrm;
|
|
43
|
-
function setVrm(vrmToUse) {
|
|
44
|
-
assert(!vrm, 'vrm already configured');
|
|
45
|
-
vrm = vrmToUse;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
const {
|
|
49
|
-
fakeStore = new Map(),
|
|
50
|
-
weak = false,
|
|
51
|
-
log,
|
|
52
|
-
FinalizationRegistry = FakeFinalizationRegistry,
|
|
53
|
-
WeakRef = FakeWeakRef, // VRM uses this
|
|
54
|
-
WeakMap = RealWeakMap,
|
|
55
|
-
WeakSet = RealWeakSet,
|
|
56
|
-
addToPossiblyDeadSet = () => {},
|
|
57
|
-
addToPossiblyRetiredSet = () => {},
|
|
58
|
-
} = options;
|
|
59
|
-
|
|
60
|
-
let sortedKeys;
|
|
61
|
-
let priorKeyReturned;
|
|
62
|
-
let priorKeyIndex;
|
|
63
|
-
|
|
64
|
-
function s(v) {
|
|
65
|
-
switch (typeof v) {
|
|
66
|
-
case 'symbol':
|
|
67
|
-
return v.toString();
|
|
68
|
-
case 'bigint':
|
|
69
|
-
return `${v}n`;
|
|
70
|
-
default:
|
|
71
|
-
return `${v}`;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
function ensureSorted() {
|
|
76
|
-
if (!sortedKeys) {
|
|
77
|
-
sortedKeys = [];
|
|
78
|
-
for (const key of fakeStore.keys()) {
|
|
79
|
-
sortedKeys.push(key);
|
|
80
|
-
}
|
|
81
|
-
sortedKeys.sort((k1, k2) => k1.localeCompare(k2));
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
function clearGetNextKeyCache() {
|
|
86
|
-
priorKeyReturned = undefined;
|
|
87
|
-
priorKeyIndex = -1;
|
|
88
|
-
}
|
|
89
|
-
clearGetNextKeyCache();
|
|
90
|
-
|
|
91
|
-
function clearSorted() {
|
|
92
|
-
sortedKeys = undefined;
|
|
93
|
-
clearGetNextKeyCache();
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
function dumpStore() {
|
|
97
|
-
ensureSorted();
|
|
98
|
-
const result = [];
|
|
99
|
-
for (const key of sortedKeys) {
|
|
100
|
-
result.push([key, fakeStore.get(key)]);
|
|
101
|
-
}
|
|
102
|
-
return result;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
const syscall = {
|
|
106
|
-
vatstoreGet(key) {
|
|
107
|
-
const result = fakeStore.get(key);
|
|
108
|
-
if (log) {
|
|
109
|
-
log.push(`get ${s(key)} => ${s(result)}`);
|
|
110
|
-
}
|
|
111
|
-
return result;
|
|
112
|
-
},
|
|
113
|
-
vatstoreGetNextKey(priorKey) {
|
|
114
|
-
assert.typeof(priorKey, 'string');
|
|
115
|
-
ensureSorted();
|
|
116
|
-
// TODO: binary search for priorKey (maybe missing), then get
|
|
117
|
-
// the one after that. For now we go simple and slow. But cache
|
|
118
|
-
// a starting point, because the main use case is a full
|
|
119
|
-
// iteration. OTOH, the main use case also deletes everything,
|
|
120
|
-
// which will clobber the cache on each deletion, so it might
|
|
121
|
-
// not help.
|
|
122
|
-
const start = priorKeyReturned === priorKey ? priorKeyIndex : 0;
|
|
123
|
-
let result;
|
|
124
|
-
for (let i = start; i < sortedKeys.length; i += 1) {
|
|
125
|
-
const key = sortedKeys[i];
|
|
126
|
-
if (key > priorKey) {
|
|
127
|
-
priorKeyReturned = key;
|
|
128
|
-
priorKeyIndex = i;
|
|
129
|
-
result = key;
|
|
130
|
-
break;
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
if (!result) {
|
|
134
|
-
// reached end without finding the key, so clear our cache
|
|
135
|
-
clearGetNextKeyCache();
|
|
136
|
-
}
|
|
137
|
-
if (log) {
|
|
138
|
-
log.push(`getNextKey ${s(priorKey)} => ${s(result)}`);
|
|
139
|
-
}
|
|
140
|
-
return result;
|
|
141
|
-
},
|
|
142
|
-
vatstoreSet(key, value) {
|
|
143
|
-
if (log) {
|
|
144
|
-
log.push(`set ${s(key)} ${s(value)}`);
|
|
145
|
-
}
|
|
146
|
-
if (!fakeStore.has(key)) {
|
|
147
|
-
clearSorted();
|
|
148
|
-
}
|
|
149
|
-
fakeStore.set(key, value);
|
|
150
|
-
},
|
|
151
|
-
vatstoreDelete(key) {
|
|
152
|
-
if (log) {
|
|
153
|
-
log.push(`delete ${s(key)}`);
|
|
154
|
-
}
|
|
155
|
-
if (fakeStore.has(key)) {
|
|
156
|
-
clearSorted();
|
|
157
|
-
}
|
|
158
|
-
fakeStore.delete(key);
|
|
159
|
-
},
|
|
160
|
-
};
|
|
161
|
-
|
|
162
|
-
function allocateExportID() {
|
|
163
|
-
return vrm.allocateNextID('exportID');
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
function allocateCollectionID() {
|
|
167
|
-
return vrm.allocateNextID('collectionID');
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
// note: The real liveslots slotToVal() maps slots (vrefs) to a WeakRef,
|
|
171
|
-
// and the WeakRef may or may not contain the target value. Use
|
|
172
|
-
// options={weak:true} to match that behavior, or the default weak:false to
|
|
173
|
-
// keep strong references.
|
|
174
|
-
const valToSlot = new WeakMap();
|
|
175
|
-
const slotToVal = new Map();
|
|
176
|
-
|
|
177
|
-
function getSlotForVal(val) {
|
|
178
|
-
return valToSlot.get(val);
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
function getValForSlot(slot) {
|
|
182
|
-
const d = slotToVal.get(slot);
|
|
183
|
-
return d && (weak ? d.deref() : d);
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
function requiredValForSlot(slot) {
|
|
187
|
-
const val = getValForSlot(slot);
|
|
188
|
-
assert(val, `${slot} must have a value`);
|
|
189
|
-
return val;
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
function setValForSlot(slot, val) {
|
|
193
|
-
slotToVal.set(slot, weak ? new RealWeakRef(val) : val);
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
function convertValToSlot(val) {
|
|
197
|
-
if (!valToSlot.has(val)) {
|
|
198
|
-
const slot = `o+${allocateExportID()}`;
|
|
199
|
-
valToSlot.set(val, slot);
|
|
200
|
-
setValForSlot(slot, val);
|
|
201
|
-
}
|
|
202
|
-
return valToSlot.get(val);
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
function convertSlotToVal(slot) {
|
|
206
|
-
const { type, id, virtual, durable, facet, baseRef } = parseVatSlot(slot);
|
|
207
|
-
assert.equal(type, 'object');
|
|
208
|
-
let val = getValForSlot(baseRef);
|
|
209
|
-
if (val) {
|
|
210
|
-
if (virtual || durable) {
|
|
211
|
-
if (facet !== undefined) {
|
|
212
|
-
return vrm.getFacet(id, val, facet);
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
return val;
|
|
216
|
-
}
|
|
217
|
-
let result;
|
|
218
|
-
if (virtual || durable) {
|
|
219
|
-
if (vrm) {
|
|
220
|
-
val = vrm.reanimate(slot);
|
|
221
|
-
if (facet !== undefined) {
|
|
222
|
-
result = vrm.getFacet(id, val, facet);
|
|
223
|
-
}
|
|
224
|
-
} else {
|
|
225
|
-
assert.fail('fake liveSlots stuff configured without vrm');
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
// eslint-disable-next-line no-use-before-define
|
|
229
|
-
registerEntry(baseRef, val, facet !== undefined);
|
|
230
|
-
if (!result) {
|
|
231
|
-
result = val;
|
|
232
|
-
}
|
|
233
|
-
return result;
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
const marshal = makeMarshal(convertValToSlot, convertSlotToVal, {
|
|
237
|
-
serializeBodyFormat: 'smallcaps',
|
|
238
|
-
});
|
|
239
|
-
|
|
240
|
-
function registerEntry(baseRef, val, valIsCohort) {
|
|
241
|
-
const { facet } = parseVatSlot(baseRef);
|
|
242
|
-
!facet ||
|
|
243
|
-
Fail`registerEntry(${baseRef} should not receive individual facets`;
|
|
244
|
-
setValForSlot(baseRef, val);
|
|
245
|
-
if (valIsCohort) {
|
|
246
|
-
const { id } = parseVatSlot(baseRef);
|
|
247
|
-
for (const [index, name] of vrm.getFacetNames(id).entries()) {
|
|
248
|
-
valToSlot.set(val[name], `${baseRef}:${index}`);
|
|
249
|
-
}
|
|
250
|
-
} else {
|
|
251
|
-
valToSlot.set(val, baseRef);
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
function deleteEntry(slot, val) {
|
|
256
|
-
if (!val) {
|
|
257
|
-
val = getValForSlot(slot);
|
|
258
|
-
}
|
|
259
|
-
slotToVal.delete(slot);
|
|
260
|
-
valToSlot.delete(val);
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
function assertAcceptableSyscallCapdataSize(_capdatas) {}
|
|
264
|
-
|
|
265
|
-
const maybeExportPromise = _vref => false;
|
|
266
|
-
|
|
267
|
-
return {
|
|
268
|
-
syscall,
|
|
269
|
-
allocateExportID,
|
|
270
|
-
allocateCollectionID,
|
|
271
|
-
getSlotForVal,
|
|
272
|
-
requiredValForSlot,
|
|
273
|
-
getValForSlot,
|
|
274
|
-
setValForSlot,
|
|
275
|
-
registerEntry,
|
|
276
|
-
valToSlot,
|
|
277
|
-
slotToVal,
|
|
278
|
-
convertValToSlot,
|
|
279
|
-
convertSlotToVal,
|
|
280
|
-
marshal,
|
|
281
|
-
deleteEntry,
|
|
282
|
-
FinalizationRegistry,
|
|
283
|
-
WeakRef,
|
|
284
|
-
WeakMap,
|
|
285
|
-
WeakSet,
|
|
286
|
-
addToPossiblyDeadSet,
|
|
287
|
-
addToPossiblyRetiredSet,
|
|
288
|
-
dumpStore,
|
|
289
|
-
setVrm,
|
|
290
|
-
assertAcceptableSyscallCapdataSize,
|
|
291
|
-
maybeExportPromise,
|
|
292
|
-
};
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
export function makeFakeVirtualReferenceManager(
|
|
296
|
-
fakeStuff,
|
|
297
|
-
relaxDurabilityRules = true,
|
|
298
|
-
) {
|
|
299
|
-
return makeVirtualReferenceManager(
|
|
300
|
-
fakeStuff.syscall,
|
|
301
|
-
fakeStuff.getSlotForVal,
|
|
302
|
-
fakeStuff.getValForSlot,
|
|
303
|
-
fakeStuff.FinalizationRegistry,
|
|
304
|
-
fakeStuff.WeakRef,
|
|
305
|
-
fakeStuff.addToPossiblyDeadSet,
|
|
306
|
-
fakeStuff.addToPossiblyRetiredSet,
|
|
307
|
-
relaxDurabilityRules,
|
|
308
|
-
);
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
export function makeFakeWatchedPromiseManager(
|
|
312
|
-
vrm,
|
|
313
|
-
vom,
|
|
314
|
-
collectionManager,
|
|
315
|
-
fakeStuff,
|
|
316
|
-
) {
|
|
317
|
-
return makeWatchedPromiseManager({
|
|
318
|
-
syscall: fakeStuff.syscall,
|
|
319
|
-
vrm,
|
|
320
|
-
vom,
|
|
321
|
-
collectionManager,
|
|
322
|
-
convertValToSlot: fakeStuff.convertValToSlot,
|
|
323
|
-
convertSlotToVal: fakeStuff.convertSlotToVal,
|
|
324
|
-
maybeExportPromise: fakeStuff.maybeExportPromise,
|
|
325
|
-
});
|
|
326
|
-
}
|
|
327
|
-
/**
|
|
328
|
-
* Configure virtual stuff with relaxed durability rules and fake liveslots
|
|
329
|
-
*
|
|
330
|
-
* @param {object} [options]
|
|
331
|
-
* @param {number} [options.cacheSize]
|
|
332
|
-
* @param {boolean} [options.relaxDurabilityRules]
|
|
333
|
-
* @param {Map<any, any>} [options.fakeStore]
|
|
334
|
-
* @param {WeakMapConstructor} [options.WeakMap]
|
|
335
|
-
* @param {WeakSetConstructor} [options.WeakSet]
|
|
336
|
-
* @param {boolean} [options.weak]
|
|
337
|
-
*/
|
|
338
|
-
export function makeFakeVirtualStuff(options = {}) {
|
|
339
|
-
const actualOptions = {
|
|
340
|
-
relaxDurabilityRules: true,
|
|
341
|
-
...options,
|
|
342
|
-
};
|
|
343
|
-
const { relaxDurabilityRules } = actualOptions;
|
|
344
|
-
const fakeStuff = makeFakeLiveSlotsStuff(actualOptions);
|
|
345
|
-
const vrm = makeFakeVirtualReferenceManager(fakeStuff, relaxDurabilityRules);
|
|
346
|
-
fakeStuff.setVrm(vrm);
|
|
347
|
-
const vom = makeFakeVirtualObjectManager(vrm, fakeStuff);
|
|
348
|
-
vom.initializeKindHandleKind();
|
|
349
|
-
const cm = makeFakeCollectionManager(vrm, fakeStuff, actualOptions);
|
|
350
|
-
const wpm = makeFakeWatchedPromiseManager(vrm, vom, cm, fakeStuff);
|
|
351
|
-
return { fakeStuff, vrm, vom, cm, wpm };
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
export function makeStandaloneFakeVirtualObjectManager(options = {}) {
|
|
355
|
-
const fakeStuff = makeFakeLiveSlotsStuff(options);
|
|
356
|
-
const { relaxDurabilityRules = true } = options;
|
|
357
|
-
const vrm = makeFakeVirtualReferenceManager(fakeStuff, relaxDurabilityRules);
|
|
358
|
-
fakeStuff.setVrm(vrm);
|
|
359
|
-
const vom = makeFakeVirtualObjectManager(vrm, fakeStuff);
|
|
360
|
-
vom.initializeKindHandleKind();
|
|
361
|
-
return vom;
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
export function makeStandaloneFakeCollectionManager(options = {}) {
|
|
365
|
-
const fakeStuff = makeFakeLiveSlotsStuff(options);
|
|
366
|
-
const { relaxDurabilityRules = true } = options;
|
|
367
|
-
const vrm = makeFakeVirtualReferenceManager(fakeStuff, relaxDurabilityRules);
|
|
368
|
-
fakeStuff.setVrm(vrm);
|
|
369
|
-
return makeFakeCollectionManager(vrm, fakeStuff, options);
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
export {
|
|
373
|
-
makeStandaloneFakeVirtualObjectManager as makeFakeVirtualObjectManager,
|
|
374
|
-
makeStandaloneFakeCollectionManager as makeFakeCollectionManager,
|
|
375
|
-
};
|