Skip to content

WebStreams "respondWithNewView" incorrectly errors when using autoAllocateChunkSize #41886

@sbquinlan

Description

@sbquinlan

Version

v16.13.2

Platform

Darwin Seans-MacBook-Pro.local 21.2.0 Darwin Kernel Version 21.2.0: Sun Nov 28 20:28:41 PST 2021; root:xnu-8019.61.5~1/RELEASE_ARM64_T6000 arm64

Subsystem

No response

What steps will reproduce the bug?

const stream = new ReadableStream({
  pull: c => {
    const v = new Uint8Array(c.byobRequest.view.buffer, 0, 3);
    v.set([20, 21, 22]);
    c.byobRequest.respondWithNewView(v);
  },
  autoAllocateChunkSize: 10,
  type: 'bytes'
});

const reader = stream.getReader();
const view = reader.read();

How often does it reproduce? Is there a required condition?

Reproduces everytime, it is dependent on using the autoAllocateChunkSize and NOT using a BYOB reader on the stream.

What is the expected behavior?

I expect no error. By the spec (https://streams.spec.whatwg.org/#rs-byob-request-prototype) it should allowed respond with a new view as long as the underlying buffer is the same as the original view. I don't see a mention of this method being specifically only for BYOB readers and not autoAllocated buffers.

Not that this works without error on Chrome (only browser that currently supports byte streams): https://jsfiddle.net/w1jb7rq2/1/

What do you see instead?

RangeError [ERR_INVALID_ARG_VALUE]: The argument 'view' is invalid. Received Uint8Array(3) [ 20, 21, 22 ]
    at new NodeError (node:internal/errors:371:5)
    at readableByteStreamControllerRespondWithNewView (node:internal/webstreams/readablestream:2523:11)
    at ReadableStreamBYOBRequest.respondWithNewView (node:internal/webstreams/readablestream:682:5)
    at Object.pull (/Users/squinlan/Documents/node/test/parallel/test-whatwg-readablebytestream.js:243:21)
    at ensureIsPromise (node:internal/webstreams/util:172:19)
    at readableByteStreamControllerCallPullIfNeeded (node:internal/webstreams/readablestream:2545:5)
    at node:internal/webstreams/readablestream:2662:7 {
  code: 'ERR_INVALID_ARG_VALUE'
}

Additional information

This is due to readableByteStreamControllerPullSteps missing bufferByteLength in the desc added to pendingPullIntos

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions