fix(ses): Unravel compartment/lockdown import cycle
MODIFY
packages/ses/src/compartment-shim.js
packages/ses/src/compartment-shim.js
@@ -12,7 +12,6 @@ import {
getOwnPropertyNames,
keys,
} from './commons.js';
-// eslint-disable-next-line import/no-cycle
import { initGlobalObject } from './global-object.js';
import { performEval } from './evaluate.js';
import { load } from './module-load.js';
@@ -242,6 +241,7 @@ export const makeCompartmentConstructor = (intrinsics, nativeBrander) => {
initGlobalObject(globalObject, intrinsics, sharedGlobalPropertyNames, {
globalTransforms,
nativeBrander,
+ makeCompartmentConstructor,
});
assign(globalObject, endowments);

MODIFY
packages/ses/src/global-object.js
packages/ses/src/global-object.js
@@ -2,8 +2,6 @@ import { defineProperty, objectHasOwnProperty, entries } from './commons.js';
import { makeEvalFunction } from './make-eval-function.js';
import { makeFunctionConstructor } from './make-function-constructor.js';
import { constantProperties, universalPropertyNames } from './whitelist.js';
-// eslint-disable-next-line import/no-cycle
-import { makeCompartmentConstructor } from './compartment-shim.js';
/**
* initGlobalObject()
@@ -16,7 +14,7 @@ export function initGlobalObject(
globalObject,
intrinsics,
newGlobalPropertyNames,
- { globalTransforms, nativeBrander },
+ { globalTransforms, nativeBrander, makeCompartmentConstructor },
) {
for (const [name, constant] of entries(constantProperties)) {
defineProperty(globalObject, name, {
@@ -57,9 +55,15 @@ export function initGlobalObject(
Function: makeFunctionConstructor(globalObject, {
globalTransforms,
}),
- Compartment: makeCompartmentConstructor(intrinsics, nativeBrander),
};
+ if (makeCompartmentConstructor) {
+ perCompartmentGlobals.Compartment = makeCompartmentConstructor(
+ intrinsics,
+ nativeBrander,
+ );
+ }
+
// TODO These should still be tamed according to the whitelist before
// being made available.
for (const [name, value] of entries(perCompartmentGlobals)) {

MODIFY
packages/ses/src/lockdown-shim.js
packages/ses/src/lockdown-shim.js
@@ -31,6 +31,7 @@ import { getAnonymousIntrinsics } from './get-anonymous-intrinsics.js';
import { initGlobalObject } from './global-object.js';
import { initialGlobalPropertyNames } from './whitelist.js';
import { tameFunctionToString } from './tame-function-tostring.js';
+import { makeCompartmentConstructor } from './compartment-shim.js';
let firstOptions;
@@ -134,6 +135,7 @@ export function repairIntrinsics(options = {}) {
// start compartment, from the intrinsics.
initGlobalObject(globalThis, intrinsics, initialGlobalPropertyNames, {
nativeBrander,
+ makeCompartmentConstructor,
});
/**

MODIFY
packages/ses/test/global-object.test.js
packages/ses/test/global-object.test.js
@@ -28,7 +28,7 @@ test('globalObject', t => {
t.notEqual(globalObject, globalThis);
t.equal(globalObject.globalThis, globalObject);
- t.equals(Object.getOwnPropertyNames(globalObject).length, 7);
+ t.equals(Object.getOwnPropertyNames(globalObject).length, 6);
const descs = Object.getOwnPropertyDescriptors(globalObject);
for (const [name, desc] of Object.entries(descs)) {

fix(ses): Unravel compartment/lockdown import cycle (#405)