Skip to content

ReadableStreamBYOBReader read() throws when given DataViewΒ #40612

@mrbbot

Description

@mrbbot

Version

v17.0.1

Platform

Darwin MrBBots-MBP 19.6.0 Darwin Kernel Version 19.6.0: Thu May 6 00:48:39 PDT 2021; root:xnu-6153.141.33~1/RELEASE_X86_64 x86_64

Subsystem

stream

What steps will reproduce the bug?

Running node byob.mjs with:

// byob.mjs

import { ReadableStream } from "stream/web";

const stream = new ReadableStream({
  type: "bytes",
  start(controller) {
    controller.enqueue(new Uint8Array([1, 2, 3]));
    controller.close();
  },
});

const buffer = new ArrayBuffer(1024);
const reader = stream.getReader({ mode: "byob" });
const result = await reader.read(new DataView(buffer));
console.log(result);

...throws the following:

node:internal/webstreams/readablestream:1492
  return new ctor(transferredBuffer, byteOffset, bytesFilled / elementSize);
         ^

TypeError: ctor is not a constructor
    at readableByteStreamControllerConvertPullIntoDescriptor (node:internal/webstreams/readablestream:1492:10)
    at readableByteStreamControllerPullInto (node:internal/webstreams/readablestream:2145:9)
    at readableStreamBYOBReaderRead (node:internal/webstreams/readablestream:1717:3)
    at ReadableStreamBYOBReader.read (node:internal/webstreams/readablestream:881:5)
    at file:///.../byob.mjs:15:29
    at ModuleJob.run (node:internal/modules/esm/module_job:185:25)
    at async Promise.all (index 0)
    at async ESMLoader.import (node:internal/modules/esm/loader:281:24)
    at async loadESM (node:internal/process/esm_loader:88:5)
    at async handleMainPromise (node:internal/modules/run_main:65:12)

Replacing new DataView with new Uint8Array returns the expected output:

{ value: Uint8Array(3) [ 1, 2, 3 ], done: false }

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

No required condition, throws every time

What is the expected behavior?

Running the code in the latest Chrome (without the import) produces the following expected output:

{ value: DataView(3), done: false }

What do you see instead?

See the stack trace above

Additional information

No response

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