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

refactor: get passStyleOf from VataData if there #1676

Merged
merged 1 commit into from
Jul 15, 2023
Merged
Changes from all 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
32 changes: 25 additions & 7 deletions packages/pass-style/src/passStyleOf.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* global globalThis */

/// <reference types="ses"/>

import { isPromise } from '@endo/promise-kit';
Expand Down Expand Up @@ -188,13 +190,29 @@ const makePassStyleOf = passStyleHelpers => {
return harden(passStyleOf);
};

export const passStyleOf = makePassStyleOf([
CopyArrayHelper,
CopyRecordHelper,
TaggedHelper,
ErrorHelper,
RemotableHelper,
]);
/**
* If there is already a `VataData` global containing a `passStyleOf`,
* then presumably it was endowed for us by liveslots, so we should use
* and export that one instead. Other software may have left it for us here,
* but it would require write access to our global, or the ability to
* provide endowments to our global, both of which seems adequate as a test of
* whether it is authorized to serve the same role as liveslots.
*
* NOTE HAZARD: This use by liveslots does rely on `passStyleOf` being
* deterministic. If it is not, then in a liveslot-like virtualized
* environment, it can be used to detect GC.
*
* @type {PassStyleOf}
*/
export const passStyleOf =
globalThis?.VatData?.passStyleOf ||
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAICT, this is the only mention of VatData in all of endo, and one of only two non-spurious references to liveslots (the others looking like migration cruft). If fundamental modules are going to defer to their environment, it would be good to establish an endo convention supporting that while keeping it independent rather than inverting the usual dependency direction with agoric-sdk. My first thought would be Symbol-keyed properties, e.g.

Suggested change
globalThis?.VatData?.passStyleOf ||
globalThis?.[Symbol.for('@endo passStyleOf')] ||

makePassStyleOf([
CopyArrayHelper,
CopyRecordHelper,
TaggedHelper,
ErrorHelper,
RemotableHelper,
]);

export const assertPassable = val => {
passStyleOf(val); // throws if val is not a passable
Expand Down