refactor(ses): Rename localObject to globalLexicals
Fixes
MODIFY
packages/ses/src/compartment-evaluate.js
packages/ses/src/compartment-evaluate.js
@@ -55,7 +55,7 @@ export const provideCompartmentEvaluator = (compartmentFields, options) => {
({ safeEvaluate } = makeSafeEvaluator({
globalObject,
- localObject,
+ globalLexicals: localObject,
globalTransforms,
sloppyGlobalsMode,
knownScopeProxies,

MODIFY
packages/ses/src/compartment-shim.js
packages/ses/src/compartment-shim.js
@@ -283,7 +283,7 @@ export const makeCompartmentConstructor = (
const knownScopeProxies = new WeakSet();
const { safeEvaluate } = makeSafeEvaluator({
globalObject,
- localObject: globalLexicals,
+ globalLexicals,
globalTransforms,
sloppyGlobalsMode: false,
knownScopeProxies,

MODIFY
packages/ses/src/make-safe-evaluator.js
packages/ses/src/make-safe-evaluator.js
@@ -16,8 +16,6 @@ import { assert } from './error/assert.js';
const { details: d } = assert;
-// TODO: rename localObject to scopeObject
-
/**
* makeSafeEvaluator()
* Build the low-level operation used by all evaluators:
@@ -25,14 +23,14 @@ const { details: d } = assert;
*
* @param {Object} options
* @param {Object} options.globalObject
- * @param {Object} [options.localObject]
+ * @param {Object} [options.globalLexicals]
* @param {Array<Transform>} [options.globalTransforms]
* @param {bool} [options.sloppyGlobalsMode]
* @param {WeakSet} [options.knownScopeProxies]
*/
export const makeSafeEvaluator = ({
globalObject,
- localObject = {},
+ globalLexicals = {},
globalTransforms = [],
sloppyGlobalsMode = false,
knownScopeProxies = new WeakSet(),
@@ -41,7 +39,7 @@ export const makeSafeEvaluator = ({
scopeHandler,
admitOneUnsafeEvalNext,
resetOneUnsafeEvalNext,
- } = createScopeHandler(globalObject, localObject, {
+ } = createScopeHandler(globalObject, globalLexicals, {
sloppyGlobalsMode,
});
const { proxy: scopeProxy, revoke: revokeScopeProxy } = proxyRevocable(
@@ -56,7 +54,7 @@ export const makeSafeEvaluator = ({
let evaluate;
const makeEvaluate = () => {
if (!evaluate) {
- const constants = getScopeConstants(globalObject, localObject);
+ const constants = getScopeConstants(globalObject, globalLexicals);
const evaluateFactory = makeEvaluateFactory(constants);
evaluate = apply(evaluateFactory, scopeProxy, []);
}

MODIFY
packages/ses/src/scope-handler.js
packages/ses/src/scope-handler.js
@@ -53,7 +53,7 @@ const alwaysThrowHandler = new Proxy(
*/
export const createScopeHandler = (
globalObject,
- localObject = {},
+ globalLexicals = {},
{ sloppyGlobalsMode = false } = {},
) => {
// This flag allow us to determine if the eval() call is an done by the
@@ -90,12 +90,12 @@ export const createScopeHandler = (
// fall through
}
- // Properties of the localObject.
- if (prop in localObject) {
+ // Properties of the globalLexicals.
+ if (prop in globalLexicals) {
// Use reflect to defeat accessors that could be present on the
- // localObject object itself as `this`.
+ // globalLexicals object itself as `this`.
// This is done out of an overabundance of caution, as the SES shim
- // only use the localObject carry globalLexicals and live binding
+ // only use the globalLexicals carry globalLexicals and live binding
// traps.
// The globalLexicals are captured as a snapshot of what's passed to
// the Compartment constructor, wherein all accessors and setters are
@@ -104,7 +104,7 @@ export const createScopeHandler = (
// make use of their receiver.
// Live binding traps provide no avenue for user code to observe the
// receiver.
- return reflectGet(localObject, prop, globalObject);
+ return reflectGet(globalLexicals, prop, globalObject);
}
// Properties of the global.
@@ -112,17 +112,17 @@ export const createScopeHandler = (
},
set(_shadow, prop, value) {
- // Properties of the localObject.
- if (prop in localObject) {
- const desc = getOwnPropertyDescriptor(localObject, prop);
+ // Properties of the globalLexicals.
+ if (prop in globalLexicals) {
+ const desc = getOwnPropertyDescriptor(globalLexicals, prop);
if (objectHasOwnProperty(desc, 'value')) {
// Work around a peculiar behavior in the specs, where
// value properties are defined on the receiver.
- return reflectSet(localObject, prop, value);
+ return reflectSet(globalLexicals, prop, value);
}
// Ensure that the 'this' value on setters resolves
- // to the safeGlobal, not to the localObject object.
- return reflectSet(localObject, prop, value, globalObject);
+ // to the safeGlobal, not to the globalLexicals object.
+ return reflectSet(globalLexicals, prop, value, globalObject);
}
// Properties of the global.
@@ -166,7 +166,7 @@ export const createScopeHandler = (
return (
sloppyGlobalsMode ||
(allowNextEvalToBeUnsafe && prop === 'eval') ||
- prop in localObject ||
+ prop in globalLexicals ||
prop in globalObject ||
prop in globalThis
);

MODIFY
packages/ses/test/test-make-evaluator.js
packages/ses/test/test-make-evaluator.js
@@ -3,7 +3,7 @@ import './lockdown-safe.js';
import test from 'ava';
import { makeSafeEvaluator } from '../src/make-safe-evaluator.js';
-test('safeEvaluate - default (non-sloppy, no localObject)', t => {
+test('safeEvaluate - default (non-sloppy, no globalLexicals)', t => {
t.plan(6);
const globalObject = { abc: 123 };
@@ -55,7 +55,7 @@ test('safeEvaluate - endowments', t => {
const endowments = { abc: 123 };
const { safeEvaluate: endowedEvaluate } = makeSafeEvaluator({
globalObject,
- localObject: endowments,
+ globalLexicals: endowments,
});
const { safeEvaluate: evaluate } = makeSafeEvaluator({ globalObject });
@@ -94,7 +94,7 @@ test('safeEvaluate - transforms - rewrite source', t => {
const { safeEvaluate: evaluate } = makeSafeEvaluator({
globalObject,
- localObject: endowments,
+ globalLexicals: endowments,
globalTransforms,
});

refactor(ses): Rename localObject to globalLexicals

Fixes #840