Fix Function with no arguments
MODIFY
shim/src/evaluators.js
shim/src/evaluators.js
@@ -180,7 +180,7 @@ export function createFunctionEvaluator(unsafeRec, safeEval) {
const { unsafeFunction, unsafeGlobal } = unsafeRec;
const safeFunction = function Function(...params) {
- const functionBody = `${arrayPop(params)}` || '';
+ const functionBody = `${arrayPop(params) || ''}`;
let functionParams = `${arrayJoin(params, ',')}`;
// Is this a real functionBody, or is someone attempting an injection

MODIFY
shim/test/realm/function-eval.js
shim/test/realm/function-eval.js
import test from 'tape';
import Realm from '../../src/realm';
+test('function-no-body', t => {
+ const r = Realm.makeRootRealm();
+ const f1 = new r.global.Function();
+ const src = f1.toString();
+ t.notOk(src.includes('undefined'));
+ t.equal(f1(), undefined);
+ t.end();
+});
+
test('function-injection', t => {
const goodFunc = 'return a+1';
const r = Realm.makeRootRealm();

Fix Function with no arguments (#128)