diff --git a/packages/ses/src/lockdown-shim.js b/packages/ses/src/lockdown-shim.js index 7c63f0040c..068b72bff7 100644 --- a/packages/ses/src/lockdown-shim.js +++ b/packages/ses/src/lockdown-shim.js @@ -15,6 +15,7 @@ import makeHardener from '@agoric/make-hardener'; import { assert } from './assert.js'; +import { keys } from './commons.js'; import { makeIntrinsicsCollector } from './intrinsics.js'; import whitelistIntrinsics from './whitelist-intrinsics.js'; import repairLegacyAccessors from './repair-legacy-accessors.js'; @@ -45,6 +46,8 @@ export const harden = ref => { return lockdownHarden(ref); }; +const alreadyHardenedIntrinsics = () => false; + export function repairIntrinsics(options = {}) { // First time, absent options default to 'safe'. // Subsequent times, absent options default to first options. @@ -72,15 +75,13 @@ export function repairIntrinsics(options = {}) { // Asserts for multiple invocation of lockdown(). if (firstOptions) { - Object.keys(firstOptions).forEach(name => { + for (const name of keys(firstOptions)) { assert( options[name] === firstOptions[name], `lockdown(): cannot re-invoke with different option ${name}`, ); - }); - // Returning `false` indicates that lockdown() made no changes because it - // was invoked from SES with non-conflicting options. - return false; + } + return alreadyHardenedIntrinsics; } firstOptions = { @@ -148,13 +149,11 @@ export function repairIntrinsics(options = {}) { // Returning `true` indicates that this is a JS to SES transition. return true; } + return hardenIntrinsics; } export const lockdown = (options = {}) => { - const optHardenIntrinsics = repairIntrinsics(options); - if (optHardenIntrinsics === false) { - return false; - } - return optHardenIntrinsics(); + const maybeHardenIntrinsics = repairIntrinsics(options); + return maybeHardenIntrinsics(); };