1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 21:07:34 +00:00

LibJS: Make Function.prototype a callable function object

20.2.3 Properties of the Function Prototype Object
https://tc39.es/ecma262/#sec-properties-of-the-function-prototype-object

The Function prototype object:
- is itself a built-in function object.
This commit is contained in:
Linus Groh 2022-08-13 23:55:41 +01:00
parent 913412e0c5
commit 849495915b
3 changed files with 45 additions and 5 deletions

View file

@ -0,0 +1,26 @@
describe("correct behavior", () => {
test("length is 0", () => {
expect(Function.prototype).toHaveLength(0);
});
test("name is empty string", () => {
expect(Function.prototype.name).toBe("");
});
test("basic functionality", () => {
function fn() {}
expect(Object.getPrototypeOf(fn)).toBe(Function.prototype);
expect(Object.getPrototypeOf(Function.prototype)).toBe(Object.prototype);
});
test("is callable", () => {
expect(Function.prototype()).toBeUndefined();
});
test("is not constructable", () => {
expect(() => new Function.prototype()).toThrowWithMessage(
TypeError,
"[object FunctionPrototype] is not a constructor (evaluated from 'Function.prototype')"
);
});
});