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

LibJS: Don't crash on broken promises in AsyncGenerator#return

See: https://github.com/tc39/ecma262/pull/2683
This commit is contained in:
Luke Wilde 2023-07-14 22:23:43 +01:00 committed by Linus Groh
parent d1cb78c411
commit e86d7cab06
4 changed files with 58 additions and 15 deletions

View file

@ -143,4 +143,25 @@ describe("errors", () => {
expect(rejection).toBeInstanceOf(TypeError);
expect(rejection.message).toBe("Not an object of type AsyncGenerator");
});
// https://github.com/tc39/ecma262/pull/2683
test("doesn't crash on broken promises", () => {
const promise = Promise.resolve(1337);
Object.defineProperty(promise, "constructor", {
get: function () {
throw new Error("yaksplode");
},
});
async function* generator() {}
const generatorObject = generator();
let rejection = null;
generatorObject.return(promise).catch(error => {
rejection = error;
});
runQueuedPromiseJobs();
expect(rejection).toBeInstanceOf(Error);
expect(rejection.message).toBe("yaksplode");
});
});