mirror of
https://github.com/fergalmoran/ladybird.git
synced 2026-01-03 07:07:23 +00:00
Everywhere: Hoist the Libraries folder to the top-level
This commit is contained in:
committed by
Andreas Kling
parent
950e819ee7
commit
93712b24bf
61
Libraries/LibJS/Tests/functions/function-new-target.js
Normal file
61
Libraries/LibJS/Tests/functions/function-new-target.js
Normal file
@@ -0,0 +1,61 @@
|
||||
test("basic functionality", () => {
|
||||
function foo() {
|
||||
return new.target;
|
||||
}
|
||||
expect(foo()).toBeUndefined();
|
||||
expect(new foo()).toEqual(foo);
|
||||
|
||||
function bar() {
|
||||
const baz = () => new.target;
|
||||
return baz();
|
||||
}
|
||||
expect(bar()).toBeUndefined();
|
||||
expect(new bar()).toEqual(bar);
|
||||
|
||||
class baz {
|
||||
constructor() {
|
||||
this.newTarget = new.target;
|
||||
}
|
||||
}
|
||||
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();
|
||||
});
|
||||
Reference in New Issue
Block a user