Divide module vs realm tests
RENAME
shim/test/realm/accessors.js
shim/test/module/accessors.js
RENAME
shim/test/realm/evaluators.js
shim/test/module/evaluators.js
import test from 'tape';
+import sinon from 'sinon';
import {
createSafeEvaluatorFactory,
createSafeEvaluator,
@@ -8,12 +9,6 @@ import {
const unsafeRecord = { unsafeGlobal: this, unsafeEval: eval, unsafeFunction: Function };
-// Mimic repairFunctions.
-// eslint-disable-next-line no-proto
-Function.__proto__.constructor = () => {
- throw new Error();
-};
-
test('createSafeEvaluator', t => {
t.plan(27);
@@ -91,6 +86,12 @@ test('createSafeEvaluatorWhichTakesEndowments', t => {
test('createFunctionEvaluator', t => {
t.plan(6);
+ // Mimic repairFunctions.
+ // eslint-disable-next-line no-proto
+ sinon.stub(Function.__proto__, 'constructor').callsFake(() => {
+ throw new TypeError();
+ });
+
const safeGlobal = Object.create(null, { foo: { value: 1 }, bar: { value: 2, writable: true } });
const safeEval = createSafeEvaluator(createSafeEvaluatorFactory(unsafeRecord, safeGlobal));
const safeFunction = createFunctionEvaluator(unsafeRecord, safeEval);
@@ -149,4 +150,7 @@ test('createFunctionEvaluator', t => {
// t.equal(fn.foo, 1);
// t.equal(fn.bar, 2);
+
+ // eslint-disable-next-line no-proto
+ Function.__proto__.constructor.restore();
});

RENAME
shim/test/realm/functions.js
shim/test/module/functions.js
import test from 'tape';
import { repairFunctions } from '../../src/functions';
-repairFunctions();
-
test('Function.prototype.constructor', t => {
t.plan(4);
+ repairFunctions();
+
// eslint-disable-next-line no-new-func
t.doesNotThrow(() => Function(''));
@@ -20,6 +20,8 @@ test('Function.prototype.constructor', t => {
test('AsyncFunction.constructor', t => {
t.plan(1);
+ repairFunctions();
+
try {
const proto = Object.getPrototypeOf((0, eval)('(async function() {})'));
t.throws(() => proto.constructor(''), TypeError);
@@ -35,6 +37,8 @@ test('AsyncFunction.constructor', t => {
test('GeneratorFunction.constructor', t => {
t.plan(1);
+ repairFunctions();
+
try {
const proto = Object.getPrototypeOf((0, eval)('(function* () {})'));
t.throws(() => proto.constructor(''), TypeError);
@@ -50,6 +54,8 @@ test('GeneratorFunction.constructor', t => {
test('AsyncGeneratorFunction.constructor', t => {
t.plan(1);
+ repairFunctions();
+
try {
const proto = Object.getPrototypeOf((0, eval)('(async function* () {})'));
t.throws(() => proto.constructor(''), TypeError);

RENAME
shim/test/realm/optimizer.js
shim/test/module/optimizer.js
RENAME
shim/test/realm/scopeHandler.js
shim/test/module/scopeHandler.js
RENAME
shim/test/realm/stdlib.js
shim/test/module/stdlib.js
RENAME
shim/test/realm/utilities.js
shim/test/module/utilities.js
RENAME
shim/test/realm/confinement.js
shim/test/realm/test-confinement.js
Divide module vs realm tests