mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 06:18:14 +00:00
LibJS: Throw InternalErrors instead of Errors on CallStackSizeExceeded
These seem more appropriate.
This commit is contained in:
parent
7341faceeb
commit
957f54d96f
6 changed files with 9 additions and 9 deletions
|
@ -1517,7 +1517,7 @@ static ThrowCompletionOr<size_t> flatten_into_array(GlobalObject& global_object,
|
||||||
|
|
||||||
if (depth > 0 && TRY(value.is_array(global_object))) {
|
if (depth > 0 && TRY(value.is_array(global_object))) {
|
||||||
if (vm.did_reach_stack_space_limit())
|
if (vm.did_reach_stack_space_limit())
|
||||||
return vm.throw_completion<Error>(global_object, ErrorType::CallStackSizeExceeded);
|
return vm.throw_completion<InternalError>(global_object, ErrorType::CallStackSizeExceeded);
|
||||||
|
|
||||||
auto length = TRY(length_of_array_like(global_object, value.as_object()));
|
auto length = TRY(length_of_array_like(global_object, value.as_object()));
|
||||||
target_index = TRY(flatten_into_array(global_object, new_array, value.as_object(), length, target_index, depth - 1));
|
target_index = TRY(flatten_into_array(global_object, new_array, value.as_object(), length, target_index, depth - 1));
|
||||||
|
|
|
@ -487,7 +487,7 @@ ThrowCompletionOr<Value> ProxyObject::internal_get(PropertyKey const& property_n
|
||||||
//
|
//
|
||||||
// In JS code: `h = {}; p = new Proxy({}, h); h.__proto__ = p; p.foo // or h.foo`
|
// In JS code: `h = {}; p = new Proxy({}, h); h.__proto__ = p; p.foo // or h.foo`
|
||||||
if (vm.did_reach_stack_space_limit())
|
if (vm.did_reach_stack_space_limit())
|
||||||
return vm.throw_completion<Error>(global_object, ErrorType::CallStackSizeExceeded);
|
return vm.throw_completion<InternalError>(global_object, ErrorType::CallStackSizeExceeded);
|
||||||
|
|
||||||
// 6. Let trap be ? GetMethod(handler, "get").
|
// 6. Let trap be ? GetMethod(handler, "get").
|
||||||
auto trap = TRY(Value(&m_handler).get_method(global_object, vm.names.get));
|
auto trap = TRY(Value(&m_handler).get_method(global_object, vm.names.get));
|
||||||
|
|
|
@ -103,7 +103,7 @@ public:
|
||||||
VERIFY(!exception());
|
VERIFY(!exception());
|
||||||
// Ensure we got some stack space left, so the next function call doesn't kill us.
|
// Ensure we got some stack space left, so the next function call doesn't kill us.
|
||||||
if (did_reach_stack_space_limit())
|
if (did_reach_stack_space_limit())
|
||||||
return throw_completion<Error>(global_object, ErrorType::CallStackSizeExceeded);
|
return throw_completion<InternalError>(global_object, ErrorType::CallStackSizeExceeded);
|
||||||
m_execution_context_stack.append(&context);
|
m_execution_context_stack.append(&context);
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,7 @@ describe("error", () => {
|
||||||
a[0] = a;
|
a[0] = a;
|
||||||
expect(() => {
|
expect(() => {
|
||||||
a.flat(3893232121);
|
a.flat(3893232121);
|
||||||
}).toThrowWithMessage(Error, "Call stack size limit exceeded");
|
}).toThrowWithMessage(InternalError, "Call stack size limit exceeded");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -114,5 +114,5 @@ test("Proxy handler that has the Proxy itself as its prototype", () => {
|
||||||
handler.__proto__ = proxy;
|
handler.__proto__ = proxy;
|
||||||
expect(() => {
|
expect(() => {
|
||||||
proxy.foo;
|
proxy.foo;
|
||||||
}).toThrowWithMessage(Error, "Call stack size limit exceeded");
|
}).toThrowWithMessage(InternalError, "Call stack size limit exceeded");
|
||||||
});
|
});
|
||||||
|
|
|
@ -6,16 +6,16 @@ test("infinite recursion", () => {
|
||||||
try {
|
try {
|
||||||
infiniteRecursion();
|
infiniteRecursion();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
expect(e).toBeInstanceOf(Error);
|
expect(e).toBeInstanceOf(InternalError);
|
||||||
expect(e.name).toBe("Error");
|
expect(e.name).toBe("InternalError");
|
||||||
expect(e.message).toBe("Call stack size limit exceeded");
|
expect(e.message).toBe("Call stack size limit exceeded");
|
||||||
}
|
}
|
||||||
|
|
||||||
expect(() => {
|
expect(() => {
|
||||||
JSON.stringify({}, () => ({ foo: "bar" }));
|
JSON.stringify({}, () => ({ foo: "bar" }));
|
||||||
}).toThrowWithMessage(Error, "Call stack size limit exceeded");
|
}).toThrowWithMessage(InternalError, "Call stack size limit exceeded");
|
||||||
|
|
||||||
expect(() => {
|
expect(() => {
|
||||||
new Proxy({}, { get: (_, __, p) => p.foo }).foo;
|
new Proxy({}, { get: (_, __, p) => p.foo }).foo;
|
||||||
}).toThrowWithMessage(Error, "Call stack size limit exceeded");
|
}).toThrowWithMessage(InternalError, "Call stack size limit exceeded");
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue