Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(swingset-liveslots): endow passStyleOf to liveslots guest compartment #9874

Merged
merged 14 commits into from
Aug 17, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/SwingSet/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"@endo/init": "^1.1.3",
"@endo/marshal": "^1.5.2",
"@endo/nat": "^5.0.9",
"@endo/pass-style": "^1.4.2",
"@endo/patterns": "^1.4.2",
"@endo/promise-kit": "^1.1.4",
"@endo/ses-ava": "^1.2.4",
Expand Down
11 changes: 8 additions & 3 deletions packages/SwingSet/test/vat-env.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,18 @@ async function testForExpectedGlobals(t, workerType) {
'VatData.makeScalarBigWeakMapStore: function',
'VatData.makeScalarBigSetStore: function',
'VatData.makeScalarBigWeakSetStore: function',
'global has passStyleOf: true',
'global passStyleOf is special: false',
]);
}

test('expected globals are in the local worker vat environment', async t => {
await testForExpectedGlobals(t, 'local');
});

test('expected globals are in the XS worker vat environment', async t => {
await testForExpectedGlobals(t, 'xs-worker');
});
test.failing(
erights marked this conversation as resolved.
Show resolved Hide resolved
'expected globals are in the XS worker vat environment',
async t => {
await testForExpectedGlobals(t, 'xs-worker');
},
);
10 changes: 9 additions & 1 deletion packages/SwingSet/test/vat-envtest.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// @ts-nocheck
/* global VatData */
/* global VatData globalThis */
import { Far } from '@endo/far';
import { passStyleOf } from '@endo/pass-style';
import { PassStyleOfEndowmentSymbol } from '@endo/pass-style/endow.js';

export function buildRootObject(vatPowers) {
const log = vatPowers.testLog;
Expand All @@ -13,6 +15,12 @@ export function buildRootObject(vatPowers) {
for (const prop of Object.keys(VatData)) {
log(`VatData.${prop}: ${typeof VatData[prop]}`);
}
const globalPassStyleOf =
globalThis && globalThis[PassStyleOfEndowmentSymbol];
log(`global has passStyleOf: ${!!globalPassStyleOf}`);
log(
`global passStyleOf is special: ${globalPassStyleOf !== passStyleOf}`,
);
},
});
}
10 changes: 4 additions & 6 deletions packages/swingset-liveslots/src/liveslots.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import { annotateError, assert, Fail, makeError, X } from '@endo/errors';
import {
Remotable,
passStyleOf,
getInterfaceOf,
makeMarshal,
} from '@endo/marshal';
import { passStyleOf } from '@endo/pass-style';
import { PassStyleOfEndowmentSymbol } from '@endo/pass-style/endow.js';
import { Remotable, getInterfaceOf, makeMarshal } from '@endo/marshal';
import { isPromise } from '@endo/promise-kit';
import { E, HandledPromise } from '@endo/eventual-send';
import { insistVatType, makeVatSlot, parseVatSlot } from './parseVatSlots.js';
Expand Down Expand Up @@ -1363,6 +1360,7 @@ function build(
makeScalarBigSetStore: collectionManager.makeScalarBigSetStore,
makeScalarBigWeakSetStore: collectionManager.makeScalarBigWeakSetStore,
},
[PassStyleOfEndowmentSymbol]: passStyleOf,
});

