mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-30 00:31:14 +00:00
LibWeb/Streams: Use MUST_OR_THROW_OOM() when creating JS exceptions
This cannot throw unless we OOM.
This commit is contained in:
parent
d192f44523
commit
1c165b67ef
Notes:
sideshowbarker
2024-07-16 21:39:23 +09:00
Author: https://github.com/linusg Commit: https://github.com/SerenityOS/serenity/commit/1c165b67ef Pull-request: https://github.com/SerenityOS/serenity/pull/18370 Reviewed-by: https://github.com/mattco98 ✅
|
@ -148,7 +148,8 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<JS::Promise>> consume_body(JS::Realm& realm
|
|||
{
|
||||
// 1. If object is unusable, then return a promise rejected with a TypeError.
|
||||
if (object.is_unusable()) {
|
||||
auto promise_capability = WebIDL::create_rejected_promise(realm, JS::TypeError::create(realm, "Body is unusable"sv).release_allocated_value_but_fixme_should_propagate_errors());
|
||||
auto exception = MUST_OR_THROW_OOM(JS::TypeError::create(realm, "Body is unusable"sv));
|
||||
auto promise_capability = WebIDL::create_rejected_promise(realm, exception);
|
||||
return JS::NonnullGCPtr { verify_cast<JS::Promise>(*promise_capability->promise().ptr()) };
|
||||
}
|
||||
|
||||
|
|
|
@ -308,7 +308,7 @@ WebIDL::ExceptionOr<void> readable_stream_reader_generic_release(ReadableStreamG
|
|||
auto& realm = stream->realm();
|
||||
|
||||
// 4. If stream.[[state]] is "readable", reject reader.[[closedPromise]] with a TypeError exception.
|
||||
auto exception = TRY(JS::TypeError::create(realm, "Released readable stream"sv));
|
||||
auto exception = MUST_OR_THROW_OOM(JS::TypeError::create(realm, "Released readable stream"sv));
|
||||
if (stream->is_readable()) {
|
||||
WebIDL::reject_promise(realm, *reader.closed_promise_capability(), exception);
|
||||
}
|
||||
|
@ -389,7 +389,7 @@ WebIDL::ExceptionOr<void> readable_stream_default_reader_release(ReadableStreamD
|
|||
TRY(readable_stream_reader_generic_release(reader));
|
||||
|
||||
// 2. Let e be a new TypeError exception.
|
||||
auto e = TRY(JS::TypeError::create(realm, "Reader has been released"sv));
|
||||
auto e = MUST_OR_THROW_OOM(JS::TypeError::create(realm, "Reader has been released"sv));
|
||||
|
||||
// 3. Perform ! ReadableStreamDefaultReaderErrorReadRequests(reader, e).
|
||||
readable_stream_default_reader_error_read_requests(reader, e);
|
||||
|
|
|
@ -84,7 +84,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<JS::Promise>> ReadableStreamDefaultReader::
|
|||
|
||||
// 1. If this.[[stream]] is undefined, return a promise rejected with a TypeError exception.
|
||||
if (!m_stream) {
|
||||
auto exception = TRY(JS::TypeError::create(realm, "Cannot read from an empty stream"sv));
|
||||
auto exception = MUST_OR_THROW_OOM(JS::TypeError::create(realm, "Cannot read from an empty stream"sv));
|
||||
auto promise_capability = WebIDL::create_rejected_promise(realm, exception);
|
||||
return JS::NonnullGCPtr { verify_cast<JS::Promise>(*promise_capability->promise()) };
|
||||
}
|
||||
|
|
|
@ -27,7 +27,8 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<JS::Promise>> ReadableStreamGenericReaderMi
|
|||
// 1. If this.[[stream]] is undefined, return a promise rejected with a TypeError exception.
|
||||
if (!m_stream) {
|
||||
auto& realm = stream()->realm();
|
||||
auto promise_capability = WebIDL::create_rejected_promise(realm, TRY(JS::TypeError::create(realm, "No stream present to cancel"sv)));
|
||||
auto exception = MUST_OR_THROW_OOM(JS::TypeError::create(realm, "No stream present to cancel"sv));
|
||||
auto promise_capability = WebIDL::create_rejected_promise(realm, exception);
|
||||
return JS::NonnullGCPtr { verify_cast<JS::Promise>(*promise_capability->promise().ptr()) };
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue