@agoric/swingset-liveslots 0.10.3-u13.0 → 0.10.3-u16.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.
Files changed (60) hide show
  1. package/README.md +2 -0
  2. package/package.json +27 -19
  3. package/src/cache.js +2 -1
  4. package/src/capdata.js +0 -1
  5. package/src/collectionManager.js +154 -72
  6. package/src/index.js +4 -1
  7. package/src/liveslots.js +52 -81
  8. package/src/message.js +4 -4
  9. package/src/types.js +8 -2
  10. package/src/vatDataTypes.d.ts +271 -0
  11. package/src/vatDataTypes.js +2 -0
  12. package/src/vatstore-iterators.js +2 -0
  13. package/src/virtualObjectManager.js +189 -70
  14. package/src/virtualReferences.js +51 -0
  15. package/src/watchedPromises.js +61 -16
  16. package/test/{test-baggage.js → baggage.test.js} +1 -2
  17. package/test/{test-cache.js → cache.test.js} +0 -1
  18. package/test/{test-collection-schema-refcount.js → collection-schema-refcount.test.js} +1 -2
  19. package/test/{test-collection-upgrade.js → collection-upgrade.test.js} +1 -3
  20. package/test/{test-collections.js → collections.test.js} +117 -14
  21. package/test/{test-dropped-collection-weakrefs.js → dropped-collection-weakrefs.test.js} +1 -2
  22. package/test/{test-durabilityChecks.js → durabilityChecks.test.js} +3 -3
  23. package/test/{test-facetiousness.js → facetiousness.test.js} +1 -2
  24. package/test/gc-and-finalize.js +30 -1
  25. package/test/gc-helpers.js +2 -3
  26. package/test/{test-gc-sensitivity.js → gc-sensitivity.test.js} +2 -2
  27. package/test/{test-handled-promises.js → handled-promises.test.js} +5 -7
  28. package/test/{test-initial-vrefs.js → initial-vrefs.test.js} +2 -3
  29. package/test/liveslots-helpers.js +6 -6
  30. package/test/{test-liveslots-mock-gc.js → liveslots-mock-gc.test.js} +2 -2
  31. package/test/{test-liveslots-real-gc.js → liveslots-real-gc.test.js} +44 -35
  32. package/test/{test-liveslots.js → liveslots.test.js} +13 -14
  33. package/test/mock-gc.js +1 -0
  34. package/test/storeGC/{test-lifecycle.js → lifecycle.test.js} +2 -2
  35. package/test/storeGC/{test-refcount-management.js → refcount-management.test.js} +1 -2
  36. package/test/storeGC/{test-scalar-store-kind.js → scalar-store-kind.test.js} +0 -1
  37. package/test/storeGC/{test-weak-key.js → weak-key.test.js} +1 -2
  38. package/test/util.js +2 -2
  39. package/test/vat-util.js +1 -1
  40. package/test/virtual-objects/{test-cease-recognition.js → cease-recognition.test.js} +2 -2
  41. package/test/virtual-objects/{test-cross-facet.js → cross-facet.test.js} +5 -4
  42. package/test/virtual-objects/{test-empty-data.js → empty-data.test.js} +1 -2
  43. package/test/virtual-objects/{test-facets.js → facets.test.js} +1 -2
  44. package/test/virtual-objects/{test-kind-changes.js → kind-changes.test.js} +2 -2
  45. package/test/virtual-objects/{test-reachable-vrefs.js → reachable-vrefs.test.js} +2 -2
  46. package/test/virtual-objects/{test-rep-tostring.js → rep-tostring.test.js} +2 -3
  47. package/test/virtual-objects/{test-retain-remotable.js → retain-remotable.test.js} +25 -24
  48. package/test/virtual-objects/{test-state-shape.js → state-shape.test.js} +2 -2
  49. package/test/virtual-objects/{test-virtualObjectGC.js → virtualObjectGC.test.js} +2 -2
  50. package/test/virtual-objects/{test-virtualObjectManager.js → virtualObjectManager.test.js} +126 -8
  51. package/test/virtual-objects/{test-vo-real-gc.js → vo-real-gc.test.js} +8 -8
  52. package/test/virtual-objects/{test-weakcollections-vref-handling.js → weakcollections-vref-handling.test.js} +1 -2
  53. package/test/{test-vo-test-harness.js → vo-test-harness.test.js} +0 -1
  54. package/test/{test-vpid-liveslots.js → vpid-liveslots.test.js} +4 -5
  55. package/test/waitUntilQuiescent.js +2 -1
  56. package/tools/fakeVirtualSupport.js +51 -21
  57. package/tools/prepare-test-env.js +13 -0
  58. package/tools/setup-vat-data.js +62 -0
  59. package/CHANGELOG.md +0 -85
  60. package/test/kmarshal.js +0 -79
