mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 18:07:34 +00:00
LibJS: Don't assume a this argument for function.prototype.bind
Assuming we had at least one argument meant that the ...arg count would underflow causing the bound function to have length 0 instead of the given length when binding with no arguments.
This commit is contained in:
parent
c4f3d44be1
commit
9d05ca7b20
2 changed files with 14 additions and 1 deletions
|
@ -126,6 +126,19 @@ describe("bound function |this|", () => {
|
|||
test("arrow functions cannot be bound", () => {
|
||||
expect((() => this).bind("foo")()).toBe(globalThis);
|
||||
});
|
||||
|
||||
test("length of original function is used for bound function", () => {
|
||||
[0, 1, 2147483647, 2147483648, 2147483649].forEach(value => {
|
||||
function emptyFunction() {}
|
||||
|
||||
Object.defineProperty(emptyFunction, "length", { value });
|
||||
|
||||
expect(emptyFunction.bind().length).toBe(value);
|
||||
expect(emptyFunction.bind(null).length).toBe(value);
|
||||
expect(emptyFunction.bind(null, 0).length).toBe(Math.max(0, value - 1));
|
||||
expect(emptyFunction.bind(null, 0, 1, 2).length).toBe(Math.max(0, value - 3));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("bound function constructors", () => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue