Skip to content

Commit

Permalink
Iron out signature of repairIntrinsics()
Browse files Browse the repository at this point in the history
  • Loading branch information
kriskowal committed Jul 23, 2020
1 parent 18e765f commit a071709
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions packages/ses/src/lockdown-shim.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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 = {
Expand Down Expand Up @@ -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();
};

0 comments on commit a071709

Please sign in to comment.