From 7bfc8db0bc73d667e664235b222e261c0ce3da0a Mon Sep 17 00:00:00 2001 From: "Mark S. Miller" Date: Fri, 14 Jul 2023 16:41:58 -0700 Subject: [PATCH] refactor: get passStyleOf from VataData if there --- packages/pass-style/src/passStyleOf.js | 32 ++++++++++++++++++++------ 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/packages/pass-style/src/passStyleOf.js b/packages/pass-style/src/passStyleOf.js index 8ee34d5636..9774bdeee6 100644 --- a/packages/pass-style/src/passStyleOf.js +++ b/packages/pass-style/src/passStyleOf.js @@ -1,3 +1,5 @@ +/* global globalThis */ + /// import { isPromise } from '@endo/promise-kit'; @@ -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