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:
Taym Haddadi 2025-03-10 12:43:04 -07:00 committed by GitHub
parent 459aee27b6
commit a5cf04c479
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
30 changed files with 3410 additions and 324 deletions

View file

@ -32,7 +32,7 @@ use crate::dom::readablestreamdefaultreader::ReadRequest;
use crate::dom::underlyingsourcecontainer::{UnderlyingSourceContainer, UnderlyingSourceType};
use crate::js::conversions::ToJSValConvertible;
use crate::realms::{InRealm, enter_realm};
use crate::script_runtime::{CanGc, JSContext, JSContext as SafeJSContext};
use crate::script_runtime::{CanGc, JSContext as SafeJSContext};
/// The fulfillment handler for
/// <https://streams.spec.whatwg.org/#readable-stream-default-controller-call-pull-if-needed>
@ -45,7 +45,7 @@ struct PullAlgorithmFulfillmentHandler {
impl Callback for PullAlgorithmFulfillmentHandler {
/// Continuation of <https://streams.spec.whatwg.org/#readable-stream-default-controller-call-pull-if-needed>
/// Upon fulfillment of pullPromise
fn callback(&self, _cx: JSContext, _v: HandleValue, _realm: InRealm, can_gc: CanGc) {
fn callback(&self, _cx: SafeJSContext, _v: HandleValue, _realm: InRealm, can_gc: CanGc) {
// Set controller.[[pulling]] to false.
self.controller.pulling.set(false);
@ -71,7 +71,7 @@ struct PullAlgorithmRejectionHandler {
impl Callback for PullAlgorithmRejectionHandler {
/// Continuation of <https://streams.spec.whatwg.org/#readable-stream-default-controller-call-pull-if-needed>
/// Upon rejection of pullPromise with reason e.
fn callback(&self, _cx: JSContext, v: HandleValue, _realm: InRealm, can_gc: CanGc) {
fn callback(&self, _cx: SafeJSContext, v: HandleValue, _realm: InRealm, can_gc: CanGc) {
// Perform ! ReadableStreamDefaultControllerError(controller, e).
self.controller.error(v, can_gc);
}
@ -88,7 +88,7 @@ struct StartAlgorithmFulfillmentHandler {
impl Callback for StartAlgorithmFulfillmentHandler {
/// Continuation of <https://streams.spec.whatwg.org/#set-up-readable-stream-default-controller>
/// Upon fulfillment of startPromise,
fn callback(&self, _cx: JSContext, _v: HandleValue, _realm: InRealm, can_gc: CanGc) {
fn callback(&self, _cx: SafeJSContext, _v: HandleValue, _realm: InRealm, can_gc: CanGc) {
// Set controller.[[started]] to true.
self.controller.started.set(true);
@ -108,7 +108,7 @@ struct StartAlgorithmRejectionHandler {
impl Callback for StartAlgorithmRejectionHandler {
/// Continuation of <https://streams.spec.whatwg.org/#set-up-readable-stream-default-controller>
/// Upon rejection of startPromise with reason r,
fn callback(&self, _cx: JSContext, v: HandleValue, _realm: InRealm, can_gc: CanGc) {
fn callback(&self, _cx: SafeJSContext, v: HandleValue, _realm: InRealm, can_gc: CanGc) {
// Perform ! ReadableStreamDefaultControllerError(controller, r).
self.controller.error(v, can_gc);
}
@ -499,6 +499,8 @@ impl ReadableStreamDefaultController {
/// <https://streams.spec.whatwg.org/#readable-stream-default-controller-call-pull-if-needed>
fn call_pull_if_needed(&self, can_gc: CanGc) {
// Let shouldPull be ! ReadableStreamDefaultControllerShouldCallPull(controller).
// If shouldPull is false, return.
if !self.should_call_pull() {
return;
}