mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00: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
|
@ -248,7 +248,7 @@ impl AudioBufferMethods<crate::DomTypeHolder> for AudioBuffer {
|
|||
}
|
||||
|
||||
self.js_channels.borrow()[channel as usize]
|
||||
.get_buffer()
|
||||
.get_typed_array()
|
||||
.map_err(|_| Error::JSFailed)
|
||||
}
|
||||
|
||||
|
|
|
@ -16,15 +16,31 @@ use std::sync::Arc;
|
|||
#[cfg(feature = "webgpu")]
|
||||
use js::jsapi::NewExternalArrayBuffer;
|
||||
use js::jsapi::{
|
||||
GetArrayBufferByteLength, Heap, IsDetachedArrayBufferObject, JS_GetArrayBufferViewBuffer,
|
||||
JS_GetArrayBufferViewByteLength, JS_IsArrayBufferViewObject, JS_IsTypedArrayObject, JSObject,
|
||||
ArrayBufferClone, ArrayBufferCopyData, GetArrayBufferByteLength,
|
||||
HasDefinedArrayBufferDetachKey, Heap, IsArrayBufferObject, IsDetachedArrayBufferObject,
|
||||
JS_ClearPendingException, JS_GetArrayBufferViewBuffer, JS_GetArrayBufferViewByteLength,
|
||||
JS_GetArrayBufferViewByteOffset, JS_GetArrayBufferViewType, JS_GetPendingException,
|
||||
JS_GetTypedArrayLength, JS_IsArrayBufferViewObject, JS_IsTypedArrayObject,
|
||||
JS_NewBigInt64ArrayWithBuffer, JS_NewBigUint64ArrayWithBuffer, JS_NewDataView,
|
||||
JS_NewFloat16ArrayWithBuffer, JS_NewFloat32ArrayWithBuffer, JS_NewFloat64ArrayWithBuffer,
|
||||
JS_NewInt8ArrayWithBuffer, JS_NewInt16ArrayWithBuffer, JS_NewInt32ArrayWithBuffer,
|
||||
JS_NewUint8ArrayWithBuffer, JS_NewUint8ClampedArrayWithBuffer, JS_NewUint16ArrayWithBuffer,
|
||||
JS_NewUint32ArrayWithBuffer, JSObject, NewArrayBuffer, NewArrayBufferWithContents,
|
||||
StealArrayBufferContents, Type,
|
||||
};
|
||||
use js::jsval::{ObjectValue, UndefinedValue};
|
||||
use js::rust::wrappers::DetachArrayBuffer;
|
||||
use js::rust::{CustomAutoRooterGuard, Handle, MutableHandleObject};
|
||||
#[cfg(feature = "webgpu")]
|
||||
use js::typedarray::{ArrayBuffer, HeapArrayBuffer};
|
||||
use js::typedarray::{CreateWith, TypedArray, TypedArrayElement, TypedArrayElementCreator};
|
||||
use js::rust::{
|
||||
CustomAutoRooterGuard, Handle, MutableHandleObject,
|
||||
MutableHandleValue as SafeMutableHandleValue,
|
||||
};
|
||||
use js::typedarray::{
|
||||
ArrayBuffer, ArrayBufferU8, ArrayBufferView, ArrayBufferViewU8, CreateWith, HeapArrayBuffer,
|
||||
TypedArray, TypedArrayElement, TypedArrayElementCreator,
|
||||
};
|
||||
|
||||
use crate::dom::bindings::error::Error;
|
||||
use crate::dom::bindings::import::module::Fallible;
|
||||
#[cfg(feature = "webgpu")]
|
||||
use crate::dom::globalscope::GlobalScope;
|
||||
use crate::script_runtime::{CanGc, JSContext};
|
||||
|
@ -35,6 +51,7 @@ use crate::script_runtime::{CanGc, JSContext};
|
|||
/// provides a view onto an `ArrayBuffer`.
|
||||
///
|
||||
/// See: <https://webidl.spec.whatwg.org/#BufferSource>
|
||||
#[derive(PartialEq)]
|
||||
pub(crate) enum BufferSource {
|
||||
/// Represents an `ArrayBufferView` (e.g., `Uint8Array`, `DataView`).
|
||||
/// See: <https://webidl.spec.whatwg.org/#ArrayBufferView>
|
||||
|
@ -42,11 +59,7 @@ pub(crate) enum BufferSource {
|
|||
|
||||
/// Represents an `ArrayBuffer`, a fixed-length binary data buffer.
|
||||
/// See: <https://webidl.spec.whatwg.org/#idl-ArrayBuffer>
|
||||
#[allow(dead_code)]
|
||||
ArrayBuffer(Box<Heap<*mut JSObject>>),
|
||||
|
||||
/// Default variant, used as a placeholder in initialization.
|
||||
Default(Box<Heap<*mut JSObject>>),
|
||||
}
|
||||
|
||||
pub(crate) fn new_initialized_heap_buffer_source<T>(
|
||||
|
@ -69,16 +82,8 @@ where
|
|||
if typed_array_result.is_err() {
|
||||
return Err(());
|
||||
}
|
||||
let heap_buffer_source = HeapBufferSource::<T>::default();
|
||||
|
||||
match &heap_buffer_source.buffer_source {
|
||||
BufferSource::ArrayBufferView(buffer) |
|
||||
BufferSource::ArrayBuffer(buffer) |
|
||||
BufferSource::Default(buffer) => {
|
||||
buffer.set(*array);
|
||||
},
|
||||
}
|
||||
heap_buffer_source
|
||||
HeapBufferSource::<T>::new(BufferSource::ArrayBufferView(Heap::boxed(*array.handle())))
|
||||
},
|
||||
};
|
||||
Ok(heap_buffer_source)
|
||||
|
@ -94,6 +99,25 @@ pub(crate) struct HeapBufferSource<T> {
|
|||
phantom: PhantomData<T>,
|
||||
}
|
||||
|
||||
impl<T> Eq for HeapBufferSource<T> where T: TypedArrayElement {}
|
||||
|
||||
impl<T> PartialEq for HeapBufferSource<T>
|
||||
where
|
||||
T: TypedArrayElement,
|
||||
{
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
match &self.buffer_source {
|
||||
BufferSource::ArrayBufferView(heap) | BufferSource::ArrayBuffer(heap) => match &other
|
||||
.buffer_source
|
||||
{
|
||||
BufferSource::ArrayBufferView(from_heap) | BufferSource::ArrayBuffer(from_heap) => unsafe {
|
||||
heap.handle() == from_heap.handle()
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> HeapBufferSource<T>
|
||||
where
|
||||
T: TypedArrayElement,
|
||||
|
@ -105,34 +129,78 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
pub(crate) fn default() -> HeapBufferSource<T> {
|
||||
pub(crate) fn from_view(
|
||||
chunk: CustomAutoRooterGuard<ArrayBufferView>,
|
||||
) -> HeapBufferSource<ArrayBufferViewU8> {
|
||||
HeapBufferSource::<ArrayBufferViewU8>::new(BufferSource::ArrayBufferView(Heap::boxed(
|
||||
unsafe { *chunk.underlying_object() },
|
||||
)))
|
||||
}
|
||||
|
||||
pub(crate) fn default() -> Self {
|
||||
HeapBufferSource {
|
||||
buffer_source: BufferSource::Default(Box::default()),
|
||||
buffer_source: BufferSource::ArrayBufferView(Heap::boxed(std::ptr::null_mut())),
|
||||
phantom: PhantomData,
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn is_initialized(&self) -> bool {
|
||||
match &self.buffer_source {
|
||||
BufferSource::ArrayBufferView(buffer) |
|
||||
BufferSource::ArrayBuffer(buffer) |
|
||||
BufferSource::Default(buffer) => !buffer.get().is_null(),
|
||||
BufferSource::ArrayBufferView(buffer) | BufferSource::ArrayBuffer(buffer) => {
|
||||
!buffer.get().is_null()
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn get_buffer(&self) -> Result<TypedArray<T, *mut JSObject>, ()> {
|
||||
pub(crate) fn get_typed_array(&self) -> Result<TypedArray<T, *mut JSObject>, ()> {
|
||||
TypedArray::from(match &self.buffer_source {
|
||||
BufferSource::ArrayBufferView(buffer) |
|
||||
BufferSource::ArrayBuffer(buffer) |
|
||||
BufferSource::Default(buffer) => buffer.get(),
|
||||
BufferSource::ArrayBufferView(buffer) | BufferSource::ArrayBuffer(buffer) => {
|
||||
buffer.get()
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
pub(crate) fn get_buffer_view_value(
|
||||
&self,
|
||||
cx: JSContext,
|
||||
mut handle_mut: SafeMutableHandleValue,
|
||||
) {
|
||||
match &self.buffer_source {
|
||||
BufferSource::ArrayBufferView(buffer) => {
|
||||
rooted!(in(*cx) let value = ObjectValue(buffer.get()));
|
||||
handle_mut.set(*value);
|
||||
},
|
||||
BufferSource::ArrayBuffer(_) => {
|
||||
unreachable!("BufferSource::ArrayBuffer does not have a view buffer.")
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn get_array_buffer_view_buffer(
|
||||
&self,
|
||||
cx: JSContext,
|
||||
) -> HeapBufferSource<ArrayBufferU8> {
|
||||
match &self.buffer_source {
|
||||
BufferSource::ArrayBufferView(buffer) => unsafe {
|
||||
let mut is_shared = false;
|
||||
rooted!(in (*cx) let view_buffer =
|
||||
JS_GetArrayBufferViewBuffer(*cx, buffer.handle(), &mut is_shared));
|
||||
|
||||
HeapBufferSource::<ArrayBufferU8>::new(BufferSource::ArrayBuffer(Heap::boxed(
|
||||
*view_buffer.handle(),
|
||||
)))
|
||||
},
|
||||
BufferSource::ArrayBuffer(_) => {
|
||||
unreachable!("BufferSource::ArrayBuffer does not have a view buffer.")
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
/// <https://tc39.es/ecma262/#sec-detacharraybuffer>
|
||||
pub(crate) fn detach_buffer(&self, cx: JSContext) -> bool {
|
||||
assert!(self.is_initialized());
|
||||
match &self.buffer_source {
|
||||
BufferSource::ArrayBufferView(buffer) | BufferSource::Default(buffer) => {
|
||||
BufferSource::ArrayBufferView(buffer) => {
|
||||
let mut is_shared = false;
|
||||
unsafe {
|
||||
// assert buffer is an ArrayBuffer view
|
||||
|
@ -151,9 +219,9 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
pub(crate) fn buffer_to_option(&self) -> Option<TypedArray<T, *mut JSObject>> {
|
||||
pub(crate) fn typed_array_to_option(&self) -> Option<TypedArray<T, *mut JSObject>> {
|
||||
if self.is_initialized() {
|
||||
self.get_buffer().ok()
|
||||
self.get_typed_array().ok()
|
||||
} else {
|
||||
warn!("Buffer not initialized.");
|
||||
None
|
||||
|
@ -163,7 +231,7 @@ where
|
|||
pub(crate) fn is_detached_buffer(&self, cx: JSContext) -> bool {
|
||||
assert!(self.is_initialized());
|
||||
match &self.buffer_source {
|
||||
BufferSource::ArrayBufferView(buffer) | BufferSource::Default(buffer) => {
|
||||
BufferSource::ArrayBufferView(buffer) => {
|
||||
let mut is_shared = false;
|
||||
unsafe {
|
||||
assert!(JS_IsArrayBufferViewObject(*buffer.handle()));
|
||||
|
@ -182,7 +250,7 @@ where
|
|||
pub(crate) fn viewed_buffer_array_byte_length(&self, cx: JSContext) -> usize {
|
||||
assert!(self.is_initialized());
|
||||
match &self.buffer_source {
|
||||
BufferSource::ArrayBufferView(buffer) | BufferSource::Default(buffer) => {
|
||||
BufferSource::ArrayBufferView(buffer) => {
|
||||
let mut is_shared = false;
|
||||
unsafe {
|
||||
assert!(JS_IsArrayBufferViewObject(*buffer.handle()));
|
||||
|
@ -200,7 +268,7 @@ where
|
|||
|
||||
pub(crate) fn byte_length(&self) -> usize {
|
||||
match &self.buffer_source {
|
||||
BufferSource::ArrayBufferView(buffer) | BufferSource::Default(buffer) => unsafe {
|
||||
BufferSource::ArrayBufferView(buffer) => unsafe {
|
||||
JS_GetArrayBufferViewByteLength(*buffer.handle())
|
||||
},
|
||||
BufferSource::ArrayBuffer(buffer) => unsafe {
|
||||
|
@ -209,19 +277,54 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
pub(crate) fn array_length(&self) -> usize {
|
||||
self.get_buffer().unwrap().len()
|
||||
pub(crate) fn get_byte_offset(&self) -> usize {
|
||||
match &self.buffer_source {
|
||||
BufferSource::ArrayBufferView(buffer) => unsafe {
|
||||
JS_GetArrayBufferViewByteOffset(*buffer.handle())
|
||||
},
|
||||
BufferSource::ArrayBuffer(_) => {
|
||||
unreachable!("BufferSource::ArrayBuffer does not have a byte offset.")
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn get_typed_array_length(&self) -> usize {
|
||||
match &self.buffer_source {
|
||||
BufferSource::ArrayBufferView(buffer) => unsafe {
|
||||
JS_GetTypedArrayLength(*buffer.handle())
|
||||
},
|
||||
BufferSource::ArrayBuffer(_) => {
|
||||
unreachable!("BufferSource::ArrayBuffer does not have a length.")
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
/// <https://tc39.es/ecma262/#typedarray>
|
||||
pub(crate) fn has_typed_array_name(&self) -> bool {
|
||||
match &self.buffer_source {
|
||||
BufferSource::ArrayBufferView(buffer) | BufferSource::Default(buffer) => unsafe {
|
||||
BufferSource::ArrayBufferView(buffer) => unsafe {
|
||||
JS_IsTypedArrayObject(*buffer.handle())
|
||||
},
|
||||
BufferSource::ArrayBuffer(_) => false,
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn get_array_buffer_view_type(&self) -> Type {
|
||||
match &self.buffer_source {
|
||||
BufferSource::ArrayBufferView(buffer) => unsafe {
|
||||
JS_GetArrayBufferViewType(*buffer.handle())
|
||||
},
|
||||
BufferSource::ArrayBuffer(_) => unreachable!("ArrayBuffer does not have a view type."),
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn is_array_buffer_object(&self) -> bool {
|
||||
match &self.buffer_source {
|
||||
BufferSource::ArrayBufferView(heap) | BufferSource::ArrayBuffer(heap) => unsafe {
|
||||
IsArrayBufferObject(*heap.handle())
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> HeapBufferSource<T>
|
||||
|
@ -233,9 +336,8 @@ where
|
|||
assert!(self.is_initialized());
|
||||
|
||||
typedarray!(in(*cx) let array: TypedArray = match &self.buffer_source {
|
||||
BufferSource::ArrayBufferView(buffer) |
|
||||
BufferSource::ArrayBuffer(buffer) |
|
||||
BufferSource::Default(buffer) => {
|
||||
BufferSource::ArrayBufferView(buffer) | BufferSource::ArrayBuffer(buffer)
|
||||
=> {
|
||||
buffer.get()
|
||||
},
|
||||
});
|
||||
|
@ -250,9 +352,7 @@ where
|
|||
};
|
||||
|
||||
match &self.buffer_source {
|
||||
BufferSource::ArrayBufferView(buffer) |
|
||||
BufferSource::ArrayBuffer(buffer) |
|
||||
BufferSource::Default(buffer) => {
|
||||
BufferSource::ArrayBufferView(buffer) | BufferSource::ArrayBuffer(buffer) => {
|
||||
buffer.set(ptr::null_mut());
|
||||
},
|
||||
}
|
||||
|
@ -268,9 +368,8 @@ where
|
|||
) -> Result<(), ()> {
|
||||
assert!(self.is_initialized());
|
||||
typedarray!(in(*cx) let array: TypedArray = match &self.buffer_source {
|
||||
BufferSource::ArrayBufferView(buffer) |
|
||||
BufferSource::ArrayBuffer(buffer) |
|
||||
BufferSource::Default(buffer) => {
|
||||
BufferSource::ArrayBufferView(buffer) | BufferSource::ArrayBuffer(buffer)
|
||||
=> {
|
||||
buffer.get()
|
||||
},
|
||||
});
|
||||
|
@ -295,9 +394,8 @@ where
|
|||
) -> Result<(), ()> {
|
||||
assert!(self.is_initialized());
|
||||
typedarray!(in(*cx) let mut array: TypedArray = match &self.buffer_source {
|
||||
BufferSource::ArrayBufferView(buffer) |
|
||||
BufferSource::ArrayBuffer(buffer) |
|
||||
BufferSource::Default(buffer) => {
|
||||
BufferSource::ArrayBufferView(buffer) | BufferSource::ArrayBuffer(buffer)
|
||||
=> {
|
||||
buffer.get()
|
||||
},
|
||||
});
|
||||
|
@ -325,23 +423,194 @@ where
|
|||
create_buffer_source(cx, data, array.handle_mut(), can_gc)?;
|
||||
|
||||
match &self.buffer_source {
|
||||
BufferSource::ArrayBufferView(buffer) |
|
||||
BufferSource::ArrayBuffer(buffer) |
|
||||
BufferSource::Default(buffer) => {
|
||||
BufferSource::ArrayBufferView(buffer) | BufferSource::ArrayBuffer(buffer) => {
|
||||
buffer.set(*array);
|
||||
},
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// <https://tc39.es/ecma262/#sec-clonearraybuffer>
|
||||
pub(crate) fn clone_array_buffer(
|
||||
&self,
|
||||
cx: JSContext,
|
||||
byte_offset: usize,
|
||||
byte_length: usize,
|
||||
) -> Option<HeapBufferSource<ArrayBufferU8>> {
|
||||
match &self.buffer_source {
|
||||
BufferSource::ArrayBufferView(heap) | BufferSource::ArrayBuffer(heap) => {
|
||||
let result =
|
||||
unsafe { ArrayBufferClone(*cx, heap.handle(), byte_offset, byte_length) };
|
||||
if result.is_null() {
|
||||
None
|
||||
} else {
|
||||
Some(HeapBufferSource::<ArrayBufferU8>::new(
|
||||
BufferSource::ArrayBuffer(Heap::boxed(result)),
|
||||
))
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
/// <https://streams.spec.whatwg.org/#abstract-opdef-cancopydatablockbytes>
|
||||
// CanCopyDataBlockBytes(descriptorBuffer, destStart, queueBuffer, queueByteOffset, bytesToCopy)
|
||||
pub(crate) fn can_copy_data_block_bytes(
|
||||
&self,
|
||||
cx: JSContext,
|
||||
to_index: usize,
|
||||
from_buffer: &HeapBufferSource<ArrayBufferU8>,
|
||||
from_index: usize,
|
||||
bytes_to_copy: usize,
|
||||
) -> bool {
|
||||
// Assert: toBuffer is an Object.
|
||||
// Assert: toBuffer has an [[ArrayBufferData]] internal slot.
|
||||
assert!(self.is_array_buffer_object());
|
||||
|
||||
// Assert: fromBuffer is an Object.
|
||||
// Assert: fromBuffer has an [[ArrayBufferData]] internal slot.
|
||||
assert!(from_buffer.is_array_buffer_object());
|
||||
|
||||
// If toBuffer is fromBuffer, return false.
|
||||
match &self.buffer_source {
|
||||
BufferSource::ArrayBufferView(heap) | BufferSource::ArrayBuffer(heap) => {
|
||||
match &from_buffer.buffer_source {
|
||||
BufferSource::ArrayBufferView(from_heap) |
|
||||
BufferSource::ArrayBuffer(from_heap) => {
|
||||
unsafe {
|
||||
if heap.handle() == from_heap.handle() {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
},
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
// If ! IsDetachedBuffer(toBuffer) is true, return false.
|
||||
if self.is_detached_buffer(cx) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// If ! IsDetachedBuffer(fromBuffer) is true, return false.
|
||||
if from_buffer.is_detached_buffer(cx) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// If toIndex + count > toBuffer.[[ArrayBufferByteLength]], return false.
|
||||
if to_index + bytes_to_copy > self.byte_length() {
|
||||
return false;
|
||||
}
|
||||
|
||||
// If fromIndex + count > fromBuffer.[[ArrayBufferByteLength]], return false.
|
||||
if from_index + bytes_to_copy > from_buffer.byte_length() {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Return true.
|
||||
true
|
||||
}
|
||||
|
||||
pub(crate) fn copy_data_block_bytes(
|
||||
&self,
|
||||
cx: JSContext,
|
||||
dest_start: usize,
|
||||
from_buffer: &HeapBufferSource<ArrayBufferU8>,
|
||||
from_byte_offset: usize,
|
||||
bytes_to_copy: usize,
|
||||
) -> bool {
|
||||
match &self.buffer_source {
|
||||
BufferSource::ArrayBufferView(heap) | BufferSource::ArrayBuffer(heap) => unsafe {
|
||||
match &from_buffer.buffer_source {
|
||||
BufferSource::ArrayBufferView(from_heap) |
|
||||
BufferSource::ArrayBuffer(from_heap) => ArrayBufferCopyData(
|
||||
*cx,
|
||||
heap.handle(),
|
||||
dest_start,
|
||||
from_heap.handle(),
|
||||
from_byte_offset,
|
||||
bytes_to_copy,
|
||||
),
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
/// <https://streams.spec.whatwg.org/#can-transfer-array-buffer>
|
||||
pub(crate) fn can_transfer_array_buffer(&self, cx: JSContext) -> bool {
|
||||
// Assert: O is an Object.
|
||||
// Assert: O has an [[ArrayBufferData]] internal slot.
|
||||
assert!(self.is_array_buffer_object());
|
||||
|
||||
// If ! IsDetachedBuffer(O) is true, return false.
|
||||
if self.is_detached_buffer(cx) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// If SameValue(O.[[ArrayBufferDetachKey]], undefined) is false, return false.
|
||||
// Return true.
|
||||
let mut is_defined = false;
|
||||
match &self.buffer_source {
|
||||
BufferSource::ArrayBufferView(heap) | BufferSource::ArrayBuffer(heap) => unsafe {
|
||||
if !HasDefinedArrayBufferDetachKey(*cx, heap.handle(), &mut is_defined) {
|
||||
return false;
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
!is_defined
|
||||
}
|
||||
|
||||
/// <https://streams.spec.whatwg.org/#transfer-array-buffer>
|
||||
pub(crate) fn transfer_array_buffer(
|
||||
&self,
|
||||
cx: JSContext,
|
||||
) -> Fallible<HeapBufferSource<ArrayBufferU8>> {
|
||||
assert!(self.is_array_buffer_object());
|
||||
|
||||
// Assert: ! IsDetachedBuffer(O) is false.
|
||||
assert!(!self.is_detached_buffer(cx));
|
||||
|
||||
// Let arrayBufferByteLength be O.[[ArrayBufferByteLength]].
|
||||
// Step 3 (Reordered)
|
||||
let buffer_length = self.byte_length();
|
||||
|
||||
// Let arrayBufferData be O.[[ArrayBufferData]].
|
||||
// Step 2 (Reordered)
|
||||
let buffer_data = match &self.buffer_source {
|
||||
BufferSource::ArrayBufferView(buffer) | BufferSource::ArrayBuffer(buffer) => unsafe {
|
||||
StealArrayBufferContents(*cx, buffer.handle())
|
||||
},
|
||||
};
|
||||
|
||||
// Perform ? DetachArrayBuffer(O).
|
||||
// This will throw an exception if O has an [[ArrayBufferDetachKey]] that is not undefined,
|
||||
// such as a WebAssembly.Memory’s buffer. [WASM-JS-API-1]
|
||||
if !self.detach_buffer(cx) {
|
||||
rooted!(in(*cx) let mut rval = UndefinedValue());
|
||||
unsafe {
|
||||
assert!(JS_GetPendingException(*cx, rval.handle_mut().into()));
|
||||
JS_ClearPendingException(*cx)
|
||||
};
|
||||
|
||||
Err(Error::Type("can't transfer array buffer".to_owned()))
|
||||
} else {
|
||||
// Return a new ArrayBuffer object, created in the current Realm,
|
||||
// whose [[ArrayBufferData]] internal slot value is arrayBufferData and
|
||||
// whose [[ArrayBufferByteLength]] internal slot value is arrayBufferByteLength.
|
||||
Ok(HeapBufferSource::<ArrayBufferU8>::new(
|
||||
BufferSource::ArrayBuffer(Heap::boxed(unsafe {
|
||||
NewArrayBufferWithContents(*cx, buffer_length, buffer_data)
|
||||
})),
|
||||
))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl<T> crate::dom::bindings::trace::JSTraceable for HeapBufferSource<T> {
|
||||
#[inline]
|
||||
unsafe fn trace(&self, tracer: *mut js::jsapi::JSTracer) {
|
||||
match &self.buffer_source {
|
||||
BufferSource::ArrayBufferView(buffer) |
|
||||
BufferSource::ArrayBuffer(buffer) |
|
||||
BufferSource::Default(buffer) => {
|
||||
BufferSource::ArrayBufferView(buffer) | BufferSource::ArrayBuffer(buffer) => {
|
||||
buffer.trace(tracer);
|
||||
},
|
||||
}
|
||||
|
@ -385,6 +654,134 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
pub(crate) fn byte_size(byte_type: Type) -> u64 {
|
||||
match byte_type {
|
||||
Type::Int8 | Type::Uint8 | Type::Uint8Clamped => 1,
|
||||
Type::Int16 | Type::Uint16 | Type::Float16 => 2,
|
||||
Type::Int32 | Type::Uint32 | Type::Float32 => 4,
|
||||
Type::Int64 | Type::Float64 | Type::BigInt64 | Type::BigUint64 => 8,
|
||||
Type::Simd128 => 16,
|
||||
_ => unreachable!("invalid scalar type"),
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Eq, JSTraceable, MallocSizeOf, PartialEq)]
|
||||
pub(crate) enum Constructor {
|
||||
DataView,
|
||||
Name(
|
||||
#[ignore_malloc_size_of = "mozjs"]
|
||||
#[no_trace]
|
||||
Type,
|
||||
),
|
||||
}
|
||||
|
||||
pub(crate) fn create_buffer_source_with_constructor(
|
||||
cx: JSContext,
|
||||
constructor: &Constructor,
|
||||
buffer_source: &HeapBufferSource<ArrayBufferU8>,
|
||||
byte_offset: usize,
|
||||
byte_length: usize,
|
||||
) -> Fallible<HeapBufferSource<ArrayBufferViewU8>> {
|
||||
let buffer = unsafe {
|
||||
Heap::boxed(
|
||||
*buffer_source
|
||||
.get_typed_array()
|
||||
.expect("Failed to get typed array")
|
||||
.underlying_object(),
|
||||
)
|
||||
.handle()
|
||||
};
|
||||
|
||||
match constructor {
|
||||
Constructor::DataView => Ok(HeapBufferSource::new(BufferSource::ArrayBufferView(
|
||||
Heap::boxed(unsafe { JS_NewDataView(*cx, buffer, byte_offset, byte_length) }),
|
||||
))),
|
||||
Constructor::Name(name_type) => construct_typed_array(
|
||||
cx,
|
||||
name_type,
|
||||
buffer_source,
|
||||
byte_offset,
|
||||
byte_length as i64,
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
/// Helper function to construct different TypedArray views
|
||||
fn construct_typed_array(
|
||||
cx: JSContext,
|
||||
name_type: &Type,
|
||||
buffer_source: &HeapBufferSource<ArrayBufferU8>,
|
||||
byte_offset: usize,
|
||||
byte_length: i64,
|
||||
) -> Fallible<HeapBufferSource<ArrayBufferViewU8>> {
|
||||
let buffer = unsafe {
|
||||
Heap::boxed(
|
||||
*buffer_source
|
||||
.get_typed_array()
|
||||
.expect("Failed to get typed array")
|
||||
.underlying_object(),
|
||||
)
|
||||
.handle()
|
||||
};
|
||||
let array_view = match name_type {
|
||||
Type::Int8 => unsafe { JS_NewInt8ArrayWithBuffer(*cx, buffer, byte_offset, byte_length) },
|
||||
Type::Uint8 => unsafe { JS_NewUint8ArrayWithBuffer(*cx, buffer, byte_offset, byte_length) },
|
||||
Type::Uint16 => unsafe {
|
||||
JS_NewUint16ArrayWithBuffer(*cx, buffer, byte_offset, byte_length)
|
||||
},
|
||||
Type::Int16 => unsafe { JS_NewInt16ArrayWithBuffer(*cx, buffer, byte_offset, byte_length) },
|
||||
Type::Int32 => unsafe { JS_NewInt32ArrayWithBuffer(*cx, buffer, byte_offset, byte_length) },
|
||||
Type::Uint32 => unsafe {
|
||||
JS_NewUint32ArrayWithBuffer(*cx, buffer, byte_offset, byte_length)
|
||||
},
|
||||
Type::Float32 => unsafe {
|
||||
JS_NewFloat32ArrayWithBuffer(*cx, buffer, byte_offset, byte_length)
|
||||
},
|
||||
Type::Float64 => unsafe {
|
||||
JS_NewFloat64ArrayWithBuffer(*cx, buffer, byte_offset, byte_length)
|
||||
},
|
||||
Type::Uint8Clamped => unsafe {
|
||||
JS_NewUint8ClampedArrayWithBuffer(*cx, buffer, byte_offset, byte_length)
|
||||
},
|
||||
Type::BigInt64 => unsafe {
|
||||
JS_NewBigInt64ArrayWithBuffer(*cx, buffer, byte_offset, byte_length)
|
||||
},
|
||||
Type::BigUint64 => unsafe {
|
||||
JS_NewBigUint64ArrayWithBuffer(*cx, buffer, byte_offset, byte_length)
|
||||
},
|
||||
Type::Float16 => unsafe {
|
||||
JS_NewFloat16ArrayWithBuffer(*cx, buffer, byte_offset, byte_length)
|
||||
},
|
||||
Type::Int64 | Type::Simd128 | Type::MaxTypedArrayViewType => {
|
||||
unreachable!("Invalid TypedArray type")
|
||||
},
|
||||
};
|
||||
|
||||
Ok(HeapBufferSource::new(BufferSource::ArrayBufferView(
|
||||
Heap::boxed(array_view),
|
||||
)))
|
||||
}
|
||||
|
||||
pub(crate) fn create_array_buffer_with_size(
|
||||
cx: JSContext,
|
||||
size: usize,
|
||||
) -> Fallible<HeapBufferSource<ArrayBufferU8>> {
|
||||
let result = unsafe { NewArrayBuffer(*cx, size) };
|
||||
if result.is_null() {
|
||||
rooted!(in(*cx) let mut rval = UndefinedValue());
|
||||
unsafe {
|
||||
assert!(JS_GetPendingException(*cx, rval.handle_mut().into()));
|
||||
JS_ClearPendingException(*cx)
|
||||
};
|
||||
|
||||
Err(Error::Type("can't create array buffer".to_owned()))
|
||||
} else {
|
||||
Ok(HeapBufferSource::<ArrayBufferU8>::new(
|
||||
BufferSource::ArrayBuffer(Heap::boxed(result)),
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "webgpu")]
|
||||
#[derive(JSTraceable, MallocSizeOf)]
|
||||
pub(crate) struct DataBlock {
|
||||
|
|
|
@ -108,12 +108,12 @@ impl DefaultTeeUnderlyingSource {
|
|||
/// Let pullAlgorithm be the following steps:
|
||||
#[cfg_attr(crown, allow(crown::unrooted_must_root))]
|
||||
pub(crate) fn pull_algorithm(&self, can_gc: CanGc) -> Rc<Promise> {
|
||||
let cx = GlobalScope::get_cx();
|
||||
// If reading is true,
|
||||
if self.reading.get() {
|
||||
// Set readAgain to true.
|
||||
self.read_again.set(true);
|
||||
// Return a promise resolved with undefined.
|
||||
let cx = GlobalScope::get_cx();
|
||||
rooted!(in(*cx) let mut rval = UndefinedValue());
|
||||
return Promise::new_resolved(&self.stream.global(), cx, rval.handle(), can_gc);
|
||||
}
|
||||
|
@ -142,17 +142,11 @@ impl DefaultTeeUnderlyingSource {
|
|||
};
|
||||
|
||||
// Perform ! ReadableStreamDefaultReaderRead(reader, readRequest).
|
||||
self.reader.read(&read_request, can_gc);
|
||||
self.reader.read(cx, &read_request, can_gc);
|
||||
|
||||
// Return a promise resolved with undefined.
|
||||
let cx = GlobalScope::get_cx();
|
||||
rooted!(in(*cx) let mut rval = UndefinedValue());
|
||||
Promise::new_resolved(
|
||||
&self.stream.global(),
|
||||
GlobalScope::get_cx(),
|
||||
rval.handle(),
|
||||
can_gc,
|
||||
)
|
||||
Promise::new_resolved(&self.stream.global(), cx, rval.handle(), can_gc)
|
||||
}
|
||||
|
||||
/// <https://streams.spec.whatwg.org/#abstract-opdef-readablestreamdefaulttee>
|
||||
|
|
|
@ -186,7 +186,9 @@ impl GamepadMethods<crate::DomTypeHolder> for Gamepad {
|
|||
|
||||
// https://w3c.github.io/gamepad/#dom-gamepad-axes
|
||||
fn Axes(&self, _cx: JSContext) -> Float64Array {
|
||||
self.axes.get_buffer().expect("Failed to get gamepad axes.")
|
||||
self.axes
|
||||
.get_typed_array()
|
||||
.expect("Failed to get gamepad axes.")
|
||||
}
|
||||
|
||||
// https://w3c.github.io/gamepad/#dom-gamepad-buttons
|
||||
|
@ -277,7 +279,7 @@ impl Gamepad {
|
|||
if normalized_value.is_finite() {
|
||||
let mut axis_vec = self
|
||||
.axes
|
||||
.buffer_to_option()
|
||||
.typed_array_to_option()
|
||||
.expect("Axes have not been initialized!");
|
||||
unsafe {
|
||||
axis_vec.as_mut_slice()[axis_index] = normalized_value;
|
||||
|
|
|
@ -52,7 +52,7 @@ impl GamepadPose {
|
|||
impl GamepadPoseMethods<crate::DomTypeHolder> for GamepadPose {
|
||||
// https://w3c.github.io/gamepad/extensions.html#dom-gamepadpose-position
|
||||
fn GetPosition(&self, _cx: JSContext) -> Option<Float32Array> {
|
||||
self.position.buffer_to_option()
|
||||
self.position.typed_array_to_option()
|
||||
}
|
||||
|
||||
// https://w3c.github.io/gamepad/extensions.html#dom-gamepadpose-hasposition
|
||||
|
@ -62,17 +62,17 @@ impl GamepadPoseMethods<crate::DomTypeHolder> for GamepadPose {
|
|||
|
||||
// https://w3c.github.io/gamepad/extensions.html#dom-gamepadpose-linearvelocity
|
||||
fn GetLinearVelocity(&self, _cx: JSContext) -> Option<Float32Array> {
|
||||
self.linear_vel.buffer_to_option()
|
||||
self.linear_vel.typed_array_to_option()
|
||||
}
|
||||
|
||||
// https://w3c.github.io/gamepad/extensions.html#dom-gamepadpose-linearacceleration
|
||||
fn GetLinearAcceleration(&self, _cx: JSContext) -> Option<Float32Array> {
|
||||
self.linear_acc.buffer_to_option()
|
||||
self.linear_acc.typed_array_to_option()
|
||||
}
|
||||
|
||||
// https://w3c.github.io/gamepad/extensions.html#dom-gamepadpose-orientation
|
||||
fn GetOrientation(&self, _cx: JSContext) -> Option<Float32Array> {
|
||||
self.orientation.buffer_to_option()
|
||||
self.orientation.typed_array_to_option()
|
||||
}
|
||||
|
||||
// https://w3c.github.io/gamepad/extensions.html#dom-gamepadpose-orientation
|
||||
|
@ -82,11 +82,11 @@ impl GamepadPoseMethods<crate::DomTypeHolder> for GamepadPose {
|
|||
|
||||
// https://w3c.github.io/gamepad/extensions.html#dom-gamepadpose-angularvelocity
|
||||
fn GetAngularVelocity(&self, _cx: JSContext) -> Option<Float32Array> {
|
||||
self.angular_vel.buffer_to_option()
|
||||
self.angular_vel.typed_array_to_option()
|
||||
}
|
||||
|
||||
// https://w3c.github.io/gamepad/extensions.html#dom-gamepadpose-angularacceleration
|
||||
fn GetAngularAcceleration(&self, _cx: JSContext) -> Option<Float32Array> {
|
||||
self.angular_acc.buffer_to_option()
|
||||
self.angular_acc.typed_array_to_option()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -73,7 +73,7 @@ impl ImageData {
|
|||
Err(_) => return Err(Error::JSFailed),
|
||||
};
|
||||
|
||||
let typed_array = match heap_typed_array.get_buffer() {
|
||||
let typed_array = match heap_typed_array.get_typed_array() {
|
||||
Ok(array) => array,
|
||||
Err(_) => {
|
||||
return Err(Error::Type(
|
||||
|
@ -160,7 +160,7 @@ impl ImageData {
|
|||
assert!(self.data.is_initialized());
|
||||
let internal_data = self
|
||||
.data
|
||||
.get_buffer()
|
||||
.get_typed_array()
|
||||
.expect("Failed to get Data from ImageData.");
|
||||
// NOTE(nox): This is just as unsafe as `as_slice` itself even though we
|
||||
// are extending the lifetime of the slice, because the data in
|
||||
|
@ -209,6 +209,6 @@ impl ImageDataMethods<crate::DomTypeHolder> for ImageData {
|
|||
|
||||
/// <https://html.spec.whatwg.org/multipage/#dom-imagedata-data>
|
||||
fn GetData(&self, _: JSContext) -> Fallible<Uint8ClampedArray> {
|
||||
self.data.get_buffer().map_err(|_| Error::JSFailed)
|
||||
self.data.get_typed_array().map_err(|_| Error::JSFailed)
|
||||
}
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -2,7 +2,7 @@
|
|||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use std::cell::Cell;
|
||||
use std::cell::{Cell, RefCell};
|
||||
use std::ptr::{self};
|
||||
use std::rc::Rc;
|
||||
|
||||
|
@ -114,6 +114,17 @@ pub(crate) enum ReaderType {
|
|||
Default(MutNullableDom<ReadableStreamDefaultReader>),
|
||||
}
|
||||
|
||||
impl Eq for ReaderType {}
|
||||
impl PartialEq for ReaderType {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
matches!(
|
||||
(self, other),
|
||||
(ReaderType::BYOB(_), ReaderType::BYOB(_)) |
|
||||
(ReaderType::Default(_), ReaderType::Default(_))
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/// <https://streams.spec.whatwg.org/#create-readable-stream>
|
||||
#[cfg_attr(crown, allow(crown::unrooted_must_root))]
|
||||
fn create_readable_stream(
|
||||
|
@ -135,12 +146,7 @@ fn create_readable_stream(
|
|||
|
||||
// Let stream be a new ReadableStream.
|
||||
// Perform ! InitializeReadableStream(stream).
|
||||
let stream = ReadableStream::new_with_proto(
|
||||
global,
|
||||
None,
|
||||
ControllerType::Default(MutNullableDom::new(None)),
|
||||
can_gc,
|
||||
);
|
||||
let stream = ReadableStream::new_with_proto(global, None, can_gc);
|
||||
|
||||
// Let controller be a new ReadableStreamDefaultController.
|
||||
let controller = ReadableStreamDefaultController::new(
|
||||
|
@ -169,7 +175,7 @@ pub(crate) struct ReadableStream {
|
|||
/// <https://streams.spec.whatwg.org/#readablestream-controller>
|
||||
/// Note: the inner `MutNullableDom` should really be an `Option<Dom>`,
|
||||
/// because it is never unset once set.
|
||||
controller: ControllerType,
|
||||
controller: RefCell<Option<ControllerType>>,
|
||||
|
||||
/// <https://streams.spec.whatwg.org/#readablestream-storederror>
|
||||
#[ignore_malloc_size_of = "mozjs"]
|
||||
|
@ -179,7 +185,7 @@ pub(crate) struct ReadableStream {
|
|||
disturbed: Cell<bool>,
|
||||
|
||||
/// <https://streams.spec.whatwg.org/#readablestream-reader>
|
||||
reader: ReaderType,
|
||||
reader: RefCell<Option<ReaderType>>,
|
||||
|
||||
/// <https://streams.spec.whatwg.org/#readablestream-state>
|
||||
state: Cell<ReadableStreamState>,
|
||||
|
@ -188,17 +194,13 @@ pub(crate) struct ReadableStream {
|
|||
impl ReadableStream {
|
||||
#[cfg_attr(crown, allow(crown::unrooted_must_root))]
|
||||
/// <https://streams.spec.whatwg.org/#initialize-readable-stream>
|
||||
fn new_inherited(controller: ControllerType) -> ReadableStream {
|
||||
let reader = match &controller {
|
||||
ControllerType::Default(_) => ReaderType::Default(MutNullableDom::new(None)),
|
||||
ControllerType::Byte(_) => ReaderType::BYOB(MutNullableDom::new(None)),
|
||||
};
|
||||
fn new_inherited() -> ReadableStream {
|
||||
ReadableStream {
|
||||
reflector_: Reflector::new(),
|
||||
controller,
|
||||
controller: RefCell::new(None),
|
||||
stored_error: Heap::default(),
|
||||
disturbed: Default::default(),
|
||||
reader,
|
||||
reader: RefCell::new(None),
|
||||
state: Cell::new(Default::default()),
|
||||
}
|
||||
}
|
||||
|
@ -207,11 +209,10 @@ impl ReadableStream {
|
|||
fn new_with_proto(
|
||||
global: &GlobalScope,
|
||||
proto: Option<SafeHandleObject>,
|
||||
controller: ControllerType,
|
||||
can_gc: CanGc,
|
||||
) -> DomRoot<ReadableStream> {
|
||||
reflect_dom_object_with_proto(
|
||||
Box::new(ReadableStream::new_inherited(controller)),
|
||||
Box::new(ReadableStream::new_inherited()),
|
||||
global,
|
||||
proto,
|
||||
can_gc,
|
||||
|
@ -221,21 +222,22 @@ impl ReadableStream {
|
|||
/// Used as part of
|
||||
/// <https://streams.spec.whatwg.org/#set-up-readable-stream-default-controller>
|
||||
pub(crate) fn set_default_controller(&self, controller: &ReadableStreamDefaultController) {
|
||||
match self.controller {
|
||||
ControllerType::Default(ref ctrl) => ctrl.set(Some(controller)),
|
||||
ControllerType::Byte(_) => {
|
||||
unreachable!("set_default_controller called in setup of default controller.")
|
||||
},
|
||||
}
|
||||
*self.controller.borrow_mut() = Some(ControllerType::Default(MutNullableDom::new(Some(
|
||||
controller,
|
||||
))));
|
||||
}
|
||||
|
||||
/// Used as part of
|
||||
/// <https://streams.spec.whatwg.org/#set-up-readable-byte-stream-controller>
|
||||
pub(crate) fn set_byte_controller(&self, controller: &ReadableByteStreamController) {
|
||||
*self.controller.borrow_mut() =
|
||||
Some(ControllerType::Byte(MutNullableDom::new(Some(controller))));
|
||||
}
|
||||
|
||||
/// Used as part of
|
||||
/// <https://streams.spec.whatwg.org/#set-up-readable-stream-default-controller>
|
||||
pub(crate) fn assert_no_controller(&self) {
|
||||
let has_no_controller = match self.controller {
|
||||
ControllerType::Default(ref ctrl) => ctrl.get().is_none(),
|
||||
ControllerType::Byte(ref ctrl) => ctrl.get().is_none(),
|
||||
};
|
||||
let has_no_controller = self.controller.borrow().is_none();
|
||||
assert!(has_no_controller);
|
||||
}
|
||||
|
||||
|
@ -264,12 +266,7 @@ impl ReadableStream {
|
|||
can_gc: CanGc,
|
||||
) -> Fallible<DomRoot<ReadableStream>> {
|
||||
assert!(source.is_native());
|
||||
let stream = ReadableStream::new_with_proto(
|
||||
global,
|
||||
None,
|
||||
ControllerType::Default(MutNullableDom::new(None)),
|
||||
can_gc,
|
||||
);
|
||||
let stream = ReadableStream::new_with_proto(global, None, can_gc);
|
||||
let controller = ReadableStreamDefaultController::new(
|
||||
global,
|
||||
source,
|
||||
|
@ -283,28 +280,43 @@ impl ReadableStream {
|
|||
|
||||
/// Call into the release steps of the controller,
|
||||
pub(crate) fn perform_release_steps(&self) -> Fallible<()> {
|
||||
match &self.controller {
|
||||
ControllerType::Default(controller) => controller
|
||||
.get()
|
||||
.map(|controller_ref| controller_ref.perform_release_steps())
|
||||
.unwrap_or_else(|| Err(Error::Type("Stream should have controller.".to_string()))),
|
||||
ControllerType::Byte(_) => todo!(),
|
||||
match self.controller.borrow().as_ref() {
|
||||
Some(ControllerType::Default(ref controller)) => {
|
||||
let controller = controller
|
||||
.get()
|
||||
.ok_or_else(|| Error::Type("Stream should have controller.".to_string()))?;
|
||||
controller.perform_release_steps()
|
||||
},
|
||||
Some(ControllerType::Byte(ref controller)) => {
|
||||
let controller = controller
|
||||
.get()
|
||||
.ok_or_else(|| Error::Type("Stream should have controller.".to_string()))?;
|
||||
controller.perform_release_steps()
|
||||
},
|
||||
None => Err(Error::Type("Stream should have controller.".to_string())),
|
||||
}
|
||||
}
|
||||
|
||||
/// Call into the pull steps of the controller,
|
||||
/// as part of
|
||||
/// <https://streams.spec.whatwg.org/#readable-stream-default-reader-read>
|
||||
pub(crate) fn perform_pull_steps(&self, read_request: &ReadRequest, can_gc: CanGc) {
|
||||
match self.controller {
|
||||
ControllerType::Default(ref controller) => controller
|
||||
pub(crate) fn perform_pull_steps(
|
||||
&self,
|
||||
cx: SafeJSContext,
|
||||
read_request: &ReadRequest,
|
||||
can_gc: CanGc,
|
||||
) {
|
||||
match self.controller.borrow().as_ref() {
|
||||
Some(ControllerType::Default(ref controller)) => controller
|
||||
.get()
|
||||
.expect("Stream should have controller.")
|
||||
.perform_pull_steps(read_request, can_gc),
|
||||
ControllerType::Byte(_) => {
|
||||
unreachable!(
|
||||
"Pulling a chunk from a stream with a byte controller using a default reader"
|
||||
)
|
||||
Some(ControllerType::Byte(ref controller)) => controller
|
||||
.get()
|
||||
.expect("Stream should have controller.")
|
||||
.perform_pull_steps(cx, read_request, can_gc),
|
||||
None => {
|
||||
unreachable!("Stream does not have a controller.");
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -312,29 +324,31 @@ impl ReadableStream {
|
|||
/// Call into the pull steps of the controller,
|
||||
/// as part of
|
||||
/// <https://streams.spec.whatwg.org/#readable-stream-byob-reader-read>
|
||||
pub(crate) fn perform_pull_into_steps(
|
||||
pub(crate) fn perform_pull_into(
|
||||
&self,
|
||||
cx: SafeJSContext,
|
||||
read_into_request: &ReadIntoRequest,
|
||||
view: HeapBufferSource<ArrayBufferViewU8>,
|
||||
options: &ReadableStreamBYOBReaderReadOptions,
|
||||
can_gc: CanGc,
|
||||
) {
|
||||
match self.controller {
|
||||
ControllerType::Byte(ref controller) => controller
|
||||
match self.controller.borrow().as_ref() {
|
||||
Some(ControllerType::Byte(ref controller)) => controller
|
||||
.get()
|
||||
.expect("Stream should have controller.")
|
||||
.perform_pull_into(read_into_request, view, options, can_gc),
|
||||
ControllerType::Default(_) => unreachable!(
|
||||
"Pulling a chunk from a stream with a default controller using a BYOB reader"
|
||||
),
|
||||
.perform_pull_into(cx, read_into_request, view, options, can_gc),
|
||||
_ => {
|
||||
unreachable!(
|
||||
"Pulling a chunk from a stream with a default controller using a BYOB reader"
|
||||
)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
/// <https://streams.spec.whatwg.org/#readable-stream-add-read-request>
|
||||
pub(crate) fn add_read_request(&self, read_request: &ReadRequest) {
|
||||
match self.reader {
|
||||
// Assert: stream.[[reader]] implements ReadableStreamDefaultReader.
|
||||
ReaderType::Default(ref reader) => {
|
||||
match self.reader.borrow().as_ref() {
|
||||
Some(ReaderType::Default(ref reader)) => {
|
||||
let Some(reader) = reader.get() else {
|
||||
panic!("Attempt to add a read request without having first acquired a reader.");
|
||||
};
|
||||
|
@ -345,21 +359,17 @@ impl ReadableStream {
|
|||
// Append readRequest to stream.[[reader]].[[readRequests]].
|
||||
reader.add_read_request(read_request);
|
||||
},
|
||||
ReaderType::BYOB(_) => {
|
||||
_ => {
|
||||
unreachable!("Adding a read request can only be done on a default reader.")
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
/// <https://streams.spec.whatwg.org/#readable-stream-add-read-into-request>
|
||||
pub(crate) fn add_read_into_request(&self, read_request: &ReadIntoRequest) {
|
||||
match self.reader {
|
||||
match self.reader.borrow().as_ref() {
|
||||
// Assert: stream.[[reader]] implements ReadableStreamBYOBReader.
|
||||
ReaderType::Default(_) => {
|
||||
unreachable!("Adding a read into request can only be done on a BYOB reader.")
|
||||
},
|
||||
ReaderType::BYOB(ref reader) => {
|
||||
Some(ReaderType::BYOB(ref reader)) => {
|
||||
let Some(reader) = reader.get() else {
|
||||
unreachable!(
|
||||
"Attempt to add a read into request without having first acquired a reader."
|
||||
|
@ -372,20 +382,25 @@ impl ReadableStream {
|
|||
// Append readRequest to stream.[[reader]].[[readIntoRequests]].
|
||||
reader.add_read_into_request(read_request);
|
||||
},
|
||||
_ => {
|
||||
unreachable!("Adding a read into request can only be done on a BYOB reader.")
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
/// Endpoint to enqueue chunks directly from Rust.
|
||||
/// Note: in other use cases this call happens via the controller.
|
||||
pub(crate) fn enqueue_native(&self, bytes: Vec<u8>, can_gc: CanGc) {
|
||||
match self.controller {
|
||||
ControllerType::Default(ref controller) => controller
|
||||
match self.controller.borrow().as_ref() {
|
||||
Some(ControllerType::Default(ref controller)) => controller
|
||||
.get()
|
||||
.expect("Stream should have controller.")
|
||||
.enqueue_native(bytes, can_gc),
|
||||
_ => unreachable!(
|
||||
"Enqueueing chunk to a stream from Rust on other than default controller"
|
||||
),
|
||||
_ => {
|
||||
unreachable!(
|
||||
"Enqueueing chunk to a stream from Rust on other than default controller"
|
||||
);
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -393,22 +408,37 @@ impl ReadableStream {
|
|||
pub(crate) fn error(&self, e: SafeHandleValue, can_gc: CanGc) {
|
||||
// Assert: stream.[[state]] is "readable".
|
||||
assert!(self.is_readable());
|
||||
|
||||
// Set stream.[[state]] to "errored".
|
||||
self.state.set(ReadableStreamState::Errored);
|
||||
|
||||
// Set stream.[[storedError]] to e.
|
||||
self.stored_error.set(e.get());
|
||||
|
||||
// Let reader be stream.[[reader]].
|
||||
match self.reader {
|
||||
ReaderType::Default(ref reader) => {
|
||||
|
||||
match self.reader.borrow().as_ref() {
|
||||
Some(ReaderType::Default(ref reader)) => {
|
||||
let Some(reader) = reader.get() else {
|
||||
// If reader is undefined, return.
|
||||
return;
|
||||
};
|
||||
|
||||
// Perform ! ReadableStreamDefaultReaderErrorReadRequests(reader, e).
|
||||
reader.error(e, can_gc);
|
||||
},
|
||||
// Perform ! ReadableStreamBYOBReaderErrorReadIntoRequests(reader, e).
|
||||
_ => todo!(),
|
||||
Some(ReaderType::BYOB(ref reader)) => {
|
||||
let Some(reader) = reader.get() else {
|
||||
// If reader is undefined, return.
|
||||
return;
|
||||
};
|
||||
|
||||
// Perform ! ReadableStreamBYOBReaderErrorReadIntoRequests(reader, e).
|
||||
reader.error_read_into_requests(e, can_gc);
|
||||
},
|
||||
None => {
|
||||
// If reader is undefined, return.
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -429,14 +459,14 @@ impl ReadableStream {
|
|||
/// Call into the controller's `Close` method.
|
||||
/// <https://streams.spec.whatwg.org/#readable-stream-default-controller-close>
|
||||
pub(crate) fn controller_close_native(&self, can_gc: CanGc) {
|
||||
match self.controller {
|
||||
ControllerType::Default(ref controller) => {
|
||||
match self.controller.borrow().as_ref() {
|
||||
Some(ControllerType::Default(ref controller)) => {
|
||||
let _ = controller
|
||||
.get()
|
||||
.expect("Stream should have controller.")
|
||||
.Close(can_gc);
|
||||
},
|
||||
ControllerType::Byte(_) => {
|
||||
_ => {
|
||||
unreachable!("Native closing is only done on default controllers.")
|
||||
},
|
||||
}
|
||||
|
@ -445,26 +475,28 @@ impl ReadableStream {
|
|||
/// Returns a boolean reflecting whether the stream has all data in memory.
|
||||
/// Useful for native source integration only.
|
||||
pub(crate) fn in_memory(&self) -> bool {
|
||||
match self.controller {
|
||||
ControllerType::Default(ref controller) => controller
|
||||
match self.controller.borrow().as_ref() {
|
||||
Some(ControllerType::Default(ref controller)) => controller
|
||||
.get()
|
||||
.expect("Stream should have controller.")
|
||||
.in_memory(),
|
||||
ControllerType::Byte(_) => unreachable!(
|
||||
"Checking if source is in memory for a stream with a non-default controller"
|
||||
),
|
||||
_ => {
|
||||
unreachable!(
|
||||
"Checking if source is in memory for a stream with a non-default controller"
|
||||
)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
/// Return bytes for synchronous use, if the stream has all data in memory.
|
||||
/// Useful for native source integration only.
|
||||
pub(crate) fn get_in_memory_bytes(&self) -> Option<Vec<u8>> {
|
||||
match self.controller {
|
||||
ControllerType::Default(ref controller) => controller
|
||||
match self.controller.borrow().as_ref() {
|
||||
Some(ControllerType::Default(ref controller)) => controller
|
||||
.get()
|
||||
.expect("Stream should have controller.")
|
||||
.get_in_memory_bytes(),
|
||||
ControllerType::Byte(_) => {
|
||||
_ => {
|
||||
unreachable!("Getting in-memory bytes for a stream with a non-default controller")
|
||||
},
|
||||
}
|
||||
|
@ -503,13 +535,26 @@ impl ReadableStream {
|
|||
}
|
||||
|
||||
pub(crate) fn get_default_controller(&self) -> DomRoot<ReadableStreamDefaultController> {
|
||||
match self.controller {
|
||||
ControllerType::Default(ref controller) => {
|
||||
match self.controller.borrow().as_ref() {
|
||||
Some(ControllerType::Default(ref controller)) => {
|
||||
controller.get().expect("Stream should have controller.")
|
||||
},
|
||||
ControllerType::Byte(_) => unreachable!(
|
||||
"Getting default controller for a stream with a non-default controller"
|
||||
),
|
||||
_ => {
|
||||
unreachable!(
|
||||
"Getting default controller for a stream with a non-default controller"
|
||||
)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn get_default_reader(&self) -> DomRoot<ReadableStreamDefaultReader> {
|
||||
match self.reader.borrow().as_ref() {
|
||||
Some(ReaderType::Default(ref reader)) => {
|
||||
reader.get().expect("Stream should have reader.")
|
||||
},
|
||||
_ => {
|
||||
unreachable!("Getting default reader for a stream with a non-default reader")
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -519,8 +564,8 @@ impl ReadableStream {
|
|||
/// Native call to
|
||||
/// <https://streams.spec.whatwg.org/#readable-stream-default-reader-read>
|
||||
pub(crate) fn read_a_chunk(&self, can_gc: CanGc) -> Rc<Promise> {
|
||||
match self.reader {
|
||||
ReaderType::Default(ref reader) => {
|
||||
match self.reader.borrow().as_ref() {
|
||||
Some(ReaderType::Default(ref reader)) => {
|
||||
let Some(reader) = reader.get() else {
|
||||
unreachable!(
|
||||
"Attempt to read stream chunk without having first acquired a reader."
|
||||
|
@ -528,7 +573,7 @@ impl ReadableStream {
|
|||
};
|
||||
reader.Read(can_gc)
|
||||
},
|
||||
ReaderType::BYOB(_) => {
|
||||
_ => {
|
||||
unreachable!("Native reading of a chunk can only be done with a default reader.")
|
||||
},
|
||||
}
|
||||
|
@ -539,14 +584,18 @@ impl ReadableStream {
|
|||
/// Native call to
|
||||
/// <https://streams.spec.whatwg.org/#abstract-opdef-readablestreamdefaultreaderrelease>
|
||||
pub(crate) fn stop_reading(&self, can_gc: CanGc) {
|
||||
match self.reader {
|
||||
ReaderType::Default(ref reader) => {
|
||||
let reader_ref = self.reader.borrow();
|
||||
|
||||
match reader_ref.as_ref() {
|
||||
Some(ReaderType::Default(ref reader)) => {
|
||||
let Some(reader) = reader.get() else {
|
||||
unreachable!("Attempt to stop reading without having first acquired a reader.");
|
||||
};
|
||||
|
||||
drop(reader_ref);
|
||||
reader.release(can_gc).expect("Reader release cannot fail.");
|
||||
},
|
||||
ReaderType::BYOB(_) => {
|
||||
_ => {
|
||||
unreachable!("Native stop reading can only be done with a default reader.")
|
||||
},
|
||||
}
|
||||
|
@ -554,9 +603,10 @@ impl ReadableStream {
|
|||
|
||||
/// <https://streams.spec.whatwg.org/#is-readable-stream-locked>
|
||||
pub(crate) fn is_locked(&self) -> bool {
|
||||
match self.reader {
|
||||
ReaderType::Default(ref reader) => reader.get().is_some(),
|
||||
ReaderType::BYOB(ref reader) => reader.get().is_some(),
|
||||
match self.reader.borrow().as_ref() {
|
||||
Some(ReaderType::Default(ref reader)) => reader.get().is_some(),
|
||||
Some(ReaderType::BYOB(ref reader)) => reader.get().is_some(),
|
||||
None => false,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -581,39 +631,70 @@ impl ReadableStream {
|
|||
}
|
||||
|
||||
pub(crate) fn has_default_reader(&self) -> bool {
|
||||
match self.reader {
|
||||
ReaderType::Default(ref reader) => reader.get().is_some(),
|
||||
ReaderType::BYOB(_) => false,
|
||||
match self.reader.borrow().as_ref() {
|
||||
Some(ReaderType::Default(ref reader)) => reader.get().is_some(),
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn has_byob_reader(&self) -> bool {
|
||||
match self.reader.borrow().as_ref() {
|
||||
Some(ReaderType::BYOB(ref reader)) => reader.get().is_some(),
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn has_byte_controller(&self) -> bool {
|
||||
matches!(self.controller, ControllerType::Byte(_))
|
||||
match self.controller.borrow().as_ref() {
|
||||
Some(ControllerType::Byte(ref controller)) => controller.get().is_some(),
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
/// <https://streams.spec.whatwg.org/#readable-stream-get-num-read-requests>
|
||||
pub(crate) fn get_num_read_requests(&self) -> usize {
|
||||
assert!(self.has_default_reader());
|
||||
match self.reader {
|
||||
ReaderType::Default(ref reader) => {
|
||||
match self.reader.borrow().as_ref() {
|
||||
Some(ReaderType::Default(ref reader)) => {
|
||||
let reader = reader
|
||||
.get()
|
||||
.expect("Stream must have a reader when get num read requests is called into.");
|
||||
.expect("Stream must have a reader when getting the number of read requests.");
|
||||
reader.get_num_read_requests()
|
||||
},
|
||||
ReaderType::BYOB(_) => unreachable!(
|
||||
_ => unreachable!(
|
||||
"Stream must have a default reader when get num read requests is called into."
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
/// <https://streams.spec.whatwg.org/#readable-stream-get-num-read-into-requests>
|
||||
pub(crate) fn get_num_read_into_requests(&self) -> usize {
|
||||
assert!(self.has_byob_reader());
|
||||
|
||||
match self.reader.borrow().as_ref() {
|
||||
Some(ReaderType::BYOB(ref reader)) => {
|
||||
let Some(reader) = reader.get() else {
|
||||
unreachable!(
|
||||
"Stream must have a reader when get num read into requests is called into."
|
||||
);
|
||||
};
|
||||
reader.get_num_read_into_requests()
|
||||
},
|
||||
_ => {
|
||||
unreachable!(
|
||||
"Stream must have a BYOB reader when get num read into requests is called into."
|
||||
);
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
/// <https://streams.spec.whatwg.org/#readable-stream-fulfill-read-request>
|
||||
#[cfg_attr(crown, allow(crown::unrooted_must_root))]
|
||||
pub(crate) fn fulfill_read_request(&self, chunk: SafeHandleValue, done: bool, can_gc: CanGc) {
|
||||
// step 1 - Assert: ! ReadableStreamHasDefaultReader(stream) is true.
|
||||
assert!(self.has_default_reader());
|
||||
match self.reader {
|
||||
ReaderType::Default(ref reader) => {
|
||||
|
||||
match self.reader.borrow().as_ref() {
|
||||
Some(ReaderType::Default(ref reader)) => {
|
||||
// step 2 - Let reader be stream.[[reader]].
|
||||
let reader = reader
|
||||
.get()
|
||||
|
@ -634,12 +715,59 @@ impl ReadableStream {
|
|||
request.chunk_steps(result, can_gc);
|
||||
}
|
||||
},
|
||||
ReaderType::BYOB(_) => unreachable!(
|
||||
"Stream must have a default reader when fulfill read requests is called into."
|
||||
),
|
||||
_ => {
|
||||
unreachable!(
|
||||
"Stream must have a default reader when fulfill read requests is called into."
|
||||
);
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
/// <https://streams.spec.whatwg.org/#readable-stream-fulfill-read-into-request>
|
||||
pub(crate) fn fulfill_read_into_request(
|
||||
&self,
|
||||
chunk: SafeHandleValue,
|
||||
done: bool,
|
||||
can_gc: CanGc,
|
||||
) {
|
||||
// Assert: ! ReadableStreamHasBYOBReader(stream) is true.
|
||||
assert!(self.has_byob_reader());
|
||||
|
||||
// Let reader be stream.[[reader]].
|
||||
match self.reader.borrow().as_ref() {
|
||||
Some(ReaderType::BYOB(ref reader)) => {
|
||||
let Some(reader) = reader.get() else {
|
||||
unreachable!(
|
||||
"Stream must have a reader when a read into request is fulfilled."
|
||||
);
|
||||
};
|
||||
|
||||
// Assert: reader.[[readIntoRequests]] is not empty.
|
||||
assert!(reader.get_num_read_into_requests() > 0);
|
||||
|
||||
// Let readIntoRequest be reader.[[readIntoRequests]][0].
|
||||
// Remove readIntoRequest from reader.[[readIntoRequests]].
|
||||
let read_into_request = reader.remove_read_into_request();
|
||||
|
||||
// If done is true, perform readIntoRequest’s close steps, given chunk.
|
||||
let result = RootedTraceableBox::new(Heap::default());
|
||||
if done {
|
||||
result.set(*chunk);
|
||||
read_into_request.close_steps(Some(result), can_gc);
|
||||
} else {
|
||||
// Otherwise, perform readIntoRequest’s chunk steps, given chunk.
|
||||
result.set(*chunk);
|
||||
read_into_request.chunk_steps(result, can_gc);
|
||||
}
|
||||
},
|
||||
_ => {
|
||||
unreachable!(
|
||||
"Stream must have a BYOB reader when fulfill read into requests is called into."
|
||||
);
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/// <https://streams.spec.whatwg.org/#readable-stream-close>
|
||||
pub(crate) fn close(&self, can_gc: CanGc) {
|
||||
// Assert: stream.[[state]] is "readable".
|
||||
|
@ -647,8 +775,8 @@ impl ReadableStream {
|
|||
// Set stream.[[state]] to "closed".
|
||||
self.state.set(ReadableStreamState::Closed);
|
||||
// Let reader be stream.[[reader]].
|
||||
match self.reader {
|
||||
ReaderType::Default(ref reader) => {
|
||||
match self.reader.borrow().as_ref() {
|
||||
Some(ReaderType::Default(ref reader)) => {
|
||||
let Some(reader) = reader.get() else {
|
||||
// If reader is undefined, return.
|
||||
return;
|
||||
|
@ -656,7 +784,17 @@ impl ReadableStream {
|
|||
// step 5 & 6
|
||||
reader.close(can_gc);
|
||||
},
|
||||
ReaderType::BYOB(ref _reader) => {},
|
||||
Some(ReaderType::BYOB(ref reader)) => {
|
||||
let Some(reader) = reader.get() else {
|
||||
// If reader is undefined, return.
|
||||
return;
|
||||
};
|
||||
|
||||
reader.close(can_gc)
|
||||
},
|
||||
None => {
|
||||
// If reader is undefined, return.
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -685,24 +823,26 @@ impl ReadableStream {
|
|||
self.close(can_gc);
|
||||
|
||||
// If reader is not undefined and reader implements ReadableStreamBYOBReader,
|
||||
match self.reader {
|
||||
ReaderType::BYOB(ref reader) => {
|
||||
if let Some(reader) = reader.get() {
|
||||
// step 6.1, 6.2 & 6.3 of https://streams.spec.whatwg.org/#readable-stream-cancel
|
||||
reader.close(can_gc);
|
||||
}
|
||||
},
|
||||
ReaderType::Default(ref _reader) => {},
|
||||
if let Some(ReaderType::BYOB(ref reader)) = self.reader.borrow().as_ref() {
|
||||
if let Some(reader) = reader.get() {
|
||||
// step 6.1, 6.2 & 6.3 of https://streams.spec.whatwg.org/#readable-stream-cancel
|
||||
reader.cancel(can_gc);
|
||||
}
|
||||
}
|
||||
|
||||
// Let sourceCancelPromise be ! stream.[[controller]].[[CancelSteps]](reason).
|
||||
let source_cancel_promise = match self.controller {
|
||||
ControllerType::Default(ref controller) => controller
|
||||
|
||||
let source_cancel_promise = match self.controller.borrow().as_ref() {
|
||||
Some(ControllerType::Default(ref controller)) => controller
|
||||
.get()
|
||||
.expect("Stream should have controller.")
|
||||
.perform_cancel_steps(reason, can_gc),
|
||||
ControllerType::Byte(_) => {
|
||||
todo!()
|
||||
Some(ControllerType::Byte(ref controller)) => controller
|
||||
.get()
|
||||
.expect("Stream should have controller.")
|
||||
.perform_cancel_steps(reason, can_gc),
|
||||
None => {
|
||||
panic!("Stream does not have a controller.");
|
||||
},
|
||||
};
|
||||
|
||||
|
@ -733,23 +873,7 @@ impl ReadableStream {
|
|||
|
||||
#[cfg_attr(crown, allow(crown::unrooted_must_root))]
|
||||
pub(crate) fn set_reader(&self, new_reader: Option<ReaderType>) {
|
||||
match (&self.reader, new_reader) {
|
||||
(ReaderType::Default(ref reader), Some(ReaderType::Default(new_reader))) => {
|
||||
reader.set(new_reader.get().as_deref());
|
||||
},
|
||||
(ReaderType::BYOB(ref reader), Some(ReaderType::BYOB(new_reader))) => {
|
||||
reader.set(new_reader.get().as_deref());
|
||||
},
|
||||
(ReaderType::Default(ref reader), None) => {
|
||||
reader.set(None);
|
||||
},
|
||||
(ReaderType::BYOB(ref reader), None) => {
|
||||
reader.set(None);
|
||||
},
|
||||
(_, _) => {
|
||||
unreachable!("Setting a mismatched reader type is not allowed.");
|
||||
},
|
||||
}
|
||||
*self.reader.borrow_mut() = new_reader;
|
||||
}
|
||||
|
||||
/// <https://streams.spec.whatwg.org/#abstract-opdef-readablestreamdefaulttee>
|
||||
|
@ -865,18 +989,68 @@ impl ReadableStream {
|
|||
// Assert: stream implements ReadableStream.
|
||||
// Assert: cloneForBranch2 is a boolean.
|
||||
|
||||
match self.controller {
|
||||
ControllerType::Default(ref _controller) => {
|
||||
match self.controller.borrow().as_ref() {
|
||||
Some(ControllerType::Default(_)) => {
|
||||
// Return ? ReadableStreamDefaultTee(stream, cloneForBranch2).
|
||||
self.default_tee(clone_for_branch_2, can_gc)
|
||||
},
|
||||
ControllerType::Byte(ref _controller) => {
|
||||
Some(ControllerType::Byte(_)) => {
|
||||
// If stream.[[controller]] implements ReadableByteStreamController,
|
||||
// return ? ReadableByteStreamTee(stream).
|
||||
todo!()
|
||||
Err(Error::Type(
|
||||
"Teeing is not yet supported for byte streams".to_owned(),
|
||||
))
|
||||
},
|
||||
None => {
|
||||
unreachable!("Stream should have a controller.");
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
/// <https://streams.spec.whatwg.org/#set-up-readable-byte-stream-controller-from-underlying-source>
|
||||
pub(crate) fn set_up_byte_controller(
|
||||
&self,
|
||||
global: &GlobalScope,
|
||||
underlying_source_dict: JsUnderlyingSource,
|
||||
underlying_source_handle: SafeHandleObject,
|
||||
stream: DomRoot<ReadableStream>,
|
||||
strategy_hwm: f64,
|
||||
can_gc: CanGc,
|
||||
) -> Fallible<()> {
|
||||
// Let pullAlgorithm be an algorithm that returns a promise resolved with undefined.
|
||||
// Let cancelAlgorithm be an algorithm that returns a promise resolved with undefined.
|
||||
// If underlyingSourceDict["start"] exists, then set startAlgorithm to an algorithm which returns the result
|
||||
// of invoking underlyingSourceDict["start"] with argument list « controller »
|
||||
// and callback this value underlyingSource.
|
||||
// If underlyingSourceDict["pull"] exists, then set pullAlgorithm to an algorithm which returns the result
|
||||
// of invoking underlyingSourceDict["pull"] with argument list « controller »
|
||||
// and callback this value underlyingSource.
|
||||
// If underlyingSourceDict["cancel"] exists, then set cancelAlgorithm to an algorithm which takes an
|
||||
// argument reason and returns the result of invoking underlyingSourceDict["cancel"] with argument list
|
||||
// « reason » and callback this value underlyingSource.
|
||||
|
||||
// Let autoAllocateChunkSize be underlyingSourceDict["autoAllocateChunkSize"],
|
||||
// if it exists, or undefined otherwise.
|
||||
// If autoAllocateChunkSize is 0, then throw a TypeError exception.
|
||||
if let Some(0) = underlying_source_dict.autoAllocateChunkSize {
|
||||
return Err(Error::Type("autoAllocateChunkSize cannot be 0".to_owned()));
|
||||
}
|
||||
|
||||
let controller = ReadableByteStreamController::new(
|
||||
UnderlyingSourceType::Js(underlying_source_dict, Heap::default()),
|
||||
strategy_hwm,
|
||||
global,
|
||||
can_gc,
|
||||
);
|
||||
|
||||
// Note: this must be done before `setup`,
|
||||
// otherwise `thisOb` is null in the start callback.
|
||||
controller.set_underlying_source_this_object(underlying_source_handle);
|
||||
|
||||
// Perform ? SetUpReadableByteStreamController(stream, controller, startAlgorithm,
|
||||
// pullAlgorithm, cancelAlgorithm, highWaterMark, autoAllocateChunkSize).
|
||||
controller.setup(global, stream, can_gc)
|
||||
}
|
||||
}
|
||||
|
||||
impl ReadableStreamMethods<crate::DomTypeHolder> for ReadableStream {
|
||||
|
@ -907,25 +1081,29 @@ impl ReadableStreamMethods<crate::DomTypeHolder> for ReadableStream {
|
|||
};
|
||||
|
||||
// Perform ! InitializeReadableStream(this).
|
||||
let stream = if underlying_source_dict.type_.is_some() {
|
||||
ReadableStream::new_with_proto(
|
||||
global,
|
||||
proto,
|
||||
ControllerType::Byte(MutNullableDom::new(None)),
|
||||
can_gc,
|
||||
)
|
||||
} else {
|
||||
ReadableStream::new_with_proto(
|
||||
global,
|
||||
proto,
|
||||
ControllerType::Default(MutNullableDom::new(None)),
|
||||
can_gc,
|
||||
)
|
||||
};
|
||||
let stream = ReadableStream::new_with_proto(global, proto, can_gc);
|
||||
|
||||
if underlying_source_dict.type_.is_some() {
|
||||
// TODO: If underlyingSourceDict["type"] is "bytes"
|
||||
return Err(Error::Type("Bytes streams not implemented".to_string()));
|
||||
// If strategy["size"] exists, throw a RangeError exception.
|
||||
if strategy.size.is_some() {
|
||||
return Err(Error::Range(
|
||||
"size is not supported for byte streams".to_owned(),
|
||||
));
|
||||
}
|
||||
|
||||
// Let highWaterMark be ? ExtractHighWaterMark(strategy, 0).
|
||||
let strategy_hwm = extract_high_water_mark(strategy, 0.0)?;
|
||||
|
||||
// Perform ? SetUpReadableByteStreamControllerFromUnderlyingSource(this,
|
||||
// underlyingSource, underlyingSourceDict, highWaterMark).
|
||||
stream.set_up_byte_controller(
|
||||
global,
|
||||
underlying_source_dict,
|
||||
underlying_source_obj.handle(),
|
||||
stream.clone(),
|
||||
strategy_hwm,
|
||||
can_gc,
|
||||
)?;
|
||||
} else {
|
||||
// Let highWaterMark be ? ExtractHighWaterMark(strategy, 1).
|
||||
let high_water_mark = extract_high_water_mark(strategy, 1.0)?;
|
||||
|
|
|
@ -14,7 +14,7 @@ use js::jsval::{JSVal, UndefinedValue};
|
|||
use js::rust::{HandleObject as SafeHandleObject, HandleValue as SafeHandleValue};
|
||||
use js::typedarray::{ArrayBufferView, ArrayBufferViewU8};
|
||||
|
||||
use super::bindings::buffer_source::{BufferSource, HeapBufferSource};
|
||||
use super::bindings::buffer_source::HeapBufferSource;
|
||||
use super::bindings::codegen::Bindings::ReadableStreamBYOBReaderBinding::ReadableStreamBYOBReaderReadOptions;
|
||||
use super::bindings::codegen::Bindings::ReadableStreamDefaultReaderBinding::ReadableStreamReadResult;
|
||||
use super::bindings::reflector::reflect_dom_object;
|
||||
|
@ -69,7 +69,17 @@ impl ReadIntoRequest {
|
|||
},
|
||||
can_gc,
|
||||
),
|
||||
None => promise.resolve_native(&(), can_gc),
|
||||
None => {
|
||||
let result = RootedTraceableBox::new(Heap::default());
|
||||
result.set(UndefinedValue());
|
||||
promise.resolve_native(
|
||||
&ReadableStreamReadResult {
|
||||
done: Some(true),
|
||||
value: result,
|
||||
},
|
||||
can_gc,
|
||||
);
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -177,14 +187,20 @@ impl ReadableStreamBYOBReader {
|
|||
}
|
||||
|
||||
/// <https://streams.spec.whatwg.org/#abstract-opdef-readablestreambyobreadererrorreadintorequests>
|
||||
fn error_read_into_requests(&self, rval: SafeHandleValue, can_gc: CanGc) {
|
||||
pub(crate) fn error_read_into_requests(&self, e: SafeHandleValue, can_gc: CanGc) {
|
||||
// Reject reader.[[closedPromise]] with e.
|
||||
self.closed_promise.borrow().reject_native(&e, can_gc);
|
||||
|
||||
// Set reader.[[closedPromise]].[[PromiseIsHandled]] to true.
|
||||
self.closed_promise.borrow().set_promise_is_handled();
|
||||
|
||||
// Let readRequests be reader.[[readRequests]].
|
||||
let mut read_into_requests = self.take_read_into_requests();
|
||||
|
||||
// Set reader.[[readIntoRequests]] to a new empty list.
|
||||
for request in read_into_requests.drain(0..) {
|
||||
// Perform readIntoRequest’s error steps, given e.
|
||||
request.error_steps(rval, can_gc);
|
||||
request.error_steps(e, can_gc);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -200,7 +216,7 @@ impl ReadableStreamBYOBReader {
|
|||
}
|
||||
|
||||
/// <https://streams.spec.whatwg.org/#readable-stream-cancel>
|
||||
pub(crate) fn close(&self, can_gc: CanGc) {
|
||||
pub(crate) fn cancel(&self, can_gc: CanGc) {
|
||||
// If reader is not undefined and reader implements ReadableStreamBYOBReader,
|
||||
// Let readIntoRequests be reader.[[readIntoRequests]].
|
||||
let mut read_into_requests = self.take_read_into_requests();
|
||||
|
@ -212,9 +228,15 @@ impl ReadableStreamBYOBReader {
|
|||
}
|
||||
}
|
||||
|
||||
pub(crate) fn close(&self, can_gc: CanGc) {
|
||||
// Resolve reader.[[closedPromise]] with undefined.
|
||||
self.closed_promise.borrow().resolve_native(&(), can_gc);
|
||||
}
|
||||
|
||||
/// <https://streams.spec.whatwg.org/#readable-stream-byob-reader-read>
|
||||
pub(crate) fn read(
|
||||
&self,
|
||||
cx: SafeJSContext,
|
||||
view: HeapBufferSource<ArrayBufferViewU8>,
|
||||
options: &ReadableStreamBYOBReaderReadOptions,
|
||||
read_into_request: &ReadIntoRequest,
|
||||
|
@ -234,13 +256,25 @@ impl ReadableStreamBYOBReader {
|
|||
let cx = GlobalScope::get_cx();
|
||||
rooted!(in(*cx) let mut error = UndefinedValue());
|
||||
stream.get_stored_error(error.handle_mut());
|
||||
|
||||
read_into_request.error_steps(error.handle(), can_gc);
|
||||
} else {
|
||||
// Otherwise,
|
||||
// perform ! ReadableByteStreamControllerPullInto(stream.[[controller]], view, min, readIntoRequest).
|
||||
stream.perform_pull_into_steps(read_into_request, view, options, can_gc);
|
||||
stream.perform_pull_into(cx, read_into_request, view, options, can_gc);
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn get_num_read_into_requests(&self) -> usize {
|
||||
self.read_into_requests.borrow().len()
|
||||
}
|
||||
|
||||
pub(crate) fn remove_read_into_request(&self) -> ReadIntoRequest {
|
||||
self.read_into_requests
|
||||
.borrow_mut()
|
||||
.pop_front()
|
||||
.expect("read into requests is empty")
|
||||
}
|
||||
}
|
||||
|
||||
impl ReadableStreamBYOBReaderMethods<crate::DomTypeHolder> for ReadableStreamBYOBReader {
|
||||
|
@ -260,16 +294,13 @@ impl ReadableStreamBYOBReaderMethods<crate::DomTypeHolder> for ReadableStreamBYO
|
|||
}
|
||||
|
||||
/// <https://streams.spec.whatwg.org/#byob-reader-read>
|
||||
#[allow(unsafe_code)]
|
||||
fn Read(
|
||||
&self,
|
||||
view: CustomAutoRooterGuard<ArrayBufferView>,
|
||||
options: &ReadableStreamBYOBReaderReadOptions,
|
||||
can_gc: CanGc,
|
||||
) -> Rc<Promise> {
|
||||
let view = HeapBufferSource::<ArrayBufferViewU8>::new(BufferSource::ArrayBufferView(
|
||||
Heap::boxed(unsafe { *view.underlying_object() }),
|
||||
));
|
||||
let view = HeapBufferSource::<ArrayBufferViewU8>::from_view(view);
|
||||
|
||||
// Let promise be a new promise.
|
||||
let promise = Promise::new(&self.global(), can_gc);
|
||||
|
@ -306,9 +337,9 @@ impl ReadableStreamBYOBReaderMethods<crate::DomTypeHolder> for ReadableStreamBYO
|
|||
// If view has a [[TypedArrayName]] internal slot,
|
||||
if view.has_typed_array_name() {
|
||||
// If options["min"] > view.[[ArrayLength]], return a promise rejected with a RangeError exception.
|
||||
if options.min > (view.array_length() as u64) {
|
||||
if options.min > (view.get_typed_array_length() as u64) {
|
||||
promise.reject_error(
|
||||
Error::Type("min is greater than array length".to_owned()),
|
||||
Error::Range("min is greater than array length".to_owned()),
|
||||
can_gc,
|
||||
);
|
||||
return promise;
|
||||
|
@ -318,7 +349,7 @@ impl ReadableStreamBYOBReaderMethods<crate::DomTypeHolder> for ReadableStreamBYO
|
|||
// If options["min"] > view.[[ByteLength]], return a promise rejected with a RangeError exception.
|
||||
if options.min > (view.byte_length() as u64) {
|
||||
promise.reject_error(
|
||||
Error::Type("min is greater than byte length".to_owned()),
|
||||
Error::Range("min is greater than byte length".to_owned()),
|
||||
can_gc,
|
||||
);
|
||||
return promise;
|
||||
|
@ -347,7 +378,7 @@ impl ReadableStreamBYOBReaderMethods<crate::DomTypeHolder> for ReadableStreamBYO
|
|||
let read_into_request = ReadIntoRequest::Read(promise.clone());
|
||||
|
||||
// Perform ! ReadableStreamBYOBReaderRead(this, view, options["min"], readIntoRequest).
|
||||
self.read(view, options, &read_into_request, can_gc);
|
||||
self.read(cx, view, options, &read_into_request, can_gc);
|
||||
|
||||
// Return promise.
|
||||
promise
|
||||
|
@ -371,7 +402,7 @@ impl ReadableStreamBYOBReaderMethods<crate::DomTypeHolder> for ReadableStreamBYO
|
|||
|
||||
/// <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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -4,17 +4,19 @@
|
|||
|
||||
use dom_struct::dom_struct;
|
||||
use js::gc::CustomAutoRooterGuard;
|
||||
use js::jsapi::Heap;
|
||||
use js::typedarray::{ArrayBufferView, ArrayBufferViewU8};
|
||||
|
||||
use super::bindings::buffer_source::{BufferSource, HeapBufferSource};
|
||||
use super::bindings::buffer_source::HeapBufferSource;
|
||||
use super::bindings::cell::DomRefCell;
|
||||
use super::bindings::reflector::reflect_dom_object;
|
||||
use super::bindings::root::DomRoot;
|
||||
use crate::dom::bindings::codegen::Bindings::ReadableStreamBYOBRequestBinding::ReadableStreamBYOBRequestMethods;
|
||||
use crate::dom::bindings::import::module::{Error, Fallible};
|
||||
use crate::dom::bindings::reflector::Reflector;
|
||||
use crate::dom::bindings::root::MutNullableDom;
|
||||
use crate::dom::readablebytestreamcontroller::ReadableByteStreamController;
|
||||
use crate::dom::types::GlobalScope;
|
||||
use crate::script_runtime::JSContext as SafeJSContext;
|
||||
use crate::script_runtime::{CanGc, JSContext as SafeJSContext};
|
||||
|
||||
/// <https://streams.spec.whatwg.org/#readablestreambyobrequest>
|
||||
#[dom_struct]
|
||||
|
@ -22,18 +24,47 @@ pub(crate) struct ReadableStreamBYOBRequest {
|
|||
reflector_: Reflector,
|
||||
controller: MutNullableDom<ReadableByteStreamController>,
|
||||
#[ignore_malloc_size_of = "mozjs"]
|
||||
view: HeapBufferSource<ArrayBufferViewU8>,
|
||||
view: DomRefCell<HeapBufferSource<ArrayBufferViewU8>>,
|
||||
}
|
||||
|
||||
impl ReadableStreamBYOBRequest {
|
||||
fn new_inherited() -> ReadableStreamBYOBRequest {
|
||||
ReadableStreamBYOBRequest {
|
||||
reflector_: Reflector::new(),
|
||||
controller: MutNullableDom::new(None),
|
||||
view: DomRefCell::new(HeapBufferSource::<ArrayBufferViewU8>::default()),
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn new(global: &GlobalScope, can_gc: CanGc) -> DomRoot<ReadableStreamBYOBRequest> {
|
||||
reflect_dom_object(Box::new(Self::new_inherited()), global, can_gc)
|
||||
}
|
||||
|
||||
pub(crate) fn set_controller(&self, controller: Option<&ReadableByteStreamController>) {
|
||||
self.controller.set(controller);
|
||||
}
|
||||
|
||||
pub(crate) fn set_view(&self, view: Option<HeapBufferSource<ArrayBufferViewU8>>) {
|
||||
match view {
|
||||
Some(view) => {
|
||||
*self.view.borrow_mut() = view;
|
||||
},
|
||||
None => {
|
||||
*self.view.borrow_mut() = HeapBufferSource::<ArrayBufferViewU8>::default();
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ReadableStreamBYOBRequestMethods<crate::DomTypeHolder> for ReadableStreamBYOBRequest {
|
||||
/// <https://streams.spec.whatwg.org/#rs-byob-request-view>
|
||||
fn GetView(&self, _cx: SafeJSContext) -> Option<js::typedarray::ArrayBufferView> {
|
||||
// Return this.[[view]].
|
||||
self.view.buffer_to_option()
|
||||
self.view.borrow().typed_array_to_option()
|
||||
}
|
||||
|
||||
/// <https://streams.spec.whatwg.org/#rs-byob-request-respond>
|
||||
fn Respond(&self, bytes_written: u64) -> Fallible<()> {
|
||||
fn Respond(&self, bytes_written: u64, can_gc: CanGc) -> Fallible<()> {
|
||||
let cx = GlobalScope::get_cx();
|
||||
|
||||
// If this.[[controller]] is undefined, throw a TypeError exception.
|
||||
|
@ -43,27 +74,32 @@ impl ReadableStreamBYOBRequestMethods<crate::DomTypeHolder> for ReadableStreamBY
|
|||
return Err(Error::Type("controller is undefined".to_owned()));
|
||||
};
|
||||
|
||||
// If ! IsDetachedBuffer(this.[[view]].[[ArrayBuffer]]) is true, throw a TypeError exception.
|
||||
if self.view.is_detached_buffer(cx) {
|
||||
return Err(Error::Type("buffer is detached".to_owned()));
|
||||
{
|
||||
let view = self.view.borrow();
|
||||
// If ! IsDetachedBuffer(this.[[view]].[[ArrayBuffer]]) is true, throw a TypeError exception.
|
||||
if view.get_array_buffer_view_buffer(cx).is_detached_buffer(cx) {
|
||||
return Err(Error::Type("buffer is detached".to_owned()));
|
||||
}
|
||||
|
||||
// Assert: this.[[view]].[[ByteLength]] > 0.
|
||||
assert!(view.byte_length() > 0);
|
||||
|
||||
// Assert: this.[[view]].[[ViewedArrayBuffer]].[[ByteLength]] > 0.
|
||||
assert!(view.viewed_buffer_array_byte_length(cx) > 0);
|
||||
}
|
||||
|
||||
// Assert: this.[[view]].[[ByteLength]] > 0.
|
||||
assert!(self.view.byte_length() > 0);
|
||||
|
||||
// Assert: this.[[view]].[[ViewedArrayBuffer]].[[ByteLength]] > 0.
|
||||
assert!(self.view.viewed_buffer_array_byte_length(cx) > 0);
|
||||
|
||||
// Perform ? ReadableByteStreamControllerRespond(this.[[controller]], bytesWritten).
|
||||
controller.respond(bytes_written)
|
||||
controller.respond(cx, bytes_written, can_gc)
|
||||
}
|
||||
|
||||
/// <https://streams.spec.whatwg.org/#rs-byob-request-respond-with-new-view>
|
||||
#[allow(unsafe_code)]
|
||||
fn RespondWithNewView(&self, view: CustomAutoRooterGuard<ArrayBufferView>) -> Fallible<()> {
|
||||
let view = HeapBufferSource::<ArrayBufferViewU8>::new(BufferSource::ArrayBufferView(
|
||||
Heap::boxed(unsafe { *view.underlying_object() }),
|
||||
));
|
||||
fn RespondWithNewView(
|
||||
&self,
|
||||
view: CustomAutoRooterGuard<ArrayBufferView>,
|
||||
can_gc: CanGc,
|
||||
) -> Fallible<()> {
|
||||
let cx = GlobalScope::get_cx();
|
||||
let view = HeapBufferSource::<ArrayBufferViewU8>::from_view(view);
|
||||
|
||||
// If this.[[controller]] is undefined, throw a TypeError exception.
|
||||
let controller = if let Some(controller) = self.controller.get() {
|
||||
|
@ -73,11 +109,11 @@ impl ReadableStreamBYOBRequestMethods<crate::DomTypeHolder> for ReadableStreamBY
|
|||
};
|
||||
|
||||
// If ! IsDetachedBuffer(view.[[ViewedArrayBuffer]]) is true, throw a TypeError exception.
|
||||
if self.view.is_detached_buffer(GlobalScope::get_cx()) {
|
||||
if view.is_detached_buffer(cx) {
|
||||
return Err(Error::Type("buffer is detached".to_owned()));
|
||||
}
|
||||
|
||||
// Return ? ReadableByteStreamControllerRespondWithNewView(this.[[controller]], view).
|
||||
controller.respond_with_new_view(view)
|
||||
controller.respond_with_new_view(cx, view, can_gc)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -62,7 +62,7 @@ pub(crate) trait ReadableStreamGenericReader {
|
|||
}
|
||||
|
||||
/// <https://streams.spec.whatwg.org/#readable-stream-reader-generic-cancel>
|
||||
fn generic_cancel(&self, reason: SafeHandleValue, can_gc: CanGc) -> Rc<Promise> {
|
||||
fn reader_generic_cancel(&self, reason: SafeHandleValue, can_gc: CanGc) -> Rc<Promise> {
|
||||
// Let stream be reader.[[stream]].
|
||||
let stream = self.get_stream();
|
||||
|
||||
|
@ -84,7 +84,11 @@ pub(crate) trait ReadableStreamGenericReader {
|
|||
|
||||
if let Some(stream) = self.get_stream() {
|
||||
// Assert: stream.[[reader]] is reader.
|
||||
assert!(stream.has_default_reader());
|
||||
if self.as_default_reader().is_some() {
|
||||
assert!(stream.has_default_reader());
|
||||
} else {
|
||||
assert!(stream.has_byob_reader());
|
||||
}
|
||||
|
||||
if stream.is_readable() {
|
||||
// If stream.[[state]] is "readable", reject reader.[[closedPromise]] with a TypeError exception.
|
||||
|
@ -129,7 +133,12 @@ pub(crate) trait ReadableStreamGenericReader {
|
|||
}
|
||||
|
||||
// <https://streams.spec.whatwg.org/#generic-reader-cancel>
|
||||
fn cancel(&self, global: &GlobalScope, reason: SafeHandleValue, can_gc: CanGc) -> Rc<Promise> {
|
||||
fn generic_cancel(
|
||||
&self,
|
||||
global: &GlobalScope,
|
||||
reason: SafeHandleValue,
|
||||
can_gc: CanGc,
|
||||
) -> Rc<Promise> {
|
||||
if self.get_stream().is_none() {
|
||||
// If this.[[stream]] is undefined,
|
||||
// return a promise rejected with a TypeError exception.
|
||||
|
@ -138,7 +147,7 @@ pub(crate) trait ReadableStreamGenericReader {
|
|||
promise
|
||||
} else {
|
||||
// Return ! ReadableStreamReaderGenericCancel(this, reason).
|
||||
self.generic_cancel(reason, can_gc)
|
||||
self.reader_generic_cancel(reason, can_gc)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -221,6 +221,14 @@ impl UnderlyingSourceContainer {
|
|||
}
|
||||
}
|
||||
|
||||
/// <https://streams.spec.whatwg.org/#dom-underlyingsource-autoallocatechunksize>
|
||||
pub(crate) fn auto_allocate_chunk_size(&self) -> Option<u64> {
|
||||
match &self.underlying_source_type {
|
||||
UnderlyingSourceType::Js(source, _) => source.autoAllocateChunkSize,
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Does the source have all data in memory?
|
||||
pub(crate) fn in_memory(&self) -> bool {
|
||||
self.underlying_source_type.in_memory()
|
||||
|
|
|
@ -168,7 +168,7 @@ impl XRRayMethods<crate::DomTypeHolder> for XRRay {
|
|||
}
|
||||
|
||||
self.matrix
|
||||
.get_buffer()
|
||||
.get_typed_array()
|
||||
.expect("Failed to get matrix from XRRay.")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -175,7 +175,7 @@ impl XRRigidTransformMethods<crate::DomTypeHolder> for XRRigidTransform {
|
|||
}
|
||||
|
||||
self.matrix
|
||||
.get_buffer()
|
||||
.get_typed_array()
|
||||
.expect("Failed to get transform's internal matrix.")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -105,7 +105,7 @@ impl XRViewMethods<crate::DomTypeHolder> for XRView {
|
|||
.expect("Failed to set projection matrix.")
|
||||
}
|
||||
self.proj
|
||||
.get_buffer()
|
||||
.get_typed_array()
|
||||
.expect("Failed to get projection matrix.")
|
||||
}
|
||||
|
||||
|
|
|
@ -1345,7 +1345,7 @@ impl XMLHttpRequest {
|
|||
}
|
||||
|
||||
// Return the correct ArrayBuffer
|
||||
self.response_arraybuffer.get_buffer().ok()
|
||||
self.response_arraybuffer.get_typed_array().ok()
|
||||
}
|
||||
|
||||
/// <https://xhr.spec.whatwg.org/#document-response>
|
||||
|
|
|
@ -638,6 +638,14 @@ DOMInterfaces = {
|
|||
"canGc": ["Close", "Enqueue", "Error"]
|
||||
},
|
||||
|
||||
"ReadableByteStreamController": {
|
||||
"canGc": ["GetByobRequest", "Enqueue", "Close", "Error"]
|
||||
},
|
||||
|
||||
"ReadableStreamBYOBRequest": {
|
||||
"canGc": ["Respond", "RespondWithNewView"]
|
||||
},
|
||||
|
||||
"ReadableStreamBYOBReader": {
|
||||
"canGc": ["Cancel", "Read", "ReleaseLock"]
|
||||
},
|
||||
|
|
2
tests/wpt/include.ini
vendored
2
tests/wpt/include.ini
vendored
|
@ -243,6 +243,8 @@ skip: true
|
|||
skip: true
|
||||
[readable-streams]
|
||||
skip: false
|
||||
[readable-byte-streams]
|
||||
skip: false
|
||||
[writable-streams]
|
||||
skip: false
|
||||
[subresource-integrity]
|
||||
|
|
23
tests/wpt/meta/streams/readable-byte-streams/bad-buffers-and-views.any.js.ini
vendored
Normal file
23
tests/wpt/meta/streams/readable-byte-streams/bad-buffers-and-views.any.js.ini
vendored
Normal file
|
@ -0,0 +1,23 @@
|
|||
[bad-buffers-and-views.any.serviceworker.html]
|
||||
expected: ERROR
|
||||
|
||||
[bad-buffers-and-views.any.shadowrealm-in-window.html]
|
||||
expected: ERROR
|
||||
|
||||
[bad-buffers-and-views.any.shadowrealm-in-dedicatedworker.html]
|
||||
expected: ERROR
|
||||
|
||||
[bad-buffers-and-views.any.shadowrealm-in-shadowrealm.html]
|
||||
expected: ERROR
|
||||
|
||||
[bad-buffers-and-views.https.any.shadowrealm-in-audioworklet.html]
|
||||
expected: ERROR
|
||||
|
||||
[bad-buffers-and-views.https.any.shadowrealm-in-serviceworker.html]
|
||||
expected: ERROR
|
||||
|
||||
[bad-buffers-and-views.any.shadowrealm-in-sharedworker.html]
|
||||
expected: ERROR
|
||||
|
||||
[bad-buffers-and-views.any.sharedworker.html]
|
||||
expected: ERROR
|
23
tests/wpt/meta/streams/readable-byte-streams/construct-byob-request.any.js.ini
vendored
Normal file
23
tests/wpt/meta/streams/readable-byte-streams/construct-byob-request.any.js.ini
vendored
Normal file
|
@ -0,0 +1,23 @@
|
|||
[construct-byob-request.https.any.shadowrealm-in-serviceworker.html]
|
||||
expected: ERROR
|
||||
|
||||
[construct-byob-request.https.any.shadowrealm-in-audioworklet.html]
|
||||
expected: ERROR
|
||||
|
||||
[construct-byob-request.any.shadowrealm-in-sharedworker.html]
|
||||
expected: ERROR
|
||||
|
||||
[construct-byob-request.any.shadowrealm-in-window.html]
|
||||
expected: ERROR
|
||||
|
||||
[construct-byob-request.any.shadowrealm-in-dedicatedworker.html]
|
||||
expected: ERROR
|
||||
|
||||
[construct-byob-request.any.shadowrealm-in-shadowrealm.html]
|
||||
expected: ERROR
|
||||
|
||||
[construct-byob-request.any.serviceworker.html]
|
||||
expected: ERROR
|
||||
|
||||
[construct-byob-request.any.sharedworker.html]
|
||||
expected: ERROR
|
23
tests/wpt/meta/streams/readable-byte-streams/enqueue-with-detached-buffer.any.js.ini
vendored
Normal file
23
tests/wpt/meta/streams/readable-byte-streams/enqueue-with-detached-buffer.any.js.ini
vendored
Normal file
|
@ -0,0 +1,23 @@
|
|||
[enqueue-with-detached-buffer.any.shadowrealm-in-shadowrealm.html]
|
||||
expected: ERROR
|
||||
|
||||
[enqueue-with-detached-buffer.https.any.shadowrealm-in-audioworklet.html]
|
||||
expected: ERROR
|
||||
|
||||
[enqueue-with-detached-buffer.any.sharedworker.html]
|
||||
expected: ERROR
|
||||
|
||||
[enqueue-with-detached-buffer.any.shadowrealm-in-window.html]
|
||||
expected: ERROR
|
||||
|
||||
[enqueue-with-detached-buffer.any.shadowrealm-in-sharedworker.html]
|
||||
expected: ERROR
|
||||
|
||||
[enqueue-with-detached-buffer.any.serviceworker.html]
|
||||
expected: ERROR
|
||||
|
||||
[enqueue-with-detached-buffer.https.any.shadowrealm-in-serviceworker.html]
|
||||
expected: ERROR
|
||||
|
||||
[enqueue-with-detached-buffer.any.shadowrealm-in-dedicatedworker.html]
|
||||
expected: ERROR
|
23
tests/wpt/meta/streams/readable-byte-streams/general.any.js.ini
vendored
Normal file
23
tests/wpt/meta/streams/readable-byte-streams/general.any.js.ini
vendored
Normal file
|
@ -0,0 +1,23 @@
|
|||
[general.any.shadowrealm-in-shadowrealm.html]
|
||||
expected: ERROR
|
||||
|
||||
[general.any.shadowrealm-in-sharedworker.html]
|
||||
expected: ERROR
|
||||
|
||||
[general.https.any.shadowrealm-in-serviceworker.html]
|
||||
expected: ERROR
|
||||
|
||||
[general.any.sharedworker.html]
|
||||
expected: ERROR
|
||||
|
||||
[general.any.shadowrealm-in-dedicatedworker.html]
|
||||
expected: ERROR
|
||||
|
||||
[general.https.any.shadowrealm-in-audioworklet.html]
|
||||
expected: ERROR
|
||||
|
||||
[general.any.serviceworker.html]
|
||||
expected: ERROR
|
||||
|
||||
[general.any.shadowrealm-in-window.html]
|
||||
expected: ERROR
|
23
tests/wpt/meta/streams/readable-byte-streams/non-transferable-buffers.any.js.ini
vendored
Normal file
23
tests/wpt/meta/streams/readable-byte-streams/non-transferable-buffers.any.js.ini
vendored
Normal file
|
@ -0,0 +1,23 @@
|
|||
[non-transferable-buffers.any.shadowrealm-in-shadowrealm.html]
|
||||
expected: ERROR
|
||||
|
||||
[non-transferable-buffers.https.any.shadowrealm-in-audioworklet.html]
|
||||
expected: ERROR
|
||||
|
||||
[non-transferable-buffers.any.shadowrealm-in-dedicatedworker.html]
|
||||
expected: ERROR
|
||||
|
||||
[non-transferable-buffers.any.serviceworker.html]
|
||||
expected: ERROR
|
||||
|
||||
[non-transferable-buffers.https.any.shadowrealm-in-serviceworker.html]
|
||||
expected: ERROR
|
||||
|
||||
[non-transferable-buffers.any.shadowrealm-in-sharedworker.html]
|
||||
expected: ERROR
|
||||
|
||||
[non-transferable-buffers.any.sharedworker.html]
|
||||
expected: ERROR
|
||||
|
||||
[non-transferable-buffers.any.shadowrealm-in-window.html]
|
||||
expected: ERROR
|
23
tests/wpt/meta/streams/readable-byte-streams/patched-global.any.js.ini
vendored
Normal file
23
tests/wpt/meta/streams/readable-byte-streams/patched-global.any.js.ini
vendored
Normal file
|
@ -0,0 +1,23 @@
|
|||
[patched-global.any.shadowrealm-in-sharedworker.html]
|
||||
expected: ERROR
|
||||
|
||||
[patched-global.any.shadowrealm-in-dedicatedworker.html]
|
||||
expected: ERROR
|
||||
|
||||
[patched-global.any.sharedworker.html]
|
||||
expected: ERROR
|
||||
|
||||
[patched-global.any.shadowrealm-in-shadowrealm.html]
|
||||
expected: ERROR
|
||||
|
||||
[patched-global.any.shadowrealm-in-window.html]
|
||||
expected: ERROR
|
||||
|
||||
[patched-global.https.any.shadowrealm-in-serviceworker.html]
|
||||
expected: ERROR
|
||||
|
||||
[patched-global.any.serviceworker.html]
|
||||
expected: ERROR
|
||||
|
||||
[patched-global.https.any.shadowrealm-in-audioworklet.html]
|
||||
expected: ERROR
|
31
tests/wpt/meta/streams/readable-byte-streams/read-min.any.js.ini
vendored
Normal file
31
tests/wpt/meta/streams/readable-byte-streams/read-min.any.js.ini
vendored
Normal file
|
@ -0,0 +1,31 @@
|
|||
[read-min.https.any.shadowrealm-in-audioworklet.html]
|
||||
expected: ERROR
|
||||
|
||||
[read-min.any.sharedworker.html]
|
||||
expected: ERROR
|
||||
|
||||
[read-min.any.shadowrealm-in-shadowrealm.html]
|
||||
expected: ERROR
|
||||
|
||||
[read-min.any.shadowrealm-in-dedicatedworker.html]
|
||||
expected: ERROR
|
||||
|
||||
[read-min.any.serviceworker.html]
|
||||
expected: ERROR
|
||||
|
||||
[read-min.any.shadowrealm-in-window.html]
|
||||
expected: ERROR
|
||||
|
||||
[read-min.https.any.shadowrealm-in-serviceworker.html]
|
||||
expected: ERROR
|
||||
|
||||
[read-min.any.shadowrealm-in-sharedworker.html]
|
||||
expected: ERROR
|
||||
|
||||
[read-min.any.html]
|
||||
[ReadableStream with byte source: tee() with read({ min }) from branch1 and read() from branch2]
|
||||
expected: FAIL
|
||||
|
||||
[read-min.any.worker.html]
|
||||
[ReadableStream with byte source: tee() with read({ min }) from branch1 and read() from branch2]
|
||||
expected: FAIL
|
23
tests/wpt/meta/streams/readable-byte-streams/respond-after-enqueue.any.js.ini
vendored
Normal file
23
tests/wpt/meta/streams/readable-byte-streams/respond-after-enqueue.any.js.ini
vendored
Normal file
|
@ -0,0 +1,23 @@
|
|||
[respond-after-enqueue.https.any.shadowrealm-in-audioworklet.html]
|
||||
expected: ERROR
|
||||
|
||||
[respond-after-enqueue.any.shadowrealm-in-shadowrealm.html]
|
||||
expected: ERROR
|
||||
|
||||
[respond-after-enqueue.any.shadowrealm-in-sharedworker.html]
|
||||
expected: ERROR
|
||||
|
||||
[respond-after-enqueue.any.serviceworker.html]
|
||||
expected: ERROR
|
||||
|
||||
[respond-after-enqueue.any.sharedworker.html]
|
||||
expected: ERROR
|
||||
|
||||
[respond-after-enqueue.any.shadowrealm-in-dedicatedworker.html]
|
||||
expected: ERROR
|
||||
|
||||
[respond-after-enqueue.any.shadowrealm-in-window.html]
|
||||
expected: ERROR
|
||||
|
||||
[respond-after-enqueue.https.any.shadowrealm-in-serviceworker.html]
|
||||
expected: ERROR
|
255
tests/wpt/meta/streams/readable-byte-streams/tee.any.js.ini
vendored
Normal file
255
tests/wpt/meta/streams/readable-byte-streams/tee.any.js.ini
vendored
Normal file
|
@ -0,0 +1,255 @@
|
|||
[tee.any.shadowrealm-in-sharedworker.html]
|
||||
expected: ERROR
|
||||
|
||||
[tee.any.shadowrealm-in-window.html]
|
||||
expected: ERROR
|
||||
|
||||
[tee.any.worker.html]
|
||||
[ReadableStream teeing with byte source: rs.tee() returns an array of two ReadableStreams]
|
||||
expected: FAIL
|
||||
|
||||
[ReadableStream teeing with byte source: should be able to read one branch to the end without affecting the other]
|
||||
expected: FAIL
|
||||
|
||||
[ReadableStream teeing with byte source: chunks should be cloned for each branch]
|
||||
expected: FAIL
|
||||
|
||||
[ReadableStream teeing with byte source: chunks for BYOB requests from branch 1 should be cloned to branch 2]
|
||||
expected: FAIL
|
||||
|
||||
[ReadableStream teeing with byte source: errors in the source should propagate to both branches]
|
||||
expected: FAIL
|
||||
|
||||
[ReadableStream teeing with byte source: canceling branch1 should not impact branch2]
|
||||
expected: FAIL
|
||||
|
||||
[ReadableStream teeing with byte source: canceling branch2 should not impact branch1]
|
||||
expected: FAIL
|
||||
|
||||
[ReadableStream teeing with byte source: canceling both branches should aggregate the cancel reasons into an array]
|
||||
expected: FAIL
|
||||
|
||||
[ReadableStream teeing with byte source: canceling both branches in reverse order should aggregate the cancel reasons into an array]
|
||||
expected: FAIL
|
||||
|
||||
[ReadableStream teeing with byte source: failing to cancel the original stream should cause cancel() to reject on branches]
|
||||
expected: FAIL
|
||||
|
||||
[ReadableStream teeing with byte source: erroring a teed stream should properly handle canceled branches]
|
||||
expected: FAIL
|
||||
|
||||
[ReadableStream teeing with byte source: closing the original should close the branches]
|
||||
expected: FAIL
|
||||
|
||||
[ReadableStream teeing with byte source: erroring the original should immediately error the branches]
|
||||
expected: FAIL
|
||||
|
||||
[ReadableStream teeing with byte source: erroring the original should error pending reads from default reader]
|
||||
expected: FAIL
|
||||
|
||||
[ReadableStream teeing with byte source: erroring the original should error pending reads from BYOB reader]
|
||||
expected: FAIL
|
||||
|
||||
[ReadableStream teeing with byte source: canceling branch1 should finish when branch2 reads until end of stream]
|
||||
expected: FAIL
|
||||
|
||||
[ReadableStream teeing with byte source: canceling branch1 should finish when original stream errors]
|
||||
expected: FAIL
|
||||
|
||||
[ReadableStream teeing with byte source: should not pull any chunks if no branches are reading]
|
||||
expected: FAIL
|
||||
|
||||
[ReadableStream teeing with byte source: should only pull enough to fill the emptiest queue]
|
||||
expected: FAIL
|
||||
|
||||
[ReadableStream teeing with byte source: should not pull when original is already errored]
|
||||
expected: FAIL
|
||||
|
||||
[ReadableStream teeing with byte source: stops pulling when original stream errors while branch 1 is reading]
|
||||
expected: FAIL
|
||||
|
||||
[ReadableStream teeing with byte source: stops pulling when original stream errors while branch 2 is reading]
|
||||
expected: FAIL
|
||||
|
||||
[ReadableStream teeing with byte source: stops pulling when original stream errors while both branches are reading]
|
||||
expected: FAIL
|
||||
|
||||
[ReadableStream teeing with byte source: canceling both branches in sequence with delay]
|
||||
expected: FAIL
|
||||
|
||||
[ReadableStream teeing with byte source: failing to cancel when canceling both branches in sequence with delay]
|
||||
expected: FAIL
|
||||
|
||||
[ReadableStream teeing with byte source: read from branch1 and branch2, cancel branch1, cancel branch2]
|
||||
expected: FAIL
|
||||
|
||||
[ReadableStream teeing with byte source: read from branch1 and branch2, cancel branch2, cancel branch1]
|
||||
expected: FAIL
|
||||
|
||||
[ReadableStream teeing with byte source: read from branch1 and branch2, cancel branch2, enqueue to branch1]
|
||||
expected: FAIL
|
||||
|
||||
[ReadableStream teeing with byte source: read from branch1 and branch2, cancel branch1, respond to branch2]
|
||||
expected: FAIL
|
||||
|
||||
[ReadableStream teeing with byte source: pull with BYOB reader, then pull with default reader]
|
||||
expected: FAIL
|
||||
|
||||
[ReadableStream teeing with byte source: pull with default reader, then pull with BYOB reader]
|
||||
expected: FAIL
|
||||
|
||||
[ReadableStream teeing with byte source: read from branch2, then read from branch1]
|
||||
expected: FAIL
|
||||
|
||||
[ReadableStream teeing with byte source: read from branch1 with default reader, then close while branch2 has pending BYOB read]
|
||||
expected: FAIL
|
||||
|
||||
[ReadableStream teeing with byte source: read from branch2 with default reader, then close while branch1 has pending BYOB read]
|
||||
expected: FAIL
|
||||
|
||||
[ReadableStream teeing with byte source: close when both branches have pending BYOB reads]
|
||||
expected: FAIL
|
||||
|
||||
[ReadableStream teeing with byte source: enqueue() and close() while both branches are pulling]
|
||||
expected: FAIL
|
||||
|
||||
[ReadableStream teeing with byte source: respond() and close() while both branches are pulling]
|
||||
expected: FAIL
|
||||
|
||||
[ReadableStream teeing with byte source: reading an array with a byte offset should clone correctly]
|
||||
expected: FAIL
|
||||
|
||||
|
||||
[tee.any.sharedworker.html]
|
||||
expected: ERROR
|
||||
|
||||
[tee.any.shadowrealm-in-dedicatedworker.html]
|
||||
expected: ERROR
|
||||
|
||||
[tee.any.html]
|
||||
[ReadableStream teeing with byte source: rs.tee() returns an array of two ReadableStreams]
|
||||
expected: FAIL
|
||||
|
||||
[ReadableStream teeing with byte source: should be able to read one branch to the end without affecting the other]
|
||||
expected: FAIL
|
||||
|
||||
[ReadableStream teeing with byte source: chunks should be cloned for each branch]
|
||||
expected: FAIL
|
||||
|
||||
[ReadableStream teeing with byte source: chunks for BYOB requests from branch 1 should be cloned to branch 2]
|
||||
expected: FAIL
|
||||
|
||||
[ReadableStream teeing with byte source: errors in the source should propagate to both branches]
|
||||
expected: FAIL
|
||||
|
||||
[ReadableStream teeing with byte source: canceling branch1 should not impact branch2]
|
||||
expected: FAIL
|
||||
|
||||
[ReadableStream teeing with byte source: canceling branch2 should not impact branch1]
|
||||
expected: FAIL
|
||||
|
||||
[ReadableStream teeing with byte source: canceling both branches should aggregate the cancel reasons into an array]
|
||||
expected: FAIL
|
||||
|
||||
[ReadableStream teeing with byte source: canceling both branches in reverse order should aggregate the cancel reasons into an array]
|
||||
expected: FAIL
|
||||
|
||||
[ReadableStream teeing with byte source: failing to cancel the original stream should cause cancel() to reject on branches]
|
||||
expected: FAIL
|
||||
|
||||
[ReadableStream teeing with byte source: erroring a teed stream should properly handle canceled branches]
|
||||
expected: FAIL
|
||||
|
||||
[ReadableStream teeing with byte source: closing the original should close the branches]
|
||||
expected: FAIL
|
||||
|
||||
[ReadableStream teeing with byte source: erroring the original should immediately error the branches]
|
||||
expected: FAIL
|
||||
|
||||
[ReadableStream teeing with byte source: erroring the original should error pending reads from default reader]
|
||||
expected: FAIL
|
||||
|
||||
[ReadableStream teeing with byte source: erroring the original should error pending reads from BYOB reader]
|
||||
expected: FAIL
|
||||
|
||||
[ReadableStream teeing with byte source: canceling branch1 should finish when branch2 reads until end of stream]
|
||||
expected: FAIL
|
||||
|
||||
[ReadableStream teeing with byte source: canceling branch1 should finish when original stream errors]
|
||||
expected: FAIL
|
||||
|
||||
[ReadableStream teeing with byte source: should not pull any chunks if no branches are reading]
|
||||
expected: FAIL
|
||||
|
||||
[ReadableStream teeing with byte source: should only pull enough to fill the emptiest queue]
|
||||
expected: FAIL
|
||||
|
||||
[ReadableStream teeing with byte source: should not pull when original is already errored]
|
||||
expected: FAIL
|
||||
|
||||
[ReadableStream teeing with byte source: stops pulling when original stream errors while branch 1 is reading]
|
||||
expected: FAIL
|
||||
|
||||
[ReadableStream teeing with byte source: stops pulling when original stream errors while branch 2 is reading]
|
||||
expected: FAIL
|
||||
|
||||
[ReadableStream teeing with byte source: stops pulling when original stream errors while both branches are reading]
|
||||
expected: FAIL
|
||||
|
||||
[ReadableStream teeing with byte source: canceling both branches in sequence with delay]
|
||||
expected: FAIL
|
||||
|
||||
[ReadableStream teeing with byte source: failing to cancel when canceling both branches in sequence with delay]
|
||||
expected: FAIL
|
||||
|
||||
[ReadableStream teeing with byte source: read from branch1 and branch2, cancel branch1, cancel branch2]
|
||||
expected: FAIL
|
||||
|
||||
[ReadableStream teeing with byte source: read from branch1 and branch2, cancel branch2, cancel branch1]
|
||||
expected: FAIL
|
||||
|
||||
[ReadableStream teeing with byte source: read from branch1 and branch2, cancel branch2, enqueue to branch1]
|
||||
expected: FAIL
|
||||
|
||||
[ReadableStream teeing with byte source: read from branch1 and branch2, cancel branch1, respond to branch2]
|
||||
expected: FAIL
|
||||
|
||||
[ReadableStream teeing with byte source: pull with BYOB reader, then pull with default reader]
|
||||
expected: FAIL
|
||||
|
||||
[ReadableStream teeing with byte source: pull with default reader, then pull with BYOB reader]
|
||||
expected: FAIL
|
||||
|
||||
[ReadableStream teeing with byte source: read from branch2, then read from branch1]
|
||||
expected: FAIL
|
||||
|
||||
[ReadableStream teeing with byte source: read from branch1 with default reader, then close while branch2 has pending BYOB read]
|
||||
expected: FAIL
|
||||
|
||||
[ReadableStream teeing with byte source: read from branch2 with default reader, then close while branch1 has pending BYOB read]
|
||||
expected: FAIL
|
||||
|
||||
[ReadableStream teeing with byte source: close when both branches have pending BYOB reads]
|
||||
expected: FAIL
|
||||
|
||||
[ReadableStream teeing with byte source: enqueue() and close() while both branches are pulling]
|
||||
expected: FAIL
|
||||
|
||||
[ReadableStream teeing with byte source: respond() and close() while both branches are pulling]
|
||||
expected: FAIL
|
||||
|
||||
[ReadableStream teeing with byte source: reading an array with a byte offset should clone correctly]
|
||||
expected: FAIL
|
||||
|
||||
|
||||
[tee.any.serviceworker.html]
|
||||
expected: ERROR
|
||||
|
||||
[tee.https.any.shadowrealm-in-serviceworker.html]
|
||||
expected: ERROR
|
||||
|
||||
[tee.https.any.shadowrealm-in-audioworklet.html]
|
||||
expected: ERROR
|
||||
|
||||
[tee.any.shadowrealm-in-shadowrealm.html]
|
||||
expected: ERROR
|
32
tests/wpt/meta/streams/readable-byte-streams/templated.any.js.ini
vendored
Normal file
32
tests/wpt/meta/streams/readable-byte-streams/templated.any.js.ini
vendored
Normal file
|
@ -0,0 +1,32 @@
|
|||
[templated.https.any.shadowrealm-in-audioworklet.html]
|
||||
expected: ERROR
|
||||
|
||||
[templated.any.shadowrealm-in-dedicatedworker.html]
|
||||
expected: ERROR
|
||||
|
||||
[templated.any.sharedworker.html]
|
||||
expected: ERROR
|
||||
|
||||
[templated.any.serviceworker.html]
|
||||
expected: ERROR
|
||||
|
||||
[templated.https.any.shadowrealm-in-serviceworker.html]
|
||||
expected: ERROR
|
||||
|
||||
[templated.any.shadowrealm-in-window.html]
|
||||
expected: ERROR
|
||||
|
||||
[templated.any.shadowrealm-in-shadowrealm.html]
|
||||
expected: ERROR
|
||||
|
||||
[templated.any.shadowrealm-in-sharedworker.html]
|
||||
expected: ERROR
|
||||
|
||||
[templated.any.worker.html]
|
||||
[ReadableStream with byte source (empty): instances have the correct methods and properties]
|
||||
expected: FAIL
|
||||
|
||||
|
||||
[templated.any.html]
|
||||
[ReadableStream with byte source (empty): instances have the correct methods and properties]
|
||||
expected: FAIL
|
Loading…
Add table
Add a link
Reference in a new issue