diff --git a/packages/SwingSet/src/controller.js b/packages/SwingSet/src/controller.js index f979a8acabb5..fb80604ab976 100644 --- a/packages/SwingSet/src/controller.js +++ b/packages/SwingSet/src/controller.js @@ -1,4 +1,4 @@ -/* global Compartment WeakRef FinalizationRegistry */ +/* global Compartment */ import fs from 'fs'; import path from 'path'; @@ -18,6 +18,7 @@ import { makeMeteringTransformer } from '@agoric/transform-metering'; import { makeTransform } from '@agoric/transform-eventual-send'; import { locateWorkerBin } from '@agoric/xs-vat-worker'; +import { WeakRef, FinalizationRegistry } from './optional-weakref'; import { startSubprocessWorker } from './spawnSubprocessWorker'; import { waitUntilQuiescent } from './waitUntilQuiescent'; import { insistStorageAPI } from './storageAPI'; diff --git a/packages/SwingSet/src/kernel/vatManager/nodeWorkerSupervisor.js b/packages/SwingSet/src/kernel/vatManager/nodeWorkerSupervisor.js index 447479eb6d70..ee554fc8c26b 100644 --- a/packages/SwingSet/src/kernel/vatManager/nodeWorkerSupervisor.js +++ b/packages/SwingSet/src/kernel/vatManager/nodeWorkerSupervisor.js @@ -1,6 +1,5 @@ // this file is loaded at the start of a new Worker, which makes it a new JS // environment (with it's own Realm), so we must install-ses too. -/* global WeakRef FinalizationRegistry */ import '@agoric/install-ses'; import { parentPort } from 'worker_threads'; import anylogger from 'anylogger'; @@ -8,6 +7,7 @@ import anylogger from 'anylogger'; import { assert } from '@agoric/assert'; import { importBundle } from '@agoric/import-bundle'; import { Remotable, getInterfaceOf, makeMarshal } from '@agoric/marshal'; +import { WeakRef, FinalizationRegistry } from '../../optional-weakref'; import { waitUntilQuiescent } from '../../waitUntilQuiescent'; import { makeLiveSlots } from '../liveSlots'; diff --git a/packages/SwingSet/src/kernel/vatManager/subprocessSupervisor.js b/packages/SwingSet/src/kernel/vatManager/subprocessSupervisor.js index f2d324e3036b..9a7ba68c7d41 100644 --- a/packages/SwingSet/src/kernel/vatManager/subprocessSupervisor.js +++ b/packages/SwingSet/src/kernel/vatManager/subprocessSupervisor.js @@ -1,5 +1,4 @@ // this file is loaded at the start of a new subprocess -/* global WeakRef FinalizationRegistry */ import '@agoric/install-ses'; import anylogger from 'anylogger'; @@ -8,6 +7,7 @@ import fs from 'fs'; import { assert } from '@agoric/assert'; import { importBundle } from '@agoric/import-bundle'; import { Remotable, getInterfaceOf, makeMarshal } from '@agoric/marshal'; +import { WeakRef, FinalizationRegistry } from '../../optional-weakref'; import { arrayEncoderStream, arrayDecoderStream } from '../../worker-protocol'; import { netstringEncoderStream, diff --git a/packages/SwingSet/src/optional-weakref.js b/packages/SwingSet/src/optional-weakref.js new file mode 100644 index 000000000000..af88600e061b --- /dev/null +++ b/packages/SwingSet/src/optional-weakref.js @@ -0,0 +1,17 @@ +/* global globalThis */ + +/* + * We retain a measure of compatibility with Node.js v12, which does not + * expose WeakRef or FinalizationRegistry (there is a --flag for it, but it's + * not clear how stable it is). When running on a platform without these + * tools, vats cannot do GC. + * + * Modules should do: + * + * import { WeakRef, FinalizationRegistry } from '.../optional-weakref'; + * + * and refrain from GC if `WeakRef === undefined` + */ + +export const WeakRef = globalThis.WeakRef; +export const FinalizationRegistry = globalThis.FinalizationRegistry; diff --git a/packages/SwingSet/test/test-kernel.js b/packages/SwingSet/test/test-kernel.js index c82c8bfeac34..41223eb72c05 100644 --- a/packages/SwingSet/test/test-kernel.js +++ b/packages/SwingSet/test/test-kernel.js @@ -1,8 +1,8 @@ -/* global WeakRef FinalizationRegistry */ import '@agoric/install-ses'; import test from 'ava'; import anylogger from 'anylogger'; import { initSwingStore } from '@agoric/swing-store-simple'; +import { WeakRef, FinalizationRegistry } from '../src/optional-weakref'; import { waitUntilQuiescent } from '../src/waitUntilQuiescent'; import buildKernel from '../src/kernel/index'; diff --git a/packages/SwingSet/test/test-liveslots.js b/packages/SwingSet/test/test-liveslots.js index b36544eef18f..c053979cd557 100644 --- a/packages/SwingSet/test/test-liveslots.js +++ b/packages/SwingSet/test/test-liveslots.js @@ -1,7 +1,7 @@ -/* global WeakRef FinalizationRegistry */ import '@agoric/install-ses'; import test from 'ava'; import { E } from '@agoric/eventual-send'; +import { WeakRef, FinalizationRegistry } from '../src/optional-weakref'; import { waitUntilQuiescent } from '../src/waitUntilQuiescent'; import { makeLiveSlots } from '../src/kernel/liveSlots'; diff --git a/packages/SwingSet/test/test-marshal.js b/packages/SwingSet/test/test-marshal.js index 697c4d6fdf32..877d0d7e9e92 100644 --- a/packages/SwingSet/test/test-marshal.js +++ b/packages/SwingSet/test/test-marshal.js @@ -1,8 +1,8 @@ -/* global WeakRef FinalizationRegistry */ import '@agoric/install-ses'; import test from 'ava'; import { makePromiseKit } from '@agoric/promise-kit'; +import { WeakRef, FinalizationRegistry } from '../src/optional-weakref'; import { makeMarshaller } from '../src/kernel/liveSlots'; import { buildVatController } from '../src/index'; diff --git a/packages/SwingSet/test/test-vpid-kernel.js b/packages/SwingSet/test/test-vpid-kernel.js index 808782267b76..0202ecbb5652 100644 --- a/packages/SwingSet/test/test-vpid-kernel.js +++ b/packages/SwingSet/test/test-vpid-kernel.js @@ -1,10 +1,8 @@ -/* global WeakRef FinalizationRegistry */ -// eslint-disable-next-line no-redeclare - import '@agoric/install-ses'; import test from 'ava'; import anylogger from 'anylogger'; import { initSwingStore } from '@agoric/swing-store-simple'; +import { WeakRef, FinalizationRegistry } from '../src/optional-weakref'; import { waitUntilQuiescent } from '../src/waitUntilQuiescent'; import buildKernel from '../src/kernel/index'; diff --git a/packages/SwingSet/test/test-vpid-liveslots.js b/packages/SwingSet/test/test-vpid-liveslots.js index c42dcb1fbea6..8b447ce021db 100644 --- a/packages/SwingSet/test/test-vpid-liveslots.js +++ b/packages/SwingSet/test/test-vpid-liveslots.js @@ -1,11 +1,12 @@ // eslint-disable-next-line no-redeclare -/* global setImmediate WeakRef FinalizationRegistry */ +/* global setImmediate */ import '@agoric/install-ses'; import test from 'ava'; import { E } from '@agoric/eventual-send'; import { makePromiseKit } from '@agoric/promise-kit'; +import { WeakRef, FinalizationRegistry } from '../src/optional-weakref'; import { makeLiveSlots } from '../src/kernel/liveSlots'; const RETIRE_VPIDS = true;