ladybird/Libraries/LibJS/Tests/runtime-error-call-stack-size.js
Timothy Flynn 911b915763 LibJS: Handle call stack limit exceptions in NewPromiseReactionJob
The promise job's fulfillment / rejection handlers may push an execution
context onto the VM, which will throw an internal error if our ad-hoc
call stack size limit has been reached. Thus, we cannot blindly VERIFY
that the result of invoking these handlers is non-abrupt.

This patch will propagate any internal error forward, and retains the
condition that any other error type is not thrown.
2025-02-05 08:05:01 -05:00

33 lines
908 B
JavaScript

test("infinite recursion", () => {
function infiniteRecursion() {
infiniteRecursion();
}
try {
infiniteRecursion();
} catch (e) {
expect(e).toBeInstanceOf(InternalError);
expect(e.name).toBe("InternalError");
expect(e.message).toBe("Call stack size limit exceeded");
}
expect(() => {
JSON.stringify({}, () => ({ foo: "bar" }));
}).toThrowWithMessage(InternalError, "Call stack size limit exceeded");
expect(() => {
new Proxy({}, { get: (_, __, p) => p.foo }).foo;
}).toThrowWithMessage(InternalError, "Call stack size limit exceeded");
expect(() => {
function outer() {
async function inner() {
await outer;
}
inner();
outer();
}
outer();
}).toThrowWithMessage(InternalError, "Call stack size limit exceeded");
});