mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 19:38:12 +00:00
LibJS: Rewrite Array.prototype.slice to be spec compliant
This makes it generic in the process (which is required by jQuery) This fixes 19 test262 test cases :^)
This commit is contained in:
parent
2e1a01a499
commit
d72aeb2e1a
3 changed files with 87 additions and 28 deletions
|
@ -39,6 +39,18 @@ describe("ability to work with generic non-array objects", () => {
|
|||
expect(removed[1]).toBeUndefined();
|
||||
});
|
||||
|
||||
test("slice", () => {
|
||||
const o = { length: 3, 0: "hello", 2: "serenity" };
|
||||
const slice = Array.prototype.slice.call(o, 0, 2);
|
||||
expect(o).toHaveLength(3);
|
||||
expect(o[0]).toBe("hello");
|
||||
expect(o[1]).toBeUndefined();
|
||||
expect(o[2]).toBe("serenity");
|
||||
expect(slice).toHaveLength(2);
|
||||
expect(slice[0]).toBe("hello");
|
||||
expect(slice[1]).toBeUndefined();
|
||||
});
|
||||
|
||||
test("join", () => {
|
||||
expect(Array.prototype.join.call({})).toBe("");
|
||||
expect(Array.prototype.join.call({ length: "foo" })).toBe("");
|
||||
|
|
|
@ -37,3 +37,18 @@ test("basic functionality", () => {
|
|||
expect(array).toEqual(["hello", "friends", "serenity", 1]);
|
||||
expect(slice).toEqual(["hello", "friends", "serenity", 1]);
|
||||
});
|
||||
|
||||
// FIXME: These tests are currently skipped because an invalid array length in this case is 2**32 or above.
|
||||
// The codebase currently uses size_t for lengths, which is currently the same as u32 when building for Serenity.
|
||||
// This means these lengths wrap around to 0, making the test not work correctly.
|
||||
test.skip("Invalid lengths", () => {
|
||||
var length = Math.pow(2, 32);
|
||||
|
||||
var obj = {
|
||||
length: length,
|
||||
};
|
||||
|
||||
expect(() => {
|
||||
Array.prototype.slice.call(obj, 0);
|
||||
}).toThrowWithMessage(RangeError, "Invalid array length");
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue