mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
script: implement ReadableByteStreamController (#35410)
* script: implement ReadableByteStreamController Signed-off-by: Taym Haddadi <haddadi.taym@gmail.com> * implement can_copy_data_block_bytes and copy_data_block_bytes Signed-off-by: Taym Haddadi <haddadi.taym@gmail.com> * Remove BufferSource::Default Signed-off-by: Taym Haddadi <haddadi.taym@gmail.com> * implement StartAlgorithmFulfillmentHandler, StartAlgorithmRejectionHandler, PullAlgorithmFulfillmentHandler, PullAlgorithmRejectionHandler for ReadableByteStreamController Signed-off-by: Taym Haddadi <haddadi.taym@gmail.com> * implement perform_pull_into Signed-off-by: Taym Haddadi <haddadi.taym@gmail.com> * fix build Signed-off-by: Taym Haddadi <haddadi.taym@gmail.com> * Fix clippy Signed-off-by: Taym Haddadi <haddadi.taym@gmail.com> * Fix build Signed-off-by: Taym Haddadi <haddadi.taym@gmail.com> * Remove RefCell from PullIntoDescriptor and QueueEntry Signed-off-by: Taym Haddadi <haddadi.taym@gmail.com> * Remove commented code Signed-off-by: Taym Haddadi <haddadi.taym@gmail.com> * add perform_cancel_steps, perform_release_steps and perform_pull_steps Signed-off-by: Taym Haddadi <haddadi.taym@gmail.com> * fix clippy Signed-off-by: Taym Haddadi <haddadi.taym@gmail.com> * fix crown Signed-off-by: Taym Haddadi <haddadi.taym@gmail.com> * unskip readable-byte-streams Signed-off-by: Taym Haddadi <haddadi.taym@gmail.com> * Fix CRASH Signed-off-by: Taym Haddadi <haddadi.taym@gmail.com> * fix clippy Signed-off-by: Taym Haddadi <haddadi.taym@gmail.com> * Fix more CRASHS Signed-off-by: Taym Haddadi <haddadi.taym@gmail.com> * fix more crashes Signed-off-by: Taym Haddadi <haddadi.taym@gmail.com> * Fix bad-buffers-and-views.any.js test Signed-off-by: Taym Haddadi <haddadi.taym@gmail.com> * Update test expectations Signed-off-by: Taym Haddadi <haddadi.taym@gmail.com> * Fix BorrowMutError crashes Signed-off-by: Taym Haddadi <haddadi.taym@gmail.com> * fix view_byte_length test Signed-off-by: Taym Haddadi <haddadi.taym@gmail.com> * Fix non-transferable-buffers test Signed-off-by: Taym Haddadi <haddadi.taym@gmail.com> * Pass contexts as much as possible by reference Signed-off-by: Taym Haddadi <haddadi.taym@gmail.com> * Make respond_internal Fallible Signed-off-by: Taym Haddadi <haddadi.taym@gmail.com> * Fix crwon Signed-off-by: Taym Haddadi <haddadi.taym@gmail.com> * fix process pull into descriptors using queue logic and resulting double-borrow Signed-off-by: gterzian <2792687+gterzian@users.noreply.github.com> * Fix clippy Signed-off-by: Taym Haddadi <haddadi.taym@gmail.com> * FIx more crashes Signed-off-by: Taym Haddadi <haddadi.taym@gmail.com> * Fix timeout tests Signed-off-by: Taym Haddadi <haddadi.taym@gmail.com> * Fix all tests Signed-off-by: Taym Haddadi <haddadi.taym@gmail.com> * Remove all error! logs Signed-off-by: Taym Haddadi <haddadi.taym@gmail.com> * Remove #[allow(unsafe_code)] Signed-off-by: Taym Haddadi <haddadi.taym@gmail.com> * Fix lint Signed-off-by: Taym Haddadi <haddadi.taym@gmail.com> * Fix tidy Signed-off-by: Taym Haddadi <haddadi.taym@gmail.com> * Fix test expectation Signed-off-by: Taym Haddadi <haddadi.taym@gmail.com> --------- Signed-off-by: Taym Haddadi <haddadi.taym@gmail.com> Signed-off-by: gterzian <2792687+gterzian@users.noreply.github.com> Co-authored-by: gterzian <2792687+gterzian@users.noreply.github.com>
This commit is contained in:
parent
459aee27b6
commit
a5cf04c479
30 changed files with 3410 additions and 324 deletions
|
@ -14,6 +14,7 @@ use js::rust::{HandleObject as SafeHandleObject, HandleValue as SafeHandleValue}
|
|||
|
||||
use super::bindings::reflector::reflect_dom_object;
|
||||
use super::bindings::root::MutNullableDom;
|
||||
use super::readablebytestreamcontroller::ReadableByteStreamController;
|
||||
use super::types::ReadableStreamDefaultController;
|
||||
use crate::dom::bindings::cell::DomRefCell;
|
||||
use crate::dom::bindings::codegen::Bindings::ReadableStreamDefaultReaderBinding::{
|
||||
|
@ -410,7 +411,7 @@ impl ReadableStreamDefaultReader {
|
|||
}
|
||||
|
||||
/// <https://streams.spec.whatwg.org/#readable-stream-default-reader-read>
|
||||
pub(crate) fn read(&self, read_request: &ReadRequest, can_gc: CanGc) {
|
||||
pub(crate) fn read(&self, cx: SafeJSContext, read_request: &ReadRequest, can_gc: CanGc) {
|
||||
// Let stream be reader.[[stream]].
|
||||
|
||||
// Assert: stream is not undefined.
|
||||
|
@ -435,7 +436,7 @@ impl ReadableStreamDefaultReader {
|
|||
// Assert: stream.[[state]] is "readable".
|
||||
assert!(stream.is_readable());
|
||||
// Perform ! stream.[[controller]].[[PullSteps]](readRequest).
|
||||
stream.perform_pull_steps(read_request, can_gc);
|
||||
stream.perform_pull_steps(cx, read_request, can_gc);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -505,6 +506,30 @@ impl ReadableStreamDefaultReader {
|
|||
can_gc,
|
||||
);
|
||||
}
|
||||
|
||||
/// step 3 of <https://streams.spec.whatwg.org/#abstract-opdef-readablebytestreamcontrollerprocessreadrequestsusingqueue>
|
||||
pub(crate) fn process_read_requests(
|
||||
&self,
|
||||
cx: SafeJSContext,
|
||||
controller: DomRoot<ReadableByteStreamController>,
|
||||
can_gc: CanGc,
|
||||
) -> Fallible<()> {
|
||||
// While reader.[[readRequests]] is not empty,
|
||||
while !self.read_requests.borrow().is_empty() {
|
||||
// If controller.[[queueTotalSize]] is 0, return.
|
||||
if controller.get_queue_total_size() == 0.0 {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
// Let readRequest be reader.[[readRequests]][0].
|
||||
// Remove entry from controller.[[queue]].
|
||||
let read_request = self.remove_read_request();
|
||||
|
||||
// Perform ! ReadableByteStreamControllerFillReadRequestFromQueue(controller, readRequest).
|
||||
controller.fill_read_request_from_queue(cx, &read_request, can_gc)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl ReadableStreamDefaultReaderMethods<crate::DomTypeHolder> for ReadableStreamDefaultReader {
|
||||
|
@ -525,9 +550,9 @@ impl ReadableStreamDefaultReaderMethods<crate::DomTypeHolder> for ReadableStream
|
|||
|
||||
/// <https://streams.spec.whatwg.org/#default-reader-read>
|
||||
fn Read(&self, can_gc: CanGc) -> Rc<Promise> {
|
||||
let cx = GlobalScope::get_cx();
|
||||
// If this.[[stream]] is undefined, return a promise rejected with a TypeError exception.
|
||||
if self.stream.get().is_none() {
|
||||
let cx = GlobalScope::get_cx();
|
||||
rooted!(in(*cx) let mut error = UndefinedValue());
|
||||
Error::Type("stream is undefined".to_owned()).to_jsval(
|
||||
cx,
|
||||
|
@ -555,7 +580,7 @@ impl ReadableStreamDefaultReaderMethods<crate::DomTypeHolder> for ReadableStream
|
|||
let read_request = ReadRequest::Read(promise.clone());
|
||||
|
||||
// Perform ! ReadableStreamDefaultReaderRead(this, readRequest).
|
||||
self.read(&read_request, can_gc);
|
||||
self.read(cx, &read_request, can_gc);
|
||||
|
||||
// Return promise.
|
||||
promise
|
||||
|
@ -579,7 +604,7 @@ impl ReadableStreamDefaultReaderMethods<crate::DomTypeHolder> for ReadableStream
|
|||
|
||||
/// <https://streams.spec.whatwg.org/#generic-reader-cancel>
|
||||
fn Cancel(&self, _cx: SafeJSContext, reason: SafeHandleValue, can_gc: CanGc) -> Rc<Promise> {
|
||||
self.cancel(&self.global(), reason, can_gc)
|
||||
self.generic_cancel(&self.global(), reason, can_gc)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue