From 53658ea0b5c54e66883135ea872d0295b1487445 Mon Sep 17 00:00:00 2001 From: "Mark S. Miller" Date: Wed, 27 Sep 2023 22:20:27 -0700 Subject: [PATCH] feat(pass-style): Use endowed passStyleOf if at global symbol --- packages/pass-style/endow.js | 1 + packages/pass-style/package.json | 1 + packages/pass-style/src/passStyleOf.js | 13 +++++++------ 3 files changed, 9 insertions(+), 6 deletions(-) create mode 100644 packages/pass-style/endow.js diff --git a/packages/pass-style/endow.js b/packages/pass-style/endow.js new file mode 100644 index 0000000000..e8cee0a4ac --- /dev/null +++ b/packages/pass-style/endow.js @@ -0,0 +1 @@ +export { PassStyleOfEndowmentSymbol } from './src/passStyleOf.js'; diff --git a/packages/pass-style/package.json b/packages/pass-style/package.json index 11b386d842..8759556307 100644 --- a/packages/pass-style/package.json +++ b/packages/pass-style/package.json @@ -19,6 +19,7 @@ "exports": { ".": "./index.js", "./tools.js": "./tools.js", + "./endow.js": "./endow.js", "./package.json": "./package.json" }, "scripts": { diff --git a/packages/pass-style/src/passStyleOf.js b/packages/pass-style/src/passStyleOf.js index b41c202a23..0a49fe71a1 100644 --- a/packages/pass-style/src/passStyleOf.js +++ b/packages/pass-style/src/passStyleOf.js @@ -190,10 +190,13 @@ const makePassStyleOf = passStyleHelpers => { return harden(passStyleOf); }; +export const PassStyleOfEndowmentSymbol = Symbol.for('@endo passStyleOf'); + /** - * 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, + * If there is already a PassStyleOfEndowmentSymbol property on the global, + * then presumably it was endowed for us by liveslots with a `passStyleOf` + * function, 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. @@ -205,9 +208,7 @@ const makePassStyleOf = passStyleHelpers => { * @type {PassStyleOf} */ export const passStyleOf = - // UNTIL https://github.com/endojs/endo/issues/1514 - // Prefer: globalThis?.VatData?.passStyleOf || - (globalThis && globalThis.VatData && globalThis.VatData.passStyleOf) || + (globalThis && globalThis[PassStyleOfEndowmentSymbol]) || makePassStyleOf([ CopyArrayHelper, CopyRecordHelper,