@@ -1,14 +1,23 @@
1
- /* global WeakRef */
1
+ /* global globalThis */
2
2
  /* eslint-disable max-classes-per-file */
3
3
  import { makeMarshal } from '@endo/marshal';
4
4
  import { assert } from '@agoric/assert';
5
- import { parseVatSlot } from '../src/parseVatSlots.js';
5
+ import { isPromise } from '@endo/promise-kit';
6
6
 
7
+ import { parseVatSlot } from '../src/parseVatSlots.js';
7
8
  import { makeVirtualReferenceManager } from '../src/virtualReferences.js';
8
9
  import { makeWatchedPromiseManager } from '../src/watchedPromises.js';
9
10
  import { makeFakeVirtualObjectManager } from './fakeVirtualObjectManager.js';
10
11
  import { makeFakeCollectionManager } from './fakeCollectionManager.js';
11
12
 
13
+ const { Fail } = assert;
14
+
15
+ const {
16
+ WeakRef: RealWeakRef,
17
+ WeakMap: RealWeakMap,
18
+ WeakSet: RealWeakSet,
19
+ } = globalThis;
20
+
12
21
  class FakeFinalizationRegistry {
13
22
  // eslint-disable-next-line no-useless-constructor, no-empty-function
14
23
  constructor() {}
@@ -30,8 +39,6 @@ class FakeWeakRef {
30
39
  }
31
40
  }
32
41
 
