diff --git a/src/evaluators.js b/src/evaluators.js index 42d1016..31493a7 100644 --- a/src/evaluators.js +++ b/src/evaluators.js @@ -227,7 +227,6 @@ export function createFunctionEvaluator(unsafeRec, safeEval) { functionParams += '\n/*``*/'; } - // todo: fix `this` binding in Function(). const src = `(function(${functionParams}){\n${functionBody}\n})`; return safeEval(src); diff --git a/test/realm/test-confinement.js b/test/realm/test-confinement.js index 2716cfa..9ddf5a2 100644 --- a/test/realm/test-confinement.js +++ b/test/realm/test-confinement.js @@ -10,6 +10,21 @@ test('confinement evaluation strict mode', t => { t.equal(r.evaluate('(new Function("return this"))()'), undefined); }); +test('constructor this binding', t => { + const r = Realm.makeRootRealm(); + const F = r.evaluate('(new Function("return this"))'); + + t.equal(F(), undefined); + t.equal(F.call(8), 8); + t.equal(F.call(undefined), undefined); + t.equal(Reflect.apply(F, 8, []), 8); + + const x = { F }; + t.equal(x.F(), x); + + t.end(); +}); + test('confinement evaluation constructor', t => { t.plan(2);