refactor(ses): Sublimate makeLockdown
This simplifies away the lockdown maker since we now only make one kind
of lockdown.
Fixes
MODIFY
packages/ses/index.js
packages/ses/index.js
@@ -16,12 +16,8 @@ import { globalThis, TypeError, assign } from './src/commons.js';
import { tameFunctionToString } from './src/tame-function-tostring.js';
import { getGlobalIntrinsics } from './src/intrinsics.js';
-import { getAnonymousIntrinsics } from './src/get-anonymous-intrinsics.js';
-import { makeLockdown } from './src/lockdown-shim.js';
-import {
- makeCompartmentConstructor,
- CompartmentPrototype,
-} from './src/compartment-shim.js';
+import { lockdown } from './src/lockdown-shim.js';
+import { makeCompartmentConstructor } from './src/compartment-shim.js';
import { assert } from './src/error/assert.js';
/** getThis returns globalThis in sloppy mode or undefined in strict mode. */
@@ -42,11 +38,7 @@ const Compartment = makeCompartmentConstructor(
);
assign(globalThis, {
- lockdown: makeLockdown(
- makeCompartmentConstructor,
- CompartmentPrototype,
- getAnonymousIntrinsics,
- ),
+ lockdown,
Compartment,
assert,
});

MODIFY
packages/ses/src/lockdown-shim.js
packages/ses/src/lockdown-shim.js
@@ -46,6 +46,8 @@ import { tameConsole } from './error/tame-console.js';
import tameErrorConstructor from './error/tame-error-constructor.js';
import { assert, makeAssert } from './error/assert.js';
import { makeEnvironmentCaptor } from './environment-options.js';
+import { getAnonymousIntrinsics } from './get-anonymous-intrinsics.js';
+import { makeCompartmentConstructor } from './compartment-shim.js';
/** @typedef {import('../index.js').LockdownOptions} LockdownOptions */
@@ -80,44 +82,17 @@ const alreadyHardenedIntrinsics = () => false;
* @param {Object} [options.globalLexicals]
*/
-/**
- * @callback CompartmentConstructorMaker
- * @param {CompartmentConstructorMaker} targetMakeCompartmentConstructor
- * @param {Object} intrinsics
- * @param {(func: Function) => void} markVirtualizedNativeFunction
- * @returns {CompartmentConstructor}
- */
-
// TODO https://github.com/endojs/endo/issues/814
// Lockdown currently allows multiple calls provided that the specified options
// of every call agree. With experience, we have observed that lockdown should
// only ever need to be called once and that simplifying lockdown will improve
// the quality of audits.
-// TODO https://github.com/endojs/endo/issues/815
-// Lockdown receives makeCompartmentConstructor and compartmentPrototype.
-// This is a vestige of an earlier version of SES where makeLockdown was called
-// from two different entry points: one for a layer of SES that had a
-// Compartment that only supported evaluating programs, and a second layer that
-// extended Compartment to support modules, but at the expense of entraining a
-// dependency on Babel.
-// SES currently externalizes the dependency on Babel and one version of
-// makeCompartmentConstructor is sufficient for all uses, so this can be
-// simplified.
-
/**
- * @param {CompartmentConstructorMaker} makeCompartmentConstructor
- * @param {Object} compartmentPrototype
- * @param {() => Object} getAnonymousIntrinsics
* @param {LockdownOptions} [options]
* @returns {() => {}} repairIntrinsics
*/
-export const repairIntrinsics = (
- makeCompartmentConstructor,
- compartmentPrototype,
- getAnonymousIntrinsics,
- options = {},
-) => {
+export const repairIntrinsics = (options = {}) => {
// First time, absent options default to 'safe'.
// Subsequent times, absent options default to first options.
// Thus, all present options must agree with first options.
@@ -375,28 +350,10 @@ export const repairIntrinsics = (
return hardenIntrinsics;
};
-/**
- * @param {CompartmentConstructorMaker} makeCompartmentConstructor
- * @param {Object} compartmentPrototype
- * @param {() => Object} getAnonymousIntrinsics
- * @returns {import('../index.js').Lockdown}
- */
-export const makeLockdown = (
- makeCompartmentConstructor,
- compartmentPrototype,
- getAnonymousIntrinsics,
-) => {
/**
* @param {LockdownOptions} [options]
*/
- const lockdown = (options = {}) => {
- const maybeHardenIntrinsics = repairIntrinsics(
- makeCompartmentConstructor,
- compartmentPrototype,
- getAnonymousIntrinsics,
- options,
- );
+export const lockdown = (options = {}) => {
+ const maybeHardenIntrinsics = repairIntrinsics(options);
return maybeHardenIntrinsics();
};
- return lockdown;
-};

MODIFY
packages/ses/test/test-lockdown-options.js
packages/ses/test/test-lockdown-options.js
import test from 'ava';
-import { makeLockdown } from '../src/lockdown-shim.js';
-import { getAnonymousIntrinsics } from '../src/get-anonymous-intrinsics.js';
-import {
- makeCompartmentConstructor,
- CompartmentPrototype,
-} from '../src/compartment-shim.js';
-
-const lockdown = makeLockdown(
- makeCompartmentConstructor,
- CompartmentPrototype,
- getAnonymousIntrinsics,
-);
+import { lockdown } from '../src/lockdown-shim.js';
test('lockdown throws with non-recognized options', t => {
t.throws(

refactor(ses): Sublimate makeLockdown (#918)

This simplifies away the lockdown maker since we now only make one kind
of lockdown.

Fixes #814