const inescapableGlobalProperties = harden({
Expand Down
62 changes: 62 additions & 0 deletions packages/swingset-liveslots/test/vat-environment.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// @ts-nocheck
import '@endo/init/debug.js';
import test from 'ava';
import { Far } from '@endo/marshal';
import { kser } from '@agoric/kmarshal';
import { passStyleOf } from '@endo/pass-style';
import { PassStyleOfEndowmentSymbol } from '@endo/pass-style/endow.js';
import { makeLiveSlots } from '../src/index.js';
import { makeStartVat } from './util.js';
import { buildSyscall } from './liveslots-helpers.js';
import { makeMockGC } from './mock-gc.js';

test('vat globals', async t => {
const { syscall } = buildSyscall();
const gcTools = makeMockGC();
const buildRootObject = () => Far('root', {});
let called = 0;
let vatGlobals;
let inescapableGlobalProperties;
const vatNS = harden({ buildRootObject });
// buildVatNamespace
const bVN = async (vG, iGP) => {
called += 1;
vatGlobals = vG;
inescapableGlobalProperties = iGP;
return vatNS;
};

const ls = makeLiveSlots(syscall, 'vatA', {}, {}, gcTools, undefined, bVN);
t.is(called, 0); // not called yet
await ls.dispatch(makeStartVat(kser()));
t.is(called, 1);
t.truthy(vatGlobals);

// 'harden' is provided by SES (installed by the lockdown bundle),
// not liveslots
t.is(typeof vatGlobals.harden, 'undefined');

// but liveslots provides VatData
t.is(typeof vatGlobals.VatData, 'object');
t.is(typeof vatGlobals.VatData, 'object');
t.is(typeof vatGlobals.VatData.defineKind, 'function');
t.is(typeof vatGlobals.VatData.defineKindMulti, 'function');
t.is(typeof vatGlobals.VatData.defineDurableKind, 'function');
t.is(typeof vatGlobals.VatData.defineDurableKindMulti, 'function');
t.is(typeof vatGlobals.VatData.makeKindHandle, 'function');
t.is(typeof vatGlobals.VatData.canBeDurable, 'function');
t.is(typeof vatGlobals.VatData.providePromiseWatcher, 'function');
t.is(typeof vatGlobals.VatData.watchPromise, 'function');
t.is(typeof vatGlobals.VatData.makeScalarBigMapStore, 'function');
t.is(typeof vatGlobals.VatData.makeScalarBigWeakMapStore, 'function');
t.is(typeof vatGlobals.VatData.makeScalarBigSetStore, 'function');
t.is(typeof vatGlobals.VatData.makeScalarBigWeakSetStore, 'function');
t.is(typeof vatGlobals[PassStyleOfEndowmentSymbol], 'function');
// this is the passStyleOf created by liveslots, with a real WeakMap
t.is(vatGlobals[PassStyleOfEndowmentSymbol], passStyleOf);

t.is(typeof inescapableGlobalProperties.WeakMap, 'function');
t.not(inescapableGlobalProperties.WeakMap, WeakMap);
t.is(typeof inescapableGlobalProperties.WeakSet, 'function');
t.not(inescapableGlobalProperties.WeakSet, WeakSet);
});
13 changes: 10 additions & 3 deletions packages/swingset-liveslots/tools/setup-vat-data.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
// @ts-check
/* global globalThis */
// This file produces the globalThis.VatData property outside of a running
// SwingSet so that it can be used by '@agoric/vat-data' (which only *consumes*
// `globalThis.VatData`) in code under test.

// This file produces the globalThis.VatData property outside of a
// running SwingSet so that it can be used by '@agoric/vat-data'
// (which only *consumes* `globalThis.VatData`) in code under test. It
// also populates the passStyleOf symbol-named property.

import { passStyleOf } from '@endo/pass-style';
import { PassStyleOfEndowmentSymbol } from '@endo/pass-style/endow.js';
import { makeFakeVirtualStuff } from './fakeVirtualSupport.js';

const { WeakMap, WeakSet } = globalThis;
Expand Down Expand Up @@ -37,6 +42,8 @@ globalThis.VatData = harden({
fakeVomKit.cm.makeScalarBigWeakSetStore(...args),
});

globalThis[PassStyleOfEndowmentSymbol] = passStyleOf;

export const reincarnate = (options = {}) => {
const { fakeStore = new Map(), fakeVomKit: fvk } = options;

Expand Down
1 change: 1 addition & 0 deletions packages/vats/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"@endo/import-bundle": "^1.2.1",
"@endo/marshal": "^1.5.2",
"@endo/nat": "^5.0.9",
"@endo/pass-style": "^1.4.2",
"@endo/patterns": "^1.4.2",
"@endo/promise-kit": "^1.1.4",
"import-meta-resolve": "^2.2.1",
Expand Down
29 changes: 29 additions & 0 deletions patches/@endo+compartment-mapper+1.2.1.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
diff --git a/node_modules/@endo/compartment-mapper/src/policy.js b/node_modules/@endo/compartment-mapper/src/policy.js
index ee2a8fb..98af69a 100644
--- a/node_modules/@endo/compartment-mapper/src/policy.js
+++ b/node_modules/@endo/compartment-mapper/src/policy.js
@@ -10,7 +10,9 @@ import {
policyLookupHelper,
} from './policy-format.js';

-const { create, entries, values, assign, keys, freeze } = Object;
+const { create, entries, values, assign, freeze, getOwnPropertyDescriptors } =
+ Object;
+const { ownKeys } = Reflect;
const q = JSON.stringify;

/**
@@ -28,7 +30,12 @@ export const ATTENUATORS_COMPARTMENT = '<ATTENUATORS>';
*/
const selectiveCopy = (from, to, list) => {
if (!list) {
- list = keys(from);
+ const descs = getOwnPropertyDescriptors(from);
+ list = ownKeys(from).filter(
+ key =>
+ // @ts-expect-error TypeScript still confused about a symbol as index
+ descs[key].enumerable,
+ );
}
for (let index = 0; index < list.length; index += 1) {
const key = list[index];
Loading