1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-24 22:17:42 +00:00

LibJS: Add tests for the new steps added to PerformEval

This commit is contained in:
Luke Wilde 2022-04-10 00:56:04 +01:00 committed by Linus Groh
parent 34f902fb52
commit 7798821f5b
5 changed files with 388 additions and 0 deletions

View file

@ -20,6 +20,42 @@ test("basic functionality", () => {
expect(new baz().newTarget).toEqual(baz);
});
test("retrieving new.target from direct eval", () => {
function foo() {
return eval("new.target");
}
let result;
expect(() => {
result = foo();
}).not.toThrowWithMessage(SyntaxError, "'new.target' not allowed outside of a function");
expect(result).toBe(undefined);
expect(() => {
result = new foo();
}).not.toThrowWithMessage(SyntaxError, "'new.target' not allowed outside of a function");
expect(result).toBe(foo);
});
test("cannot retrieve new.target from indirect eval", () => {
const indirect = eval;
function foo() {
return indirect("new.target");
}
expect(() => {
foo();
}).toThrowWithMessage(SyntaxError, "'new.target' not allowed outside of a function");
expect(() => {
new foo();
}).toThrowWithMessage(SyntaxError, "'new.target' not allowed outside of a function");
});
test("syntax error outside of function", () => {
expect("new.target").not.toEval();
});