fix(ses): scope tests - rename variables to match purpose
MODIFY
packages/ses/test/test-scope.js
packages/ses/test/test-scope.js
@@ -6,33 +6,33 @@ import { makeSafeEvaluator } from '../src/make-safe-evaluator.js';
test('scope behavior - lookup behavior', t => {
t.plan(7);
- const globalObject = { foo: {} };
- const globalLexicals = { foobar: {} };
+ const globalObject = { globalProp: {} };
+ const globalLexicals = { lexicalProp: {} };
const { safeEvaluate: evaluate } = makeSafeEvaluator({
globalObject,
globalLexicals,
});
- globalThis.bar = {};
+ globalThis.realmGlobalProp = {};
t.teardown(() => {
- delete globalThis.bar;
+ delete globalThis.realmGlobalProp;
});
t.is(evaluate('globalThis'), undefined);
t.is(evaluate('eval'), undefined);
- t.is(evaluate('bar'), undefined);
- t.throws(() => evaluate('dummy'), { instanceOf: ReferenceError });
+ t.is(evaluate('realmGlobalProp'), undefined);
+ t.throws(() => evaluate('missingProp'), { instanceOf: ReferenceError });
- t.is(evaluate('foo'), globalObject.foo);
- t.is(evaluate('foobar'), globalLexicals.foobar);
+ t.is(evaluate('globalProp'), globalObject.globalProp);
+ t.is(evaluate('lexicalProp'), globalLexicals.lexicalProp);
// Known compromise in fidelity of the emulated script environment:
t.deepEqual(evaluate('arguments'), ['arguments']);
});
test('scope behavior - lookup in sloppyGlobalsMode', t => {
- t.plan(7);
+ t.plan(5);
const globalObject = {};
const globalLexicals = {};
@@ -42,17 +42,15 @@ test('scope behavior - lookup in sloppyGlobalsMode', t => {
sloppyGlobalsMode: true,
});
- globalThis.bar = {};
+ globalThis.realmGlobalProp = {};
t.teardown(() => {
- delete globalThis.bar;
+ delete globalThis.realmGlobalProp;
});
t.is(evaluate('globalThis'), undefined);
t.is(evaluate('eval'), undefined);
- t.is(evaluate('foo'), undefined);
- t.is(evaluate('bar'), undefined);
- t.is(evaluate('foobar'), undefined);
- t.is(evaluate('dummy'), undefined);
+ t.is(evaluate('realmGlobalProp'), undefined);
+ t.is(evaluate('missingProp'), undefined);
// Known compromise in fidelity of the emulated script environment:
t.deepEqual(evaluate('arguments'), ['arguments']);
@@ -84,7 +82,7 @@ test('scope behavior - this-value', t => {
configurable: true,
writable: true,
},
- globalObjectProtoFnOptimizable: {
+ globalObjectProtoFnImmutable: {
value() {
return this;
},
@@ -110,7 +108,7 @@ test('scope behavior - this-value', t => {
configurable: true,
writable: true,
},
- globalObjectFnOptimizable: {
+ globalObjectFnImmutable: {
value() {
return this;
},
@@ -136,7 +134,7 @@ test('scope behavior - this-value', t => {
configurable: true,
writable: true,
},
- globalLexicalsProtoFnOptimizable: {
+ globalLexicalsProtoFnImmutable: {
value() {
return this;
},
@@ -162,7 +160,7 @@ test('scope behavior - this-value', t => {
configurable: true,
writable: true,
},
- globalLexicalsFnOptimizable: {
+ globalLexicalsFnImmutable: {
value() {
return this;
},
@@ -199,12 +197,12 @@ test('scope behavior - this-value', t => {
t.true(knownScopeProxies.has(evaluate('globalObjectProtoFn()')));
t.true(knownScopeProxies.has(evaluate('globalObjectFn()')));
- t.true(knownScopeProxies.has(evaluate('globalObjectProtoFnOptimizable()')));
- t.is(evaluate('globalObjectFnOptimizable()'), undefined);
+ t.true(knownScopeProxies.has(evaluate('globalObjectProtoFnImmutable()')));
+ t.is(evaluate('globalObjectFnImmutable()'), undefined);
t.true(knownScopeProxies.has(evaluate('globalLexicalsProtoFn()')));
t.true(knownScopeProxies.has(evaluate('globalLexicalsFn()')));
- t.true(knownScopeProxies.has(evaluate('globalLexicalsProtoFnOptimizable()')));
- t.is(evaluate('globalLexicalsFnOptimizable()'), undefined);
+ t.true(knownScopeProxies.has(evaluate('globalLexicalsProtoFnImmutable()')));
+ t.is(evaluate('globalLexicalsFnImmutable()'), undefined);
});
test('scope behavior - assignment', t => {
@@ -220,9 +218,9 @@ test('scope behavior - assignment', t => {
evaluate(`(value) => { ${leftHandRef} = value }`)(value);
};
- globalThis.bar = {};
+ globalThis.realmGlobalProp = {};
t.teardown(() => {
- delete globalThis.bar;
+ delete globalThis.realmGlobalProp;
});
const evil = {};
@@ -234,13 +232,13 @@ test('scope behavior - assignment', t => {
t.is(globalThis.eval, originalEval);
const bar = {};
- const originalBar = globalThis.bar;
- doAssignment('this.bar', bar);
- t.is(globalObject.bar, bar);
- t.is(globalThis.bar, originalBar);
+ const originalBar = globalThis.realmGlobalProp;
+ doAssignment('this.realmGlobalProp', bar);
+ t.is(globalObject.realmGlobalProp, bar);
+ t.is(globalThis.realmGlobalProp, originalBar);
const foo = {};
- const originalFoo = globalObject.for;
+ const originalFoo = globalObject.foo;
doAssignment('foo', foo);
t.is(globalObject.foo, foo);
t.not(globalObject.foo, originalFoo);
@@ -271,18 +269,18 @@ test('scope behavior - strict vs sloppy locally non-existing global set', t => {
sloppyGlobalsMode: true,
});
- globalThis.bar = {};
+ globalThis.realmGlobalProp = {};
t.teardown(() => {
- delete globalThis.bar;
+ delete globalThis.realmGlobalProp;
});
// Known compromise in fidelity of the emulated script environment:
- t.notThrows(() => evaluateStrict('bar = 123'));
- t.throws(() => evaluateStrict('abc = 123'), {
+ t.notThrows(() => evaluateStrict('realmGlobalProp = 123'));
+ t.throws(() => evaluateStrict('missingRealmGlobalProp = 123'), {
instanceOf: ReferenceError,
});
- t.notThrows(() => evaluateSloppy('bar = 456'));
- t.notThrows(() => evaluateSloppy('xyz = 456'));
+ t.notThrows(() => evaluateSloppy('realmGlobalProp = 456'));
+ t.notThrows(() => evaluateSloppy('missingRealmGlobalProp = 456'));
});
test('scope behavior - realm globalThis property info leak', t => {
@@ -293,21 +291,27 @@ test('scope behavior - realm globalThis property info leak', t => {
globalObject,
});
- t.is(evaluate('typeof foo'), 'undefined');
- t.is(evaluate('typeof bar'), 'undefined');
- t.throws(() => evaluate('foo'), { instanceOf: ReferenceError });
- t.throws(() => evaluate('bar'), { instanceOf: ReferenceError });
+ t.is(evaluate('typeof missingRealmGlobalProp'), 'undefined');
+ t.is(evaluate('typeof eventuallyAssignedRealmGlobalProp'), 'undefined');
+ t.throws(() => evaluate('missingRealmGlobalProp'), {
+ instanceOf: ReferenceError,
+ });
+ t.throws(() => evaluate('eventuallyAssignedRealmGlobalProp'), {
+ instanceOf: ReferenceError,
+ });
- globalThis.bar = {};
+ globalThis.eventuallyAssignedRealmGlobalProp = {};
t.teardown(() => {
- delete globalThis.bar;
+ delete globalThis.eventuallyAssignedRealmGlobalProp;
});
- t.is(evaluate('typeof foo'), 'undefined');
- t.is(evaluate('typeof bar'), 'undefined');
- t.throws(() => evaluate('foo'), { instanceOf: ReferenceError });
+ t.is(evaluate('typeof missingRealmGlobalProp'), 'undefined');
+ t.is(evaluate('typeof eventuallyAssignedRealmGlobalProp'), 'undefined');
+ t.throws(() => evaluate('missingRealmGlobalProp'), {
+ instanceOf: ReferenceError,
+ });
// Known compromise in fidelity of the emulated script environment:
- t.is(evaluate('bar'), undefined);
+ t.is(evaluate('eventuallyAssignedRealmGlobalProp'), undefined);
});
test('scope behavior - Symbol.unscopables fidelity test', t => {
@@ -315,33 +319,43 @@ test('scope behavior - Symbol.unscopables fidelity test', t => {
const globalObject = {
Symbol,
- [Symbol.unscopables]: { bar: true },
+ [Symbol.unscopables]: { eventuallyAssignedRealmGlobalProp: true },
};
const { safeEvaluate: evaluate } = makeSafeEvaluator({
globalObject,
});
- t.is(evaluate('typeof foo'), 'undefined');
- t.is(evaluate('typeof bar'), 'undefined');
- t.throws(() => evaluate('foo'), { instanceOf: ReferenceError });
- t.throws(() => evaluate('bar'), { instanceOf: ReferenceError });
+ t.is(evaluate('typeof missingRealmGlobalProp'), 'undefined');
+ t.is(evaluate('typeof eventuallyAssignedRealmGlobalProp'), 'undefined');
+ t.throws(() => evaluate('missingRealmGlobalProp'), {
+ instanceOf: ReferenceError,
+ });
+ t.throws(() => evaluate('eventuallyAssignedRealmGlobalProp'), {
+ instanceOf: ReferenceError,
+ });
- globalThis.bar = {};
+ globalThis.eventuallyAssignedRealmGlobalProp = {};
t.teardown(() => {
- delete globalThis.bar;
+ delete globalThis.eventuallyAssignedRealmGlobalProp;
});
- t.is(evaluate('typeof foo'), 'undefined');
- t.is(evaluate('typeof bar'), 'undefined');
- t.throws(() => evaluate('foo'), { instanceOf: ReferenceError });
+ t.is(evaluate('typeof missingRealmGlobalProp'), 'undefined');
+ t.is(evaluate('typeof eventuallyAssignedRealmGlobalProp'), 'undefined');
+ t.throws(() => evaluate('missingRealmGlobalProp'), {
+ instanceOf: ReferenceError,
+ });
// Known compromise in fidelity of the emulated script environment:
- t.is(evaluate('bar'), undefined);
+ t.is(evaluate('eventuallyAssignedRealmGlobalProp'), undefined);
- evaluate('this[Symbol.unscopables] = { bar: true }');
+ evaluate(
+ 'this[Symbol.unscopables] = { eventuallyAssignedRealmGlobalProp: true }',
+ );
- t.is(evaluate('typeof foo'), 'undefined');
- t.is(evaluate('typeof bar'), 'undefined');
- t.throws(() => evaluate('foo'), { instanceOf: ReferenceError });
+ t.is(evaluate('typeof missingRealmGlobalProp'), 'undefined');
+ t.is(evaluate('typeof eventuallyAssignedRealmGlobalProp'), 'undefined');
+ t.throws(() => evaluate('missingRealmGlobalProp'), {
+ instanceOf: ReferenceError,
+ });
// Known compromise in fidelity of the emulated script environment:
- t.is(evaluate('bar'), undefined);
+ t.is(evaluate('eventuallyAssignedRealmGlobalProp'), undefined);
});

fix(ses): scope tests - rename variables to match purpose