mirror of
https://github.com/fergalmoran/ladybird.git
synced 2025-12-29 04:37:55 +00:00
LibJS: Throw RuntimeError when reaching the end of the stack
This prevents stack overflows when calling infinite/deep recursive
functions, e.g.:
const f = () => f(); f();
JSON.stringify({}, () => ({ foo: "bar" }));
new Proxy({}, { get: (_, __, p) => p.foo }).foo;
The VM caches a StackInfo object to not slow down function calls
considerably. VM::push_call_frame() will throw an exception if
necessary (plain Error with "RuntimeError" as its .name).
This commit is contained in:
committed by
Andreas Kling
parent
9c3ead8f91
commit
a02b9983f9
21
Libraries/LibJS/Tests/runtime-error-call-stack-size.js
Normal file
21
Libraries/LibJS/Tests/runtime-error-call-stack-size.js
Normal file
@@ -0,0 +1,21 @@
|
||||
test("infinite recursion", () => {
|
||||
function infiniteRecursion() {
|
||||
infiniteRecursion();
|
||||
}
|
||||
|
||||
try {
|
||||
infiniteRecursion();
|
||||
} catch (e) {
|
||||
expect(e).toBeInstanceOf(Error);
|
||||
expect(e.name).toBe("RuntimeError");
|
||||
expect(e.message).toBe("Call stack size limit exceeded");
|
||||
}
|
||||
|
||||
expect(() => {
|
||||
JSON.stringify({}, () => ({ foo: "bar" }));
|
||||
}).toThrowWithMessage(Error, "Call stack size limit exceeded");
|
||||
|
||||
expect(() => {
|
||||
new Proxy({}, { get: (_, __, p) => p.foo }).foo;
|
||||
}).toThrowWithMessage(Error, "Call stack size limit exceeded");
|
||||
});
|
||||
Reference in New Issue
Block a user