mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 05:27:45 +00:00
LibJS: Implement Function.prototype.bind() according to the spec :^)
This commit is contained in:
parent
87b9fa2636
commit
898ad7c682
4 changed files with 66 additions and 20 deletions
|
@ -33,6 +33,20 @@ describe("basic behavior", () => {
|
|||
)
|
||||
).toBe(12);
|
||||
});
|
||||
|
||||
test("name has 'bound' prefix", () => {
|
||||
function foo() {}
|
||||
const boundFoo = foo.bind(123);
|
||||
expect(foo.name).toBe("foo");
|
||||
expect(boundFoo.name).toBe("bound foo");
|
||||
});
|
||||
|
||||
test("prototype is inherited from target function", () => {
|
||||
function foo() {}
|
||||
Object.setPrototypeOf(foo, Array.prototype);
|
||||
const boundFoo = Function.prototype.bind.call(foo, 123);
|
||||
expect(Object.getPrototypeOf(boundFoo)).toBe(Array.prototype);
|
||||
});
|
||||
});
|
||||
|
||||
describe("bound function arguments", () => {
|
||||
|
@ -144,6 +158,6 @@ describe("errors", () => {
|
|||
test("does not accept non-function values", () => {
|
||||
expect(() => {
|
||||
Function.prototype.bind.call("foo");
|
||||
}).toThrowWithMessage(TypeError, "Not an object of type Function");
|
||||
}).toThrowWithMessage(TypeError, "foo is not a function");
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue