@agoric/swingset-vat 0.32.3-dev-31ed402.0 → 0.32.3-dev-af6e3fd.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 (2) hide show
  1. package/package.json +12 -12
  2. package/src/lib/kmarshal.js +81 -31
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agoric/swingset-vat",
3
- "version": "0.32.3-dev-31ed402.0+31ed402",
3
+ "version": "0.32.3-dev-af6e3fd.0+af6e3fd",
4
4
  "description": "Vat/Container Launcher",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
@@ -27,16 +27,16 @@
27
27
  "@types/yargs-parser": "^21.0.0"
28
28
  },
29
29
  "dependencies": {
30
- "@agoric/assert": "0.6.1-dev-31ed402.0+31ed402",
31
- "@agoric/internal": "0.3.3-dev-31ed402.0+31ed402",
32
- "@agoric/store": "0.9.3-dev-31ed402.0+31ed402",
33
- "@agoric/swing-store": "0.9.2-dev-31ed402.0+31ed402",
34
- "@agoric/swingset-liveslots": "0.10.3-dev-31ed402.0+31ed402",
35
- "@agoric/swingset-xsnap-supervisor": "0.10.3-dev-31ed402.0+31ed402",
36
- "@agoric/time": "0.3.3-dev-31ed402.0+31ed402",
37
- "@agoric/vat-data": "0.5.3-dev-31ed402.0+31ed402",
38
- "@agoric/xsnap": "0.14.3-dev-31ed402.0+31ed402",
39
- "@agoric/xsnap-lockdown": "0.14.1-dev-31ed402.0+31ed402",
30
+ "@agoric/assert": "0.6.1-dev-af6e3fd.0+af6e3fd",
31
+ "@agoric/internal": "0.3.3-dev-af6e3fd.0+af6e3fd",
32
+ "@agoric/store": "0.9.3-dev-af6e3fd.0+af6e3fd",
33
+ "@agoric/swing-store": "0.9.2-dev-af6e3fd.0+af6e3fd",
34
+ "@agoric/swingset-liveslots": "0.10.3-dev-af6e3fd.0+af6e3fd",
35
+ "@agoric/swingset-xsnap-supervisor": "0.10.3-dev-af6e3fd.0+af6e3fd",
36
+ "@agoric/time": "0.3.3-dev-af6e3fd.0+af6e3fd",
37
+ "@agoric/vat-data": "0.5.3-dev-af6e3fd.0+af6e3fd",
38
+ "@agoric/xsnap": "0.14.3-dev-af6e3fd.0+af6e3fd",
39
+ "@agoric/xsnap-lockdown": "0.14.1-dev-af6e3fd.0+af6e3fd",
40
40
  "@endo/base64": "^0.2.34",
41
41
  "@endo/bundle-source": "^2.7.0",
42
42
  "@endo/captp": "^3.1.4",
@@ -97,5 +97,5 @@
97
97
  "publishConfig": {
98
98
  "access": "public"
99
99
  },
100
- "gitHead": "31ed40207648bb76e2b37cb82dd068fb1837fdd8"
100
+ "gitHead": "af6e3fd0cdc9097fd2a3d9fbf8047184e0d9aa4b"
101
101
  }
@@ -14,6 +14,85 @@ import { assert, Fail } from '@agoric/assert';
14
14
 
15
15
  const { toStringTag } = Symbol;
16
16
 
