Propagate CanGc when interacting with readable streams. (#33975)

Signed-off-by: Josh Matthews <josh@joshmatthews.net>
This commit is contained in:
Josh Matthews 2024-10-23 07:49:59 -04:00 committed by GitHub
parent f553bda7eb
commit 12e6ec25aa
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 80 additions and 57 deletions

View file

@ -190,7 +190,7 @@ impl ResponseMethods for Response {
total_bytes: _,
content_type,
source: _,
} = body.extract(global)?;
} = body.extract(global, can_gc)?;
r.body_stream.set(Some(&*stream));
@ -210,7 +210,7 @@ impl ResponseMethods for Response {
} else {
// Reset FetchResponse to an in-memory stream with empty byte sequence here for
// no-init-body case
let stream = ReadableStream::new_from_bytes(global, Vec::with_capacity(0));
let stream = ReadableStream::new_from_bytes(global, Vec::with_capacity(0), can_gc);
r.body_stream.set(Some(&*stream));
}
@ -444,12 +444,12 @@ impl Response {
*self.stream_consumer.borrow_mut() = sc;
}
pub fn stream_chunk(&self, chunk: Vec<u8>) {
pub fn stream_chunk(&self, chunk: Vec<u8>, can_gc: CanGc) {
// Note, are these two actually mutually exclusive?
if let Some(stream_consumer) = self.stream_consumer.borrow_mut().as_ref() {
stream_consumer.consume_chunk(chunk.as_slice());
} else if let Some(body) = self.body_stream.get() {
body.enqueue_native(chunk);
body.enqueue_native(chunk, can_gc);
}
}