MCPcopy Create free account
hub / github.com/awslabs/llrt / enqueue

Method enqueue

modules/llrt_stream_web/src/readable/byte_controller.rs:1705–1748  ·  view source on GitHub ↗

undefined enqueue(ArrayBufferView chunk);

(
        this: This<OwnedBorrowMut<'js, Self>>,
        ctx: Ctx<'js>,
        chunk: Value<'js>,
    )

Source from the content-addressed store, hash-verified

1703
1704 // undefined enqueue(ArrayBufferView chunk);
1705 fn enqueue(
1706 this: This<OwnedBorrowMut<'js, Self>>,
1707 ctx: Ctx<'js>,
1708 chunk: Value<'js>,
1709 ) -> Result<()> {
1710 let chunk = ViewBytes::from_value(&ctx, &this.function_array_buffer_is_view, Some(&chunk))?;
1711
1712 let (array_buffer, byte_length, _) = chunk.get_array_buffer()?;
1713
1714 // If chunk.[[ByteLength]] is 0, throw a TypeError exception.
1715 if byte_length == 0 {
1716 return Err(Exception::throw_type(
1717 &ctx,
1718 "chunk must have non-zero byteLength",
1719 ));
1720 }
1721
1722 // If chunk.[[ViewedArrayBuffer]].[[ArrayBufferByteLength]] is 0, throw a TypeError exception.
1723 if array_buffer.is_empty() {
1724 return Err(Exception::throw_type(
1725 &ctx,
1726 "chunk must have non-zero buffer byteLength",
1727 ));
1728 }
1729
1730 // If this.[[closeRequested]] is true, throw a TypeError exception.
1731 if this.close_requested {
1732 return Err(Exception::throw_type(&ctx, "stream is closed or draining"));
1733 }
1734
1735 let objects = ReadableStreamObjects::from_byte_controller(this.0).refresh_reader();
1736
1737 // If this.[[stream]].[[state]] is not "readable", throw a TypeError exception.
1738 if !matches!(objects.stream.state, ReadableStreamState::Readable) {
1739 return Err(Exception::throw_type(
1740 &ctx,
1741 "The stream is not in the readable state and cannot be enqueued to",
1742 ));
1743 };
1744
1745 // Return ? ReadableByteStreamControllerEnqueue(this, chunk).
1746 Self::readable_byte_stream_controller_enqueue(&ctx, objects, chunk)?;
1747 Ok(())
1748 }
1749
1750 // undefined error(optional any e);
1751 fn error(

Callers

nothing calls this directly

Calls 3

refresh_readerMethod · 0.80
get_array_bufferMethod · 0.45
is_emptyMethod · 0.45

Tested by

no test coverage detected