17
+ const makeStringStandinPromise = kref => {
18
+ const p = Promise.resolve(`${kref} stand in`);
19
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
20
+ Object.defineProperty(p, toStringTag, {
21
+ value: kref,
22
+ enumerable: false,
23
+ });
24
+ return harden(p);
25
+ };
26
+
27
+ const getStringStandinPromiseTag = p => {
28
+ const desc = Object.getOwnPropertyDescriptor(p, toStringTag);
29
+ assert(desc !== undefined, 'promise lacks own @@toStringTag property');
30
+ const kref = desc.value;
31
+ assert.typeof(kref, 'string');
32
+ return kref;
33
+ };
34
+
35
+ const makeAccessorStandinPromise = kref => {
36
+ // TODO This Bizarro world hack is only for the version of Endo that
37
+ // agoric-sdk currently depends on, and is already inconsistent with
38
+ // the "current" endo. Once agoric-sdk depends only on the next endo,
39
+ // we should delete this code, and rename `makeStringStandinPromise`
40
+ // above to `makeStandinPromise`.
41
+ //
42
+ // Bizarro World hack for attaching a string property to a Promise, courtesy
43
+ // of MarkM. Even though the @@toStringTag property nominally *is* a
44
+ // string, some unfortunate stuff in our hardened JS safety checks blows up
45
+ // if it actually is. Eventually that will be fixed and we'll be able to
46
+ // use the @@toStringTag property directly, but for now we need to use this
47
+ // weird construct employing a sneaky getter function. Note that this is
48
+ // only necessary in the first place because smallcaps encodes promise
49
+ // references differently from remotable object references, and the current
50
+ // version of the smallcaps decoder annoyingly insists that if the encoded
51
+ // body string says a slot is a promise, then convertSlotToVal had better by
52
+ // damn return an actual Promise, even if, as in the intended use case here,
53
+ // we neither want nor need a promise nor are capable of making any use of
54
+ // the fact that it is one.
55
+ const p = Promise.resolve(`${kref} stand in`);
56
+ // Bizarro World makes eslint hallucinate
57
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
58
+ Object.defineProperty(p, toStringTag, {
59
+ get: reveal => (reveal ? kref : NaN),
60
+ enumerable: false,
61
+ });
62
+ return harden(p);
63
+ };
64
+
65
+ const getAccessorStandinPromiseTag = p => {
66
+ // Other half of Bizarro World hack for handling promises. Note the
67
+ // peculiar way the @@toStringTag getter is used.
68
+ const desc = Object.getOwnPropertyDescriptor(p, toStringTag);
69
+ assert(desc !== undefined, 'promise lacks toStringTag getter');
70
+
71
+ const getter = desc.get;
72
+ assert.typeof(getter, 'function', 'toStringTag getter is not a function');
73
+ // @ts-expect-error violates the norm that getters have zero parameters
74
+ const kref = getter(true);
75
+ assert.typeof(kref, 'string');
76
+ return kref;
77
+ };
78
+
79
+ const [makeStandinPromise, getStandinPromiseTag] = (() => {
80
+ // Use whatever works
81
+ try {
82
+ const p = makeStringStandinPromise('string mascot');
83
+ assert(passStyleOf(p) === 'promise');
84
+ return [makeStringStandinPromise, getStringStandinPromiseTag];
85
+ } catch (_1) {
86
+ try {
87
+ const p = makeAccessorStandinPromise('accessor mascot');
88
+ assert(passStyleOf(p) === 'promise');
89
+ return [makeAccessorStandinPromise, getAccessorStandinPromiseTag];
90
+ } catch (_2) {
91
+ throw Error('One of the promise tagging schemes should have worked');
92
+ }
93
+ }
94
+ })();
95
+
17
96
  /**
18
97
  * @param {string} kref
19
98
  * @param {string} [iface]
@@ -32,27 +111,7 @@ export const kslot = (kref, iface = 'undefined') => {
32
111
  kref.startsWith('lp') ||
33
112
  kref.startsWith('rp')
34
113
  ) {
35
- // Bizarro World hack for attaching a string property to a Promise, courtesy
36
- // of MarkM. Even though the @@toStringTag property nominally *is* a
37
- // string, some unfortunate stuff in our hardened JS safety checks blows up
38
- // if it actually is. Eventually that will be fixed and we'll be able to
39
- // use the @@toStringTag property directly, but for now we need to use this
40
- // weird construct employing a sneaky getter function. Note that this is
41
- // only necessary in the first place because smallcaps encodes promise
42
- // references differently from remotable object references, and the current
43
- // version of the smallcaps decoder annoyingly insists that if the encoded
44
- // body string says a slot is a promise, then convertSlotToVal had better by
45
- // damn return an actual Promise, even if, as in the intended use case here,
46
- // we neither want nor need a promise nor are capable of making any use of
47
- // the fact that it is one.
48
- const p = Promise.resolve(`${kref} stand in`);
49
- // Bizarro World makes eslint hallucinate
50
- // eslint-disable-next-line @typescript-eslint/no-floating-promises
51
- Object.defineProperty(p, toStringTag, {
52
- get: reveal => (reveal ? kref : NaN),
53
- enumerable: false,
54
- });
55
- return harden(p);
114
+ return makeStandinPromise(kref);
56
115
  } else {
57
116
  const o = Far(iface, {
58
117
  iface: () => iface,
@@ -69,16 +128,7 @@ export const kslot = (kref, iface = 'undefined') => {
69
128
  export const krefOf = obj => {
70
129
  switch (passStyleOf(obj)) {
71
130
  case 'promise': {
72
- // Other half of Bizarro World hack for handling promises. Note the
73
- // peculiar way the @@toStringTag getter is used.
74
- const desc = Object.getOwnPropertyDescriptor(obj, toStringTag);
75
- assert(desc !== undefined, 'promise lacks toStringTag getter');
76
- const getter = desc.get;
77
- assert.typeof(getter, 'function', 'toStringTag getter is not a function');
78
- // @ts-expect-error violates the norm that getters have zero parameters
79
- const kref = getter(true);
80
- assert.typeof(kref, 'string');
81
- return kref;
131
+ return getStandinPromiseTag(obj);
82
132
  }
83
133
  case 'remotable': {
84
134
  const getKref = obj.getKref;