undefined enqueue(ArrayBufferView chunk);
(
this: This<OwnedBorrowMut<'js, Self>>,
ctx: Ctx<'js>,
chunk: Value<'js>,
)
| 1631 | |
| 1632 | // undefined enqueue(ArrayBufferView chunk); |
| 1633 | fn enqueue( |
| 1634 | this: This<OwnedBorrowMut<'js, Self>>, |
| 1635 | ctx: Ctx<'js>, |
| 1636 | chunk: Value<'js>, |
| 1637 | ) -> Result<()> { |
| 1638 | let chunk = ViewBytes::from_value(&ctx, &this.function_array_buffer_is_view, Some(&chunk))?; |
| 1639 | |
| 1640 | let (array_buffer, byte_length, _) = chunk.get_array_buffer()?; |
| 1641 | |
| 1642 | // If chunk.[[ByteLength]] is 0, throw a TypeError exception. |
| 1643 | if byte_length == 0 { |
| 1644 | return Err(Exception::throw_type( |
| 1645 | &ctx, |
| 1646 | "chunk must have non-zero byteLength", |
| 1647 | )); |
| 1648 | } |
| 1649 | |
| 1650 | // If chunk.[[ViewedArrayBuffer]].[[ArrayBufferByteLength]] is 0, throw a TypeError exception. |
| 1651 | if array_buffer.is_empty() { |
| 1652 | return Err(Exception::throw_type( |
| 1653 | &ctx, |
| 1654 | "chunk must have non-zero buffer byteLength", |
| 1655 | )); |
| 1656 | } |
| 1657 | |
| 1658 | // If this.[[closeRequested]] is true, throw a TypeError exception. |
| 1659 | if this.close_requested { |
| 1660 | return Err(Exception::throw_type(&ctx, "stream is closed or draining")); |
| 1661 | } |
| 1662 | |
| 1663 | let objects = ReadableStreamObjects::from_byte_controller(this.0).refresh_reader(); |
| 1664 | |
| 1665 | // If this.[[stream]].[[state]] is not "readable", throw a TypeError exception. |
| 1666 | if !matches!(objects.stream.state, ReadableStreamState::Readable) { |
| 1667 | return Err(Exception::throw_type( |
| 1668 | &ctx, |
| 1669 | "The stream is not in the readable state and cannot be enqueued to", |
| 1670 | )); |
| 1671 | }; |
| 1672 | |
| 1673 | // Return ? ReadableByteStreamControllerEnqueue(this, chunk). |
| 1674 | Self::readable_byte_stream_controller_enqueue(&ctx, objects, chunk)?; |
| 1675 | Ok(()) |
| 1676 | } |
| 1677 | |
| 1678 | // undefined error(optional any e); |
| 1679 | fn error( |
nothing calls this directly
no test coverage detected