1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 11:28:12 +00:00

LibJS+LibWeb: Move the macro to convert ENOMEM to an exception to LibJS

Move the macro to LibJS and change it to return a throw completion
instead of a WebIDL exception. This will let us use this macro within
LibJS to handle OOM conditions.
This commit is contained in:
Timothy Flynn 2023-01-07 12:14:54 -05:00 committed by Linus Groh
parent ba97f6a0d3
commit d8044c5358
15 changed files with 118 additions and 93 deletions

View file

@ -5,6 +5,7 @@
*/
#include <AK/URLParser.h>
#include <LibJS/Runtime/Completion.h>
#include <LibWeb/Bindings/Intrinsics.h>
#include <LibWeb/Bindings/RequestPrototype.h>
#include <LibWeb/DOM/AbortSignal.h>
@ -174,13 +175,13 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<Request>> Request::construct_impl(JS::Realm
// method
// requests method.
request->set_method(TRY_OR_RETURN_OOM(realm, ByteBuffer::copy(input_request->method())));
request->set_method(TRY_OR_THROW_OOM(vm, ByteBuffer::copy(input_request->method())));
// header list
// A copy of requests header list.
auto header_list_copy = Infrastructure::HeaderList::create(vm);
for (auto& header : *input_request->header_list())
TRY_OR_RETURN_OOM(realm, header_list_copy->append(header));
TRY_OR_THROW_OOM(vm, header_list_copy->append(header));
request->set_header_list(header_list_copy);
// unsafe-request flag
@ -365,7 +366,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<Request>> Request::construct_impl(JS::Realm
return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, "Method must not be one of CONNECT, TRACE, or TRACK"sv };
// 3. Normalize method.
method = TRY_OR_RETURN_OOM(realm, Infrastructure::normalize_method(method.bytes()));
method = TRY_OR_THROW_OOM(vm, Infrastructure::normalize_method(method.bytes()));
// 4. Set requests method to method.
request->set_method(MUST(ByteBuffer::copy(method.bytes())));