evaluators.js: remove the `endow()` transform
MODIFY
src/evaluators.js
src/evaluators.js
@@ -94,13 +94,6 @@ export function createSafeEvaluatorFactory(
...mandatoryTransforms
];
- // Add endowments needed by the transforms, threading through state as necessary.
- const endowmentState = allTransforms.reduce(
- (es, transform) => (transform.endow ? transform.endow(es) : es),
- { endowments }
- );
- endowments = endowmentState.endowments;
-
// We use the the concise method syntax to create an eval without a
// [[Construct]] behavior (such that the invocation "new eval()" throws
// TypeError: eval is not a constructor"), but which still accepts a
@@ -115,14 +108,6 @@ export function createSafeEvaluatorFactory(
);
src = rewriterState.src;
- // todo (shim limitation): scan endowments, throw error if endowment
- // overlaps with the const optimization (which would otherwise
- // incorrectly shadow endowments), or if endowments includes 'eval'. Also
- // prohibit accessor properties (to be able to consistently explain
- // things in terms of shimming the global lexical scope).
- // writeable-vs-nonwritable == let-vs-const, but there's no
- // global-lexical-scope equivalent of an accessor, outside what we can
- // explain/spec
const scopeTarget = create(
safeGlobal,
getOwnPropertyDescriptors(rewriterState.endowments)

MODIFY
test/module/evaluators.js
test/module/evaluators.js
@@ -141,10 +141,10 @@ test('createSafeEvaluatorWhichTakesEndowments - options.transforms', t => {
const realmTransforms = [
{
- endow(es) {
- return { ...es, endowments: { ...es.endowments, abc: 123 } };
- },
rewrite(ss) {
+ if (!ss.endowments.abc) {
+ ss.endowments.abc = 123;
+ }
return { ...ss, src: ss.src === 'ABC' ? 'abc' : ss.src };
}
}
@@ -166,9 +166,9 @@ test('createSafeEvaluatorWhichTakesEndowments - options.transforms', t => {
t.equal(safeEval('abc', {}), 123, 'no rewrite');
t.equal(safeEval('ABC', { ABC: 234 }), 123, 'realmTransforms rewrite ABC');
t.equal(
- safeEval('ABC', { ABC: 234, abc: 'notused' }),
+ safeEval('ABC', { ABC: 234, abc: false }),
123,
- 'endowed abc is overridden'
+ 'falsey abc is overridden'
);
t.equal(
safeEval('ABC', { def: 789 }, options),

evaluators.js: remove the `endow()` transform