ReadableStream: remove the use of get_js_stream and use DomRoot<ReadableStream> (#34836)

* Remove the use of get_js_stream and use DomRoot<ReadableStream>

Signed-off-by: Taym Haddadi <haddadi.taym@gmail.com>

* return an error instead of Option

Signed-off-by: Taym Haddadi <haddadi.taym@gmail.com>

---------

Signed-off-by: Taym Haddadi <haddadi.taym@gmail.com>
This commit is contained in:
Taym Haddadi 2025-01-05 12:37:15 +01:00 committed by GitHub
parent 15eb405f36
commit bcad0d50e9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 43 additions and 52 deletions

View file

@ -1909,12 +1909,15 @@ impl GlobalScope {
}
/// <https://w3c.github.io/FileAPI/#blob-get-stream>
pub fn get_blob_stream(&self, blob_id: &BlobId, can_gc: CanGc) -> DomRoot<ReadableStream> {
pub fn get_blob_stream(
&self,
blob_id: &BlobId,
can_gc: CanGc,
) -> Fallible<DomRoot<ReadableStream>> {
let (file_id, size) = match self.get_blob_bytes_or_file_id(blob_id) {
BlobResult::Bytes(bytes) => {
// If we have all the bytes in memory, queue them and close the stream.
let stream = ReadableStream::new_from_bytes(self, bytes, can_gc);
return stream;
return ReadableStream::new_from_bytes(self, bytes, can_gc);
},
BlobResult::File(id, size) => (id, size),
};
@ -1923,7 +1926,7 @@ impl GlobalScope {
self,
UnderlyingSourceType::Blob(size),
can_gc,
);
)?;
let recv = self.send_msg(file_id);
@ -1942,7 +1945,7 @@ impl GlobalScope {
}),
);
stream
Ok(stream)
}
pub fn read_file_async(&self, id: Uuid, promise: Rc<Promise>, callback: FileListenerCallback) {