undefined enqueue(optional any chunk, optional ReadableStreamEnqueueOptions options = {});
(
ctx: Ctx<'js>,
controller: This<OwnedBorrowMut<'js, Self>>,
chunk: Opt<Value<'js>>,
options: Opt<Value<'js>>,
)
| 654 | |
| 655 | // undefined enqueue(optional any chunk, optional ReadableStreamEnqueueOptions options = {}); |
| 656 | fn enqueue( |
| 657 | ctx: Ctx<'js>, |
| 658 | controller: This<OwnedBorrowMut<'js, Self>>, |
| 659 | chunk: Opt<Value<'js>>, |
| 660 | options: Opt<Value<'js>>, |
| 661 | ) -> Result<()> { |
| 662 | // Handle the `transfer` option per the `type: 'owning'` ReadableStream |
| 663 | // proposal (WPT `streams/readable-streams/owning-type`). The option |
| 664 | // is only meaningful on owning-type streams; any other stream throws |
| 665 | // `TypeError` if the caller passes a non-empty transfer list. |
| 666 | // |
| 667 | // WebIDL getter semantics apply: property access must propagate. |
| 668 | let mut transfer_list: Option<rquickjs::Array<'js>> = None; |
| 669 | if let Some(opts) = options.0.as_ref().and_then(|v| v.as_object()) { |
| 670 | transfer_list = opts.get::<_, Option<rquickjs::Array<'js>>>("transfer")?; |
| 671 | } |
| 672 | let has_transfer_items = transfer_list.as_ref().is_some_and(|arr| !arr.is_empty()); |
| 673 | if has_transfer_items && !controller.is_owning_type { |
| 674 | return Err(Exception::throw_type(&ctx, "transfer list is not empty")); |
| 675 | } |
| 676 | // Detach each buffer in the transfer list (owning-type streams). Uses |
| 677 | // JS `ArrayBuffer.prototype.transfer()` which returns a new buffer |
| 678 | // with the same bytes and detaches the original. We re-bind the |
| 679 | // chunk to the new buffer if it was the same reference. |
| 680 | let chunk_value = chunk.0.clone().unwrap_or_undefined(&ctx); |
| 681 | let transferred_chunk = if has_transfer_items && controller.is_owning_type { |
| 682 | transfer_owning_chunk(&ctx, chunk_value.clone(), &transfer_list.unwrap())? |
| 683 | } else { |
| 684 | chunk_value |
| 685 | }; |
| 686 | |
| 687 | let objects = ReadableStreamObjects::from_default_controller(controller.0); |
| 688 | |
| 689 | // If ! ReadableStreamDefaultControllerCanCloseOrEnqueue(this) is false, throw a TypeError exception. |
| 690 | if !objects |
| 691 | .controller |
| 692 | .readable_stream_default_controller_can_close_or_enqueue(&objects.stream) |
| 693 | { |
| 694 | return Err(Exception::throw_type( |
| 695 | &ctx, |
| 696 | "The stream is not in a state that permits enqueue", |
| 697 | )); |
| 698 | } |
| 699 | |
| 700 | objects.with_reader( |
| 701 | |objects| { |
| 702 | // Perform ? ReadableStreamDefaultControllerEnqueue(this, chunk). |
| 703 | Self::readable_stream_default_controller_enqueue( |
| 704 | ctx.clone(), |
| 705 | objects, |
| 706 | transferred_chunk.clone(), |
| 707 | ) |
| 708 | }, |
| 709 | |_| panic!("Default controller must not have byob reader"), |
| 710 | |objects| { |
| 711 | // Perform ? ReadableStreamDefaultControllerEnqueue(this, chunk). |
| 712 | Self::readable_stream_default_controller_enqueue( |
| 713 | ctx.clone(), |
nothing calls this directly
no test coverage detected