33
- const RealWeakRef = WeakRef;
34
-
35
42
  export function makeFakeLiveSlotsStuff(options = {}) {
36
43
  let vrm;
37
44
  function setVrm(vrmToUse) {
@@ -45,6 +52,8 @@ export function makeFakeLiveSlotsStuff(options = {}) {
45
52
  log,
46
53
  FinalizationRegistry = FakeFinalizationRegistry,
47
54
  WeakRef = FakeWeakRef, // VRM uses this
55
+ WeakMap = RealWeakMap,
56
+ WeakSet = RealWeakSet,
48
57
  addToPossiblyDeadSet = () => {},
49
58
  addToPossiblyRetiredSet = () => {},
50
59
  } = options;
@@ -151,18 +160,16 @@ export function makeFakeLiveSlotsStuff(options = {}) {
151
160
  },
152
161
  };
153
162
 
154
- let nextExportID = 1;
155
163
  function allocateExportID() {
156
- const exportID = nextExportID;
157
- nextExportID += 1;
158
- return exportID;
164
+ return vrm.allocateNextID('exportID');
165
+ }
166
+
167
+ function allocatePromiseID() {
168
+ return vrm.allocateNextID('promiseID');
159
169
  }
160
170
 
161
- let nextCollectionID = 1;
162
171
  function allocateCollectionID() {
163
- const collectionID = nextCollectionID;
164
- nextCollectionID += 1;
165
- return collectionID;
172
+ return vrm.allocateNextID('collectionID');
166
173
  }
167
174
 
168
175
  // note: The real liveslots slotToVal() maps slots (vrefs) to a WeakRef,
@@ -193,7 +200,9 @@ export function makeFakeLiveSlotsStuff(options = {}) {
193
200
 
194
201
  function convertValToSlot(val) {
195
202
  if (!valToSlot.has(val)) {
196
- const slot = `o+${allocateExportID()}`;
203
+ const slot = isPromise(val)
204
+ ? `p+${allocatePromiseID()}`
205
+ : `o+${allocateExportID()}`;
197
206
  valToSlot.set(val, slot);
198
207
  setValForSlot(slot, val);
199
208
  }
@@ -212,30 +221,42 @@ export function makeFakeLiveSlotsStuff(options = {}) {
212
221
  }
213
222
  return val;
214
223
  }
224
+ let result;
215
225
  if (virtual || durable) {
216
226
  if (vrm) {
217
227
  val = vrm.reanimate(slot);
218
228
  if (facet !== undefined) {
219
- return vrm.getFacet(id, val, facet);
229
+ result = vrm.getFacet(id, val, facet);
220
230
  }
221
231
  } else {
222
232
  assert.fail('fake liveSlots stuff configured without vrm');
223
233
  }
224
234
  }
225
- return val;
235
+ // eslint-disable-next-line no-use-before-define
236
+ registerEntry(baseRef, val, facet !== undefined);
237
+ if (!result) {
238
+ result = val;
239
+ }
240
+ return result;
226
241
  }
227
242
 
228
243
  const marshal = makeMarshal(convertValToSlot, convertSlotToVal, {
229
244
  serializeBodyFormat: 'smallcaps',
245
+ marshalName: 'fakeLiveSlots',
246
+ errorIdNum: 80_000,
247
+ marshalSaveError: _err => {},
230
248
  });
231
249
 
232
250
  function registerEntry(baseRef, val, valIsCohort) {
251
+ const { facet } = parseVatSlot(baseRef);
252
+ !facet ||
253
+ Fail`registerEntry(${baseRef} should not receive individual facets`;
233
254
  setValForSlot(baseRef, val);
234
255
  if (valIsCohort) {
235
256
  const { id } = parseVatSlot(baseRef);
236
- vrm.getFacetNames(id).forEach((name, index) => {
257
+ for (const [index, name] of vrm.getFacetNames(id).entries()) {
237
258
  valToSlot.set(val[name], `${baseRef}:${index}`);
238
- });
259
+ }
239
260
  } else {
240
261
  valToSlot.set(val, baseRef);
241
262
  }
@@ -270,6 +291,8 @@ export function makeFakeLiveSlotsStuff(options = {}) {
270
291
  deleteEntry,
271
292
  FinalizationRegistry,
272
293
  WeakRef,
294
+ WeakMap,
295
+ WeakSet,
273
296
  addToPossiblyDeadSet,
274
297
  addToPossiblyRetiredSet,
275
298
  dumpStore,
@@ -311,12 +334,17 @@ export function makeFakeWatchedPromiseManager(
311
334
  maybeExportPromise: fakeStuff.maybeExportPromise,
312
335
  });
313
336
  }
337
+
314
338
  /**
315
339
  * Configure virtual stuff with relaxed durability rules and fake liveslots
316
340
  *
317
341
  * @param {object} [options]
318
- * @param {number} [options.cacheSize=3]
319
- * @param {boolean} [options.relaxDurabilityRules=true]
342
+ * @param {number} [options.cacheSize]
343
+ * @param {boolean} [options.relaxDurabilityRules]
344
+ * @param {Map<any, any>} [options.fakeStore]
345
+ * @param {WeakMapConstructor} [options.WeakMap]
346
+ * @param {WeakSetConstructor} [options.WeakSet]
347
+ * @param {boolean} [options.weak]
320
348
  */
321
349
  export function makeFakeVirtualStuff(options = {}) {
322
350
  const actualOptions = {
@@ -326,11 +354,12 @@ export function makeFakeVirtualStuff(options = {}) {
326
354
  const { relaxDurabilityRules } = actualOptions;
327
355
  const fakeStuff = makeFakeLiveSlotsStuff(actualOptions);
328
356
  const vrm = makeFakeVirtualReferenceManager(fakeStuff, relaxDurabilityRules);
357
+ fakeStuff.setVrm(vrm);
329
358
  const vom = makeFakeVirtualObjectManager(vrm, fakeStuff);
330
359
  vom.initializeKindHandleKind();
331
- fakeStuff.setVrm(vrm);
332
360
  const cm = makeFakeCollectionManager(vrm, fakeStuff, actualOptions);
333
361
  const wpm = makeFakeWatchedPromiseManager(vrm, vom, cm, fakeStuff);
362
+ wpm.preparePromiseWatcherTables();
334
363
  return { fakeStuff, vrm, vom, cm, wpm };
335
364
  }
336
365
 
@@ -338,9 +367,9 @@ export function makeStandaloneFakeVirtualObjectManager(options = {}) {
338
367
  const fakeStuff = makeFakeLiveSlotsStuff(options);
339
368
  const { relaxDurabilityRules = true } = options;
340
369
  const vrm = makeFakeVirtualReferenceManager(fakeStuff, relaxDurabilityRules);
370
+ fakeStuff.setVrm(vrm);
341
371
  const vom = makeFakeVirtualObjectManager(vrm, fakeStuff);
342
372
  vom.initializeKindHandleKind();
343
- fakeStuff.setVrm(vrm);
344
373
  return vom;
345
374
  }
346
375
 
@@ -348,6 +377,7 @@ export function makeStandaloneFakeCollectionManager(options = {}) {
348
377
  const fakeStuff = makeFakeLiveSlotsStuff(options);
349
378
  const { relaxDurabilityRules = true } = options;
350
379
  const vrm = makeFakeVirtualReferenceManager(fakeStuff, relaxDurabilityRules);
380
+ fakeStuff.setVrm(vrm);
351
381
  return makeFakeCollectionManager(vrm, fakeStuff, options);
352
382
  }
353
383
 
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Prepare Agoric SwingSet vat global environment for testing.
3
+ *
4
+ * Installs Hardened JS (and does lockdown), plus adds mocks for virtual objects
5
+ * and stores.
6
+ */
7
+
8
+ import '@agoric/internal/src/install-ses-debug.js';
9
+
10
+ import { reincarnate } from './setup-vat-data.js';
11
+
12
+ // Install the VatData globals.
13
+ reincarnate();
@@ -0,0 +1,62 @@
1
+ // @ts-check
2
+ /* global globalThis */
3
+ // This file produces the globalThis.VatData property outside of a running
4
+ // SwingSet so that it can be used by '@agoric/vat-data' (which only *consumes*
5
+ // `globalThis.VatData`) in code under test.
6
+ import { makeFakeVirtualStuff } from './fakeVirtualSupport.js';
7
+
8
+ const { WeakMap, WeakSet } = globalThis;
9
+
10
+ /** @type {ReturnType<makeFakeVirtualStuff>} */
11
+ let fakeVomKit;
12
+
13
+ globalThis.VatData = harden({
14
+ // @ts-expect-error spread argument for non-rest parameter
15
+ defineKind: (...args) => fakeVomKit.vom.defineKind(...args),
16
+ // @ts-expect-error spread argument for non-rest parameter
17
+ defineKindMulti: (...args) => fakeVomKit.vom.defineKindMulti(...args),
18
+ // @ts-expect-error spread argument for non-rest parameter
19
+ defineDurableKind: (...args) => fakeVomKit.vom.defineDurableKind(...args),
20
+ defineDurableKindMulti: (...args) =>
21
+ // @ts-expect-error spread argument for non-rest parameter
22
+ fakeVomKit.vom.defineDurableKindMulti(...args),
23
+ makeKindHandle: tag => fakeVomKit.vom.makeKindHandle(tag),
24
+ canBeDurable: (...args) => fakeVomKit.vom.canBeDurable(...args),
25
+ providePromiseWatcher: (...args) =>
26
+ // @ts-expect-error spread argument for non-rest parameter
27
+ fakeVomKit.wpm.providePromiseWatcher(...args),
28
+ watchPromise: (p, watcher, ...args) =>
29
+ fakeVomKit.wpm.watchPromise(p, watcher, ...args),
30
+ makeScalarBigMapStore: (...args) =>
31
+ fakeVomKit.cm.makeScalarBigMapStore(...args),
32
+ makeScalarBigWeakMapStore: (...args) =>
33
+ fakeVomKit.cm.makeScalarBigWeakMapStore(...args),
34
+ makeScalarBigSetStore: (...args) =>
35
+ fakeVomKit.cm.makeScalarBigSetStore(...args),
36
+ makeScalarBigWeakSetStore: (...args) =>
37
+ fakeVomKit.cm.makeScalarBigWeakSetStore(...args),
38
+ });
39
+
40
+ export const reincarnate = (options = {}) => {
41
+ const { fakeStore = new Map(), fakeVomKit: fvk } = options;
42
+
43
+ if (options.fakeVomKit) {
44
+ fvk.vom.flushStateCache();
45
+ fvk.cm.flushSchemaCache();
46
+ fvk.vrm.flushIDCounters();
47
+ }
48
+
49
+ fakeVomKit = makeFakeVirtualStuff({
50
+ ...options,
51
+ fakeStore,
52
+ WeakMap,
53
+ WeakSet,
54
+ });
55
+
56
+ // @ts-expect-error toStringTag set imperatively so it doesn't show up in the type
57
+ globalThis.WeakMap = fakeVomKit.vom.VirtualObjectAwareWeakMap;
58
+ // @ts-expect-error ditto
59
+ globalThis.WeakSet = fakeVomKit.vom.VirtualObjectAwareWeakSet;
60
+
61
+ return { ...options, fakeStore, fakeVomKit };
62
+ };
package/CHANGELOG.md DELETED
@@ -1,85 +0,0 @@
1
- # Change Log
2
-
3
- All notable changes to this project will be documented in this file.
4
- See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
-
6
- ### [0.10.3-u13.0](https://github.com/Agoric/agoric-sdk/compare/@agoric/swingset-liveslots@0.10.3-u12.0...@agoric/swingset-liveslots@0.10.3-u13.0) (2023-12-07)
7
-
8
- **Note:** Version bump only for package @agoric/swingset-liveslots
9
-
10
-
11
-
12
-
13
-
14
- ### [0.10.3-u12.0](https://github.com/Agoric/agoric-sdk/compare/@agoric/swingset-liveslots@0.10.3-u11wf.0...@agoric/swingset-liveslots@0.10.3-u12.0) (2023-11-10)
15
-
16
- **Note:** Version bump only for package @agoric/swingset-liveslots
17
-
18
-
19
-
20
-
21
-
22
- ### [0.10.3-u11wf.0](https://github.com/Agoric/agoric-sdk/compare/@agoric/swingset-liveslots@0.10.3-u11.0...@agoric/swingset-liveslots@0.10.3-u11wf.0) (2023-09-23)
23
-
24
- **Note:** Version bump only for package @agoric/swingset-liveslots
25
-
26
-
27
-
28
-
29
-
30
- ### [0.10.3-u11.0](https://github.com/Agoric/agoric-sdk/compare/@agoric/swingset-liveslots@0.10.2...@agoric/swingset-liveslots@0.10.3-u11.0) (2023-08-24)
31
-
32
- **Note:** Version bump only for package @agoric/swingset-liveslots
33
-
34
-
35
-
36
-
37
-
38
- ### [0.10.2](https://github.com/Agoric/agoric-sdk/compare/@agoric/swingset-liveslots@0.10.1...@agoric/swingset-liveslots@0.10.2) (2023-06-02)
39
-
40
- **Note:** Version bump only for package @agoric/swingset-liveslots
41
-
42
-
43
-
44
-
45
-
46
- ### [0.10.1](https://github.com/Agoric/agoric-sdk/compare/@agoric/swingset-liveslots@0.10.0...@agoric/swingset-liveslots@0.10.1) (2023-05-24)
47
-
48
- **Note:** Version bump only for package @agoric/swingset-liveslots
49
-
50
-
51
-
52
-
53
-
54
- ## 0.10.0 (2023-05-19)
55
-
56
-
57
- ### Features
58
-
59
- * better diagnostic for failed reanimate ([c0c9c94](https://github.com/Agoric/agoric-sdk/commit/c0c9c9433648d520aa2bcdbadbbfe877831567c7)), closes [Error#1](https://github.com/Agoric/Error/issues/1)
60
- * **swingset-liveslots:** label virtual instances ([4191eb6](https://github.com/Agoric/agoric-sdk/commit/4191eb62d0e64048c3c715e5f71a53a747267350))
61
- * add APIs for tracking/debugging undesired object retention (aka "leaks") ([0a7221b](https://github.com/Agoric/agoric-sdk/commit/0a7221b3c04f3b2894c30346fa2ea6fb0130c046)), closes [#7318](https://github.com/Agoric/agoric-sdk/issues/7318)
62
- * move liveslots and specific tests to a new package ([0921a89](https://github.com/Agoric/agoric-sdk/commit/0921a8903b72cfefdf05a5906bcfb826cac1cc2f)), closes [#6596](https://github.com/Agoric/agoric-sdk/issues/6596)
63
-
64
-
65
- ### Bug Fixes
66
-
67
- * **liveslots:** allow new Kind upgrade to add new facets ([6bc6694](https://github.com/Agoric/agoric-sdk/commit/6bc6694968e6d2f529e7c91ec1efb11fdff2e2d3)), closes [#7437](https://github.com/Agoric/agoric-sdk/issues/7437)
68
- * **liveslots:** retain WeakRefs to voAware collections ([3935723](https://github.com/Agoric/agoric-sdk/commit/393572396781afd17691e1366abeba696228a24e)), closes [#7371](https://github.com/Agoric/agoric-sdk/issues/7371)
69
- * **swingset-liveslots:** prevent VOM infinite loop if `globalThis.WeakSet` etc are replaced ([d7b35e2](https://github.com/Agoric/agoric-sdk/commit/d7b35e28715a715ef510f2717e0040fa017caab4))
70
- * adding dup entries to virtual sets is OK ([c81d367](https://github.com/Agoric/agoric-sdk/commit/c81d3677d8085eb4debe5baa416816ff94d582cf)), closes [#7234](https://github.com/Agoric/agoric-sdk/issues/7234)
71
- * code updates for new marshal ([292f971](https://github.com/Agoric/agoric-sdk/commit/292f971769db69e61782f96638c2f687c3f95ac2))
72
- * **SwingSet:** Don't send stopVat during upgrade ([5cc47d2](https://github.com/Agoric/agoric-sdk/commit/5cc47d2d8892690f8c1653630b41dd64cc42d73b)), closes [#6650](https://github.com/Agoric/agoric-sdk/issues/6650)
73
- * **types:** return value of deleter ([457f576](https://github.com/Agoric/agoric-sdk/commit/457f5765b9fc0a693e6eb5e6644ddf4af3b791db))
74
- * move many type definitions from swingset to liveslots ([727143d](https://github.com/Agoric/agoric-sdk/commit/727143d5562498e2e3013c34304f229b4dd11da5))
75
- * move rejectAllPromises from stopVat to kernels-side upgradeVat ([d79623f](https://github.com/Agoric/agoric-sdk/commit/d79623f3fb3b87653dba1c71eb1153711c9d962c)), closes [#6694](https://github.com/Agoric/agoric-sdk/issues/6694)
76
- * Move upgrade-time abandonExports responsibility into the kernel ([66ac657](https://github.com/Agoric/agoric-sdk/commit/66ac657d51d3d1be61ee4a6e9a621a664086ee57)), closes [#6696](https://github.com/Agoric/agoric-sdk/issues/6696)
77
- * only the exo api change ([5cf3bf1](https://github.com/Agoric/agoric-sdk/commit/5cf3bf10a71dd02094365a66e87032e5d17d004f))
78
- * **liveslots:** use Map for vrefStatus, not object ([1456e2a](https://github.com/Agoric/agoric-sdk/commit/1456e2ae006bb1c702383cedda5e5c407968840e))
79
- * **swingset:** move a bunch of types from swingset to swingset-liveslots ([14f9bb0](https://github.com/Agoric/agoric-sdk/commit/14f9bb00c82c085dc647f23b6c90b26e6a0a6dfd))
80
- * **swingset-liveslots:** Move promise rejection responsibility into the kernel ([dd29ff3](https://github.com/Agoric/agoric-sdk/commit/dd29ff35c5dc72efbbf7087849182aa7f04b2bb1)), closes [#6694](https://github.com/Agoric/agoric-sdk/issues/6694)
81
- * add 'v'/'d' virtual/durable annotations to vrefs ([b859e92](https://github.com/Agoric/agoric-sdk/commit/b859e92fe041415d6e34250f672a10ad927aa33e)), closes [#6695](https://github.com/Agoric/agoric-sdk/issues/6695)
82
- * update description of "FINALIZED" state ([809f366](https://github.com/Agoric/agoric-sdk/commit/809f3660c083467e76deb1487015cb24205a801d))
83
- * without assertKeyPattern ([#7035](https://github.com/Agoric/agoric-sdk/issues/7035)) ([c9fcd7f](https://github.com/Agoric/agoric-sdk/commit/c9fcd7f82757732435cd96f3377e4fbfb6586ce7))
84
- * **swingset-liveslots:** copy helper files to new liveslots package ([be7229f](https://github.com/Agoric/agoric-sdk/commit/be7229f7217c1ecc523069a57945a372f4a1e00e))
85
- * **swingset-liveslots:** update imports of helper files ([0b4b38a](https://github.com/Agoric/agoric-sdk/commit/0b4b38a1f9efbb3e1e860172b0b802548d18ae2e))
package/test/kmarshal.js DELETED
@@ -1,79 +0,0 @@
1
- import { Far, makeMarshal, passStyleOf } from '@endo/marshal';
2
- import { assert } from '@agoric/assert';
3
-
4
- // Simple wrapper for serializing and unserializing marshalled values inside the
5
- // kernel, where we don't actually want to use clists nor actually allocate real
6
- // objects, but instead to stay entirely within the domain of krefs. This is
7
- // used to enable syntactic manipulation of serialized values while remaining
8
- // agnostic about the internal details of the serialization encoding.
9
-
10
- const refMap = new WeakMap();
11
-
12
- export const kslot = (kref, iface) => {
13
- assert.typeof(kref, 'string');
14
- if (iface && iface.startsWith('Alleged: ')) {
15
- // Encoder prepends "Alleged: " to iface string, but the decoder doesn't strip it
16
- // Unclear whether it's the decoder or me who is wrong
17
- iface = iface.slice(9);
18
- }
19
- if (
20
- kref.startsWith('p') ||
21
- kref.startsWith('kp') ||
22
- kref.startsWith('lp') ||
23
- kref.startsWith('rp')
24
- ) {
25
- // TODO: temporary hack because smallcaps encodes promise references
26
- // differently from remotable object references, and the current version of
27
- // the smallcaps decoder annoyingly insists that if the encoded body string
28
- // says a slot is a promise, then convertSlotToVal had better by damn return
29
- // an actual Promise, even if, as in the intended use case here, we neither
30
- // want nor need a promise, nor the overhead of a map to keep track of it
31
- // with. This behavior is in service of defense against a hypothesized
32
- // security issue whose exact nature has largely been forgotton in the
33
- // months since it was first encountered. MarkM is currently researching
34
- // what the problem was thought to have been, to see if it is real and to
35
- // understand it if so. This will eventually result in either changes to
36
- // the smallcaps encoding or to the marshal setup API to support the purely
37
- // manipulative use case. In the meantime, this ugliness...
38
- const p = new Promise(() => undefined);
39
- refMap.set(p, kref);
40
- return harden(p);
41
- } else {
42
- const o = Far(iface, {
43
- iface: () => iface,
44
- getKref: () => `${kref}`,
45
- });
46
- return o;
47
- }
48
- };
49
-
50
- export const krefOf = obj => {
51
- const fromMap = refMap.get(obj);
52
- if (fromMap) {
53
- return fromMap;
54
- }
55
- // When krefOf() is called as part of kmarshal.serialize, marshal
56
- // will only give it things that are 'remotable' (Promises and the
57
- // Far objects created by kslot()). When krefOf() is called by
58
- // kernel code (as part of extractSingleSlot() or the vat-comms
59
- // equivalent), it ought to throw if 'obj' is not one of the Far
60
- // objects created by our kslot().
61
- assert.equal(passStyleOf(obj), 'remotable', obj);
62
- const getKref = obj.getKref;
63
- assert.typeof(getKref, 'function');
64
- return getKref();
65
- };
66
-
67
- const kmarshal = makeMarshal(krefOf, kslot, {
68
- serializeBodyFormat: 'smallcaps',
69
- errorTagging: 'off',
70
- });
71
-
72
- export const kser = value => kmarshal.serialize(harden(value));
73
-
74
- export const kunser = serializedValue => kmarshal.unserialize(serializedValue);
75
-
76
- export function makeError(message) {
77
- assert.typeof(message, 'string');
78
- return kser(Error(message));
79
- }