more eslint appeasement
This changes all the clearly-correct cases, leaving the subtle ones for
a separate commit.
MODIFY
.eslintrc.js
.eslintrc.js
@@ -9,6 +9,7 @@ module.exports = {
'function-paren-newline': 'off',
'arrow-parens': 'off',
strict: 'off',
+ 'no-console': 'off',
},
};

MODIFY
src/bundle/anonIntrinsics.js
src/bundle/anonIntrinsics.js
@@ -101,11 +101,11 @@ export default function getAnonIntrinsics(global) {
// Is the resulting object either the undeniable object, or does
// it inherit directly from the undeniable object?
- function* aStrictGenerator() {}
+ function* aStrictGenerator() {} // eslint-disable-line no-empty-function
const Generator = getProto(aStrictGenerator);
- async function* aStrictAsyncGenerator() {}
+ async function* aStrictAsyncGenerator() {} // eslint-disable-line no-empty-function
const AsyncGenerator = getProto(aStrictAsyncGenerator);
- async function aStrictAsyncFunction() {}
+ async function aStrictAsyncFunction() {} // eslint-disable-line no-empty-function
const AsyncFunctionPrototype = getProto(aStrictAsyncFunction);
// TODO: this is dead code, but could be useful: make this the
@@ -113,7 +113,7 @@ export default function getAnonIntrinsics(global) {
const undeniableTuples = [
['Object.prototype', Object.prototype, {}],
- ['Function.prototype', Function.prototype, function() {}],
+ ['Function.prototype', Function.prototype, function foo() {}],
['Array.prototype', Array.prototype, []],
['RegExp.prototype', RegExp.prototype, /x/],
['Boolean.prototype', Boolean.prototype, true],
@@ -150,7 +150,7 @@ export default function getAnonIntrinsics(global) {
if (base[iteratorSym]) {
const anIter = base[iteratorSym]();
const anIteratorPrototype = getProto(anIter);
- registery[name] = anIteratorPrototype;
+ registery[name] = anIteratorPrototype; // eslint-disable-line no-param-reassign
const anIterProtoBase = getProto(anIteratorPrototype);
if (anIterProtoBase !== Object.prototype) {
if (!registery.IteratorPrototype) {
@@ -159,7 +159,7 @@ export default function getAnonIntrinsics(global) {
'%IteratorPrototype%.__proto__ was not Object.prototype',
);
}
- registery.IteratorPrototype = anIterProtoBase;
+ registery.IteratorPrototype = anIterProtoBase; // eslint-disable-line no-param-reassign
} else if (registery.IteratorPrototype !== anIterProtoBase) {
throw new Error(`unexpected %${name}%.__proto__`);
}
@@ -279,11 +279,11 @@ export default function getAnonIntrinsics(global) {
result.TypedArray = TypedArray;
})();
- for (const name in result) {
+ Object.keys(result).forEach(name => {
if (result[name] === void 0) {
throw new Error(`Malformed intrinsic: ${name}`);
}
- }
+ });
return result;
}

MODIFY
src/bundle/createSES.js
src/bundle/createSES.js
// See the License for the specific language governing permissions and
// limitations under the License.
-import tameDate from './tame-date.js';
-import tameMath from './tame-math.js';
-import tameIntl from './tame-intl.js';
-import tameError from './tame-error.js';
-import tameRegExp from './tame-regexp.js';
-import removeProperties from './removeProperties.js';
-import getAnonIntrinsics from './anonIntrinsics.js';
-import { deepFreeze } from './deepFreeze.js';
-import hardenPrimordials from './hardenPrimordials.js';
-import whitelist from './whitelist.js';
-import { makeConsole } from './make-console.js';
+import tameDate from './tame-date';
+import tameMath from './tame-math';
+import tameIntl from './tame-intl';
+import tameError from './tame-error';
+import tameRegExp from './tame-regexp';
+import removeProperties from './removeProperties';
+import getAnonIntrinsics from './anonIntrinsics';
+import { deepFreeze } from './deepFreeze';
+import hardenPrimordials from './hardenPrimordials';
+import whitelist from './whitelist';
+import makeConsole from './make-console';
export function createSESWithRealmConstructor(creatorStrings, Realm) {
function makeSESRootRealm(options) {
+ // eslint-disable-next-line no-param-reassign
options = Object(options); // Todo: sanitize
const shims = [];
const wl = JSON.parse(JSON.stringify(whitelist));
@@ -114,6 +115,7 @@ export function createSESWithRealmConstructor(creatorStrings, Realm) {
}
export function createSESInThisRealm(global, creatorStrings, parentRealm) {
+ // eslint-disable-next-line no-param-reassign,no-undef
global.SES = createSESWithRealmConstructor(creatorStrings, Realm);
// todo: wrap exceptions, effectively undoing the wrapping that
// Realm.evaluate does
@@ -185,8 +187,10 @@ export function createSESInThisRealm(global, creatorStrings, parentRealm) {
// closes over the parent's Realm object so it shouldn't be accessible from
// the outside.
+ // eslint-disable-next-line no-param-reassign
global.SES.confine = (code, endowments) =>
callAndWrapError(() => parentRealm.evaluate(code, endowments));
+ // eslint-disable-next-line no-param-reassign
global.SES.confineExpr = (code, endowments) =>
callAndWrapError(() => parentRealm.evaluate(`(${code})`, endowments));
}

MODIFY
src/bundle/def.js
src/bundle/def.js
// See the License for the specific language governing permissions and
// limitations under the License.
-import { deepFreeze } from './deepFreeze.js';
+import { deepFreeze } from './deepFreeze';
-export function def(node) {
+export default function def(node) {
// TODO HACK return a shallow freeze unless Object.prototype is frozen.
// This detects whether we are in a SES realm.

MODIFY
src/bundle/hardenPrimordials.js
src/bundle/hardenPrimordials.js
-/* global def getAnonIntrinsics deepFreeze */
+/* global getAnonIntrinsics deepFreeze */
export default function hardenPrimoridals(global) {
'use strict';

MODIFY
src/bundle/index.js
src/bundle/index.js
import {
createSESWithRealmConstructor,
createSESInThisRealm,
-} from './createSES.js';
-import { def } from './def.js';
-import { Nat } from './nat.js';
+} from './createSES';
+import def from './def';
+import Nat from './nat';
export { createSESWithRealmConstructor, createSESInThisRealm, def, Nat };

MODIFY
src/bundle/make-console.js
src/bundle/make-console.js
-export function makeConsole(parentConsole) {
+export default function makeConsole(parentConsole) {
/* 'parentConsole' is the parent Realm's original 'console' object. We must
wrap it, exposing a 'console' with a 'console.log' (and perhaps others)
to the local realm, without allowing access to the original 'console',
@@ -89,7 +89,7 @@ export function makeConsole(parentConsole) {
// TODO: in a stack trace, this appears as
// "Object.newConsole.(anonymous function) [as trace]"
// can we make that "newConsole.trace" ?
- newConsole[name] = function(...args) {
+ newConsole[name] = function newerConsole(...args) {
callAndWrapError(orig, ...args);
};
}

MODIFY
src/bundle/nat.js
src/bundle/nat.js
* "https://mail.mozilla.org/pipermail/es-discuss/2013-July/031716.html"
* >Allen Wirfs-Brock's suggested phrasing</a> on es-discuss.
*/
-export function Nat(allegedNum) {
+export default function Nat(allegedNum) {
// TODO simplify by using Number.isSafeInteger
if (typeof allegedNum !== 'number') {
throw new RangeError('not a number');
}
+ // eslint-disable-next-line no-self-compare
if (allegedNum !== allegedNum) {
throw new RangeError('NaN not natural');
}

MODIFY
src/bundle/removeProperties.js
src/bundle/removeProperties.js
@@ -26,16 +26,18 @@ export default function removeProperties(global, whitelist) {
const uncurryThis = fn => (thisArg, ...args) =>
Reflect.apply(fn, thisArg, args);
- const gopd = Object.getOwnPropertyDescriptor;
- const gopn = Object.getOwnPropertyNames;
- const keys = Object.keys;
+ const {
+ getOwnPropertyDescriptor: gopd,
+ getOwnPropertyNames: gopn,
+ keys,
+ } = Object;
const cleaning = new WeakMap();
const getProto = Object.getPrototypeOf;
const hop = uncurryThis(Object.prototype.hasOwnProperty);
const whiteTable = new WeakMap();
- function addToWhiteTable(global, rootPermit) {
+ function addToWhiteTable(rootValue, rootPermit) {
/**
* The whiteTable should map from each path-accessible primordial
* object to the permit object that describes how it should be
@@ -72,7 +74,7 @@ export default function removeProperties(global, whitelist) {
}
});
}
- register(global, rootPermit);
+ register(rootValue, rootPermit);
}
/**
@@ -90,8 +92,9 @@ export default function removeProperties(global, whitelist) {
return permit[name];
}
}
+ // eslint-disable-next-line no-constant-condition
while (true) {
- base = getProto(base);
+ base = getProto(base); // eslint-disable-line no-param-reassign
if (base === null) {
return false;
}
@@ -144,13 +147,13 @@ export default function removeProperties(global, whitelist) {
// and thus made safe.
// reportProperty(ses.severities.SAFE_SPEC_VIOLATION,
// 'Not a data property', path);
- delete value[name];
+ delete value[name]; // eslint-disable-line no-param-reassign
} else {
clean(desc.get, `${path}<getter>`, num + 1);
clean(desc.set, `${path}<setter>`, num + 1);
}
} else {
- delete value[name];
+ delete value[name]; // eslint-disable-line no-param-reassign
}
});
}

MODIFY
src/bundle/tame-date.js
src/bundle/tame-date.js
@@ -30,5 +30,5 @@ export default function tameDate() {
// disable Date.now
newDateConstructor.now = () => NaN;
- Date = newDateConstructor;
+ Date = newDateConstructor; // eslint-disable-line no-global-assign
}

MODIFY
src/bundle/tame-intl.js
src/bundle/tame-intl.js
@@ -18,6 +18,7 @@ export default function tameIntl() {
throw Error('disabled');
};
}
+ // eslint-disable-next-line no-extend-native
Object.prototype.toLocaleString = () => {
throw new Error('toLocaleString suppressed');
};

MODIFY
src/bundle/tame-regexp.js
src/bundle/tame-regexp.js
@@ -8,6 +8,7 @@ export default function tameRegExp() {
// On some engines we can't just do 'delete RegExp.$1'.
const unsafeRegExp = RegExp;
+ // eslint-disable-next-line no-global-assign
RegExp = function RegExp(...args) {
return Reflect.construct(unsafeRegExp, args, new.target);
};

MODIFY
test/test-def.js
test/test-def.js
@@ -4,9 +4,9 @@ import { SES } from '../src/index';
test('SES environment has def', t => {
const s = SES.makeSESRootRealm();
function check() {
- const defMe1 = function() {};
+ const defMe1 = function me() {};
defMe1.other = {};
- const defMe2 = def(defMe1);
+ const defMe2 = def(defMe1); // eslint-disable-line no-undef
return { defMe1, defMe2 };
}
const { defMe1, defMe2 } = s.evaluate(`${check}; check()`);

MODIFY
test/test-nat.js
test/test-nat.js
@@ -4,7 +4,7 @@ import { SES } from '../src/index';
test('SES environment has Nat', t => {
const s = SES.makeSESRootRealm();
function check() {
- const n = x => Nat(x);
+ const n = x => Nat(x); // eslint-disable-line no-undef
return { n };
}
const { n } = s.evaluate(`${check}; check()`);

MODIFY
test/test.js
test/test.js
@@ -9,7 +9,7 @@ test('create', t => {
});
test('SESRealm does not see primal realm names', t => {
- const hidden = 1;
+ const hidden = 1; // eslint-disable-line no-unused-vars
const s = SES.makeSESRootRealm();
t.throws(() => s.evaluate('hidden+1'), ReferenceError);
t.end();
@@ -50,7 +50,7 @@ test('SESRealm has SES.confine', t => {
test('SESRealm.SES wraps exceptions', t => {
const s = SES.makeSESRootRealm();
function fail() {
- missing;
+ missing; // eslint-disable-line no-unused-expressions,no-undef
}
function check(failStr) {
try {
@@ -72,6 +72,8 @@ test('SESRealm.SES wraps exceptions', t => {
});
test('primal realm SES does not have confine', t => {
+ // we actually want to see if 'Object.SES' is present or not
+ // eslint-disable-next-line no-prototype-builtins
t.equal(Object.hasOwnProperty('SES'), false);
t.end();
});
@@ -87,11 +89,11 @@ test('main use case', t => {
}
return power(arg);
}
- const attenuated_power = s.evaluate(`(${attenuate})`, { power });
+ const attenuatedPower = s.evaluate(`(${attenuate})`, { power });
function use(arg) {
return power(arg);
}
- const user = s.evaluate(`(${use})`, { power: attenuated_power });
+ const user = s.evaluate(`(${use})`, { power: attenuatedPower });
t.equal(user(1), 2);
t.throws(() => user(-1), s.global.TypeError);
t.end();

more eslint appeasement

This changes all the clearly-correct cases, leaving the subtle ones for
a separate commit.