refactor(ses): re-order some lines
Preparations for makeEvaluate, no observable changes
MODIFY
packages/ses/src/compartment-shim.js
packages/ses/src/compartment-shim.js
@@ -206,7 +206,7 @@ export const makeCompartmentConstructor = (
name = '<unknown>',
transforms = [],
__shimTransforms__ = [],
- globalLexicals = {},
+ globalLexicals: globalLexicalsOption = {},
resolveHook,
importHook,
moduleMapHook,
@@ -244,6 +244,30 @@ export const makeCompartmentConstructor = (
}
}
+ const invalidNames = arrayFilter(
+ getOwnPropertyNames(globalLexicalsOption),
+ identifier => !isValidIdentifierName(identifier),
+ );
+ if (invalidNames.length) {
+ throw new TypeError(
+ `Cannot create compartment with invalid names for global lexicals: ${arrayJoin(
+ invalidNames,
+ ', ',
+ )}; these names would not be lexically mentionable`,
+ );
+ }
+ // The caller continues to own the globalLexicals object they passed to
+ // the compartment constructor, but the compartment only respects the
+ // original values and they are constants in the scope of evaluated
+ // programs and executed modules.
+ // This shallow copy captures only the values of enumerable own
+ // properties, erasing accessors.
+ // The snapshot is frozen to ensure that the properties are immutable
+ // when transferred-by-property-descriptor onto local scope objects.
+ const globalLexicals = freeze({ ...globalLexicalsOption });
+
+ const knownScopeProxies = new WeakSet();
+
const globalObject = {};
initGlobalObject(
globalObject,
@@ -259,35 +283,12 @@ export const makeCompartmentConstructor = (
assign(globalObject, endowments);
- const invalidNames = arrayFilter(
- getOwnPropertyNames(globalLexicals),
- identifier => !isValidIdentifierName(identifier),
- );
- if (invalidNames.length) {
- throw new TypeError(
- `Cannot create compartment with invalid names for global lexicals: ${arrayJoin(
- invalidNames,
- ', ',
- )}; these names would not be lexically mentionable`,
- );
- }
-
- const knownScopeProxies = new WeakSet();
-
weakmapSet(privateFields, this, {
name,
globalTransforms,
globalObject,
knownScopeProxies,
- // The caller continues to own the globalLexicals object they passed to
- // the compartment constructor, but the compartment only respects the
- // original values and they are constants in the scope of evaluated
- // programs and executed modules.
- // This shallow copy captures only the values of enumerable own
- // properties, erasing accessors.
- // The snapshot is frozen to ensure that the properties are immutable
- // when transferred-by-property-descriptor onto local scope objects.
- globalLexicals: freeze({ ...globalLexicals }),
+ globalLexicals,
resolveHook,
importHook,
moduleMap,

MODIFY
packages/ses/src/evaluate.js
packages/ses/src/evaluate.js
@@ -41,14 +41,6 @@ export const performEval = (
knownScopeProxies = new WeakSet(),
} = {},
) => {
- // Execute the mandatory transforms last to ensure that any rewritten code
- // meets those mandatory requirements.
- source = applyTransforms(source, [
- ...localTransforms,
- ...globalTransforms,
- mandatoryTransforms,
- ]);
-
const {
scopeHandler,
admitOneUnsafeEvalNext,
@@ -60,16 +52,24 @@ export const performEval = (
immutableObject,
scopeHandler,
);
+ weaksetAdd(knownScopeProxies, scopeProxy);
const constants = getScopeConstants(globalObject, localObject);
const evaluateFactory = makeEvaluateFactory(constants);
const evaluate = apply(evaluateFactory, scopeProxy, []);
+ // Execute the mandatory transforms last to ensure that any rewritten code
+ // meets those mandatory requirements.
+ source = applyTransforms(source, [
+ ...localTransforms,
+ ...globalTransforms,
+ mandatoryTransforms,
+ ]);
+
admitOneUnsafeEvalNext();
let err;
try {
// Ensure that "this" resolves to the safe global.
- weaksetAdd(knownScopeProxies, scopeProxy);
return apply(evaluate, globalObject, [source]);
} catch (e) {
// stash the child-code error in hopes of debugging the internal failure

refactor(ses): re-order some lines
Preparations for makeEvaluate, no observable changes