Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add testcase for other Function this bindings #18

Merged
merged 3 commits into from
Jul 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/evaluators.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,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