Ver código fonte

LibWeb/Streams: Use MUST_OR_THROW_OOM() when creating JS exceptions

This cannot throw unless we OOM.
Linus Groh 2 anos atrás
pai
commit
1c165b67ef

+ 2 - 1
Userland/Libraries/LibWeb/Fetch/Body.cpp

@@ -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()) };
     }
 

+ 2 - 2
Userland/Libraries/LibWeb/Streams/AbstractOperations.cpp

@@ -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);

+ 1 - 1
Userland/Libraries/LibWeb/Streams/ReadableStreamDefaultReader.cpp

@@ -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()) };
     }

+ 2 - 1
Userland/Libraries/LibWeb/Streams/ReadableStreamGenericReader.cpp

@@ -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()) };
     }