Skip to content

Commit

Permalink
Auto merge of #29881 - jdm:no-streams, r=<try>
Browse files Browse the repository at this point in the history
Remove JS stream usage

Rewrite readable stream code to avoid use of JS streams. Fixes #29088.
  • Loading branch information
bors-servo committed Jun 16, 2023
2 parents 1fb7d45 + 759696b commit 113ef95
Show file tree
Hide file tree
Showing 7 changed files with 227 additions and 103 deletions.
14 changes: 7 additions & 7 deletions components/script/body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,23 +296,23 @@ impl Callback for TransmitBodyPromiseHandler {
// Step 5.5, the "otherwise" steps.
// TODO: terminate fetch.
let _ = self.control_sender.send(BodyChunkRequest::Done);
return self.stream.stop_reading();
return self.stream.stop_reading(cx);
},
};

if is_done {
// Step 5.3, the "done" steps.
// TODO: queue a fetch task on request to process request end-of-body.
let _ = self.control_sender.send(BodyChunkRequest::Done);
return self.stream.stop_reading();
return self.stream.stop_reading(cx);
}

let chunk = match get_read_promise_bytes(cx.clone(), &v) {
Ok(chunk) => chunk,
Err(_) => {
// Step 5.5, the "otherwise" steps.
let _ = self.control_sender.send(BodyChunkRequest::Error);
return self.stream.stop_reading();
return self.stream.stop_reading(cx);
},
};

Expand All @@ -336,10 +336,10 @@ struct TransmitBodyPromiseRejectionHandler {

impl Callback for TransmitBodyPromiseRejectionHandler {
/// <https://fetch.spec.whatwg.org/#concept-request-transmit-body>
fn callback(&self, _cx: JSContext, _v: HandleValue, _realm: InRealm) {
fn callback(&self, cx: JSContext, _v: HandleValue, _realm: InRealm) {
// Step 5.4, the "rejection" steps.
let _ = self.control_sender.send(BodyChunkRequest::Error);
return self.stream.stop_reading();
return self.stream.stop_reading(cx);
}
}

Expand Down Expand Up @@ -660,7 +660,7 @@ impl Callback for ConsumeBodyPromiseHandler {
let is_done = match get_read_promise_done(cx.clone(), &v) {
Ok(is_done) => is_done,
Err(err) => {
stream.stop_reading();
stream.stop_reading(cx);
// When read is fulfilled with a value that doesn't matches with neither of the above patterns.
return self.result_promise.reject_error(err);
},
Expand All @@ -673,7 +673,7 @@ impl Callback for ConsumeBodyPromiseHandler {
let chunk = match get_read_promise_bytes(cx.clone(), &v) {
Ok(chunk) => chunk,
Err(err) => {
stream.stop_reading();
stream.stop_reading(cx);
// When read is fulfilled with a value that matches with neither of the above patterns
return self.result_promise.reject_error(err);
},
Expand Down
4 changes: 3 additions & 1 deletion components/script/dom/blob.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,9 @@ impl BlobMethods for Blob {

// <https://w3c.github.io/FileAPI/#blob-get-stream>
fn Stream(&self, _cx: JSContext) -> NonNull<JSObject> {
self.get_stream().get_js_stream()
//self.get_stream().get_js_stream()
let stream = self.get_stream();
NonNull::new(*stream.reflector().get_jsobject()).expect("shouldn't be null")
}

// https://w3c.github.io/FileAPI/#slice-method-algo
Expand Down

0 comments on commit 113ef95

Please sign in to comment.