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

LibJS: Let WrappedFunction inherit target name and length

This is a normative change in the ShadowRealm spec.

See: b73a1dc
This commit is contained in:
Linus Groh 2022-01-24 19:14:04 +00:00
parent 886d6c62f9
commit e20efaa083
6 changed files with 119 additions and 21 deletions

View file

@ -46,6 +46,37 @@ describe("normal behavior", () => {
expect(typeof wrappedFunction).toBe("function");
expect(Object.getPrototypeOf(wrappedFunction)).toBe(Function.prototype);
expect(shadowRealm.evaluate("(function () {})").name).toBe("wrapped ");
expect(shadowRealm.evaluate("(function foo() {})").name).toBe("wrapped foo");
expect(shadowRealm.evaluate("(function () {})")).toHaveLength(0);
expect(shadowRealm.evaluate("(function (foo, bar) {})")).toHaveLength(2);
expect(
shadowRealm.evaluate(
"Object.defineProperty(function () {}, 'length', { get() { return -Infinity } })"
)
).toHaveLength(0);
expect(
shadowRealm.evaluate(
"Object.defineProperty(function () {}, 'length', { get() { return Infinity } })"
)
).toHaveLength(Infinity);
for (const property of ["name", "length"]) {
expect(() => {
shadowRealm.evaluate(
`
function foo() {}
Object.defineProperty(foo, "${property}", {
get() { throw Error(); }
});
`
);
}).toThrowWithMessage(
TypeError,
"Trying to copy target name and length did not complete normally"
);
}
expect(() => {
shadowRealm.evaluate("(function () { throw Error(); })")();
}).toThrowWithMessage(