mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
Auto merge of #24977 - ridhimrastogi:async-wasm-compilation-final, r=jdm
Add StreamConsumer wrapper and methods to response <!-- Please describe your changes on the following line: --> Add Streamconsumer wrapper to Response --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: --> - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [x] These changes fix #21476 <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
This commit is contained in:
commit
6e3c131139
6 changed files with 51 additions and 90 deletions
|
@ -40,6 +40,7 @@ use crate::dom::document::PendingRestyle;
|
|||
use crate::dom::htmlimageelement::SourceSet;
|
||||
use crate::dom::htmlmediaelement::{HTMLMediaElementFetchContext, MediaFrameRenderer};
|
||||
use crate::dom::identityhub::Identities;
|
||||
use crate::script_runtime::StreamConsumer;
|
||||
use crate::task::TaskBox;
|
||||
use app_units::Au;
|
||||
use canvas_traits::canvas::{
|
||||
|
@ -543,6 +544,7 @@ unsafe_no_jsmanaged_fields!(Arc<Mutex<dyn AudioRenderer>>);
|
|||
unsafe_no_jsmanaged_fields!(MediaSessionActionType);
|
||||
unsafe_no_jsmanaged_fields!(MediaMetadata);
|
||||
unsafe_no_jsmanaged_fields!(WebrenderIpcSender);
|
||||
unsafe_no_jsmanaged_fields!(StreamConsumer);
|
||||
|
||||
unsafe impl<'a> JSTraceable for &'a str {
|
||||
#[inline]
|
||||
|
|
|
@ -19,6 +19,7 @@ use crate::dom::headers::{is_obs_text, is_vchar};
|
|||
use crate::dom::headers::{Guard, Headers};
|
||||
use crate::dom::promise::Promise;
|
||||
use crate::dom::xmlhttprequest::Extractable;
|
||||
use crate::script_runtime::StreamConsumer;
|
||||
use dom_struct::dom_struct;
|
||||
use http::header::HeaderMap as HyperHeaders;
|
||||
use hyper::StatusCode;
|
||||
|
@ -48,6 +49,8 @@ pub struct Response {
|
|||
body: DomRefCell<NetTraitsResponseBody>,
|
||||
#[ignore_malloc_size_of = "Rc"]
|
||||
body_promise: DomRefCell<Option<(Rc<Promise>, BodyType)>>,
|
||||
#[ignore_malloc_size_of = "StreamConsumer"]
|
||||
stream_consumer: DomRefCell<Option<StreamConsumer>>,
|
||||
}
|
||||
|
||||
impl Response {
|
||||
|
@ -64,6 +67,7 @@ impl Response {
|
|||
url_list: DomRefCell::new(vec![]),
|
||||
body: DomRefCell::new(NetTraitsResponseBody::Empty),
|
||||
body_promise: DomRefCell::new(None),
|
||||
stream_consumer: DomRefCell::new(None),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -441,11 +445,24 @@ impl Response {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn set_stream_consumer(&self, sc: Option<StreamConsumer>) {
|
||||
*self.stream_consumer.borrow_mut() = sc;
|
||||
}
|
||||
|
||||
pub fn stream_chunk(&self, stream: &[u8]) {
|
||||
if let Some(stream_consumer) = self.stream_consumer.borrow_mut().as_ref() {
|
||||
stream_consumer.consume_chunk(stream);
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(unrooted_must_root)]
|
||||
pub fn finish(&self, body: Vec<u8>) {
|
||||
*self.body.borrow_mut() = NetTraitsResponseBody::Done(body);
|
||||
if let Some((p, body_type)) = self.body_promise.borrow_mut().take() {
|
||||
consume_body_with_promise(self, body_type, &p);
|
||||
}
|
||||
if let Some(stream_consumer) = self.stream_consumer.borrow_mut().take() {
|
||||
stream_consumer.stream_end();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue