mirror of
https://github.com/RGBCube/serenity
synced 2025-07-10 04:07:35 +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:
parent
9c3ead8f91
commit
a02b9983f9
5 changed files with 58 additions and 18 deletions
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");
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue