Skip to content

Commit

Permalink
Auto merge of #26810 - CYBAI:fix-infinite-stream, r=<try>
Browse files Browse the repository at this point in the history
Fix infinite stream and its missing incumbent script environment when newing a new stream

---
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes fix #26807
- [ ] There are tests for these changes OR
- [ ] These changes do not require tests because ___
  • Loading branch information
bors-servo committed Jun 7, 2020
2 parents 0645d8c + 4835422 commit e7ee127
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
12 changes: 12 additions & 0 deletions components/script/body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ use js::typedarray::{ArrayBuffer, CreateWith};
use mime::{self, Mime};
use net_traits::request::{BodyChunkRequest, BodySource as NetBodySource, RequestBody};
use script_traits::serializable::BlobImpl;
use std::cell::Cell;
use std::ptr;
use std::rc::Rc;
use std::str;
Expand Down Expand Up @@ -72,6 +73,7 @@ struct TransmitBodyConnectHandler {
bytes_sender: Option<IpcSender<Vec<u8>>>,
control_sender: IpcSender<BodyChunkRequest>,
in_memory: Option<Vec<u8>>,
in_memory_done: Cell<bool>,
source: BodySource,
}

Expand All @@ -91,6 +93,7 @@ impl TransmitBodyConnectHandler {
bytes_sender: None,
control_sender,
in_memory,
in_memory_done: Cell::new(false),
source,
}
}
Expand Down Expand Up @@ -155,6 +158,12 @@ impl TransmitBodyConnectHandler {

/// The entry point to <https://fetch.spec.whatwg.org/#concept-request-transmit-body>
fn transmit_body_chunk(&mut self) {
if self.in_memory_done.get() {
// Step 5.1.3
let _ = self.control_sender.send(BodyChunkRequest::Done);
return;
}

let stream = self.stream.clone();
let control_sender = self.control_sender.clone();
let bytes_sender = self
Expand All @@ -165,6 +174,9 @@ impl TransmitBodyConnectHandler {
// In case of the data being in-memory, send everything in one chunk, by-passing SpiderMonkey.
if let Some(bytes) = self.in_memory.clone() {
let _ = bytes_sender.send(bytes);
// Mark this body as `done` so that we can correctly make it as Done in next tick
// and we won't leave this stream too early
self.in_memory_done.set(true);
return;
}

Expand Down
3 changes: 2 additions & 1 deletion components/script/dom/readablestream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::dom::bindings::conversions::{ConversionBehavior, ConversionResult};
use crate::dom::bindings::error::Error;
use crate::dom::bindings::reflector::{reflect_dom_object, DomObject, Reflector};
use crate::dom::bindings::root::DomRoot;
use crate::dom::bindings::settings_stack::AutoEntryScript;
use crate::dom::bindings::settings_stack::{AutoEntryScript, AutoIncumbentScript};
use crate::dom::bindings::utils::get_dictionary_property;
use crate::dom::globalscope::GlobalScope;
use crate::dom::promise::Promise;
Expand Down Expand Up @@ -118,6 +118,7 @@ impl ReadableStream {
source: ExternalUnderlyingSource,
) -> DomRoot<ReadableStream> {
let _ar = enter_realm(global);
let _ais = AutoIncumbentScript::new(global);
let cx = global.get_cx();

let source = Rc::new(ExternalUnderlyingSourceController::new(source));
Expand Down

0 comments on commit e7ee127

Please sign in to comment.