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

LibJS: Return non-object argument unaltered from Object.setPrototypeOf()

This was missing step 3 from the spec:

    3. If Type(O) is not Object, return O.

Also use RequireObjectCoercible() for a better error message and make
the rest of the code a bit easier to read and more similar to the spec
text.
This commit is contained in:
Linus Groh 2021-06-22 18:59:24 +01:00
parent 1f8b6ac3c3
commit 8a06a93ce2
2 changed files with 18 additions and 11 deletions

View file

@ -9,6 +9,13 @@ describe("correct behavior", () => {
expect(Object.setPrototypeOf(o, p)).toBe(o);
expect(Object.getPrototypeOf(o)).toBe(p);
});
test("non-object argument is returned without being coerced to object", () => {
let o = 42;
let p = {};
expect(Object.setPrototypeOf(o, p)).toBe(o);
expect(Object.getPrototypeOf(o)).toBe(Number.prototype);
});
});
describe("errors", () => {