Skip to content

Commit

Permalink
Merge pull request #1676 from endojs/markm-vatdata-pass-style
Browse files Browse the repository at this point in the history
refactor: get passStyleOf from VataData if there
  • Loading branch information
erights authored Jul 15, 2023
2 parents 96e33eb + 7bfc8db commit 4291993
Showing 1 changed file with 25 additions and 7 deletions.
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 ||
makePassStyleOf([
CopyArrayHelper,
CopyRecordHelper,
TaggedHelper,
ErrorHelper,
RemotableHelper,
]);

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

0 comments on commit 4291993

Please sign in to comment.