Skip to content

Commit

Permalink
Merge pull request #18 from Agoric/function-this-bind
Browse files Browse the repository at this point in the history
add testcase for other Function this bindings
  • Loading branch information
erights authored Jul 8, 2019
2 parents 45b7c21 + 8fcbc4e commit 61cf8a0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
1 change: 0 additions & 1 deletion src/evaluators.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
15 changes: 15 additions & 0 deletions test/realm/test-confinement.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 61cf8a0

Please sign in to comment.