Skip to content

ReadableStreamDefaultReader.read accesses Object.prototype.then #46786

Open
@KhafraDev

Description

@KhafraDev

Version

v19.7.0

Platform

Microsoft Windows NT 10.0.19045.0 x64

Subsystem

web streams

What steps will reproduce the bug?

const hello = new TextEncoder().encode('hello')

const rs = new ReadableStream({
  start(controller) {
    controller.enqueue(hello);
    controller.close();
  }
})

const reader = rs.getReader()

Object.defineProperty(Object.prototype, 'then', {
  get () {
    throw new Error()
  }
})

while (true) {
  const { done } = await reader.read()

  if (done) break
}

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

No response

What is the expected behavior?

No error thrown

What do you see instead?

file:///undici/test.mjs:14
    throw new Error()
          ^

Error
    at Object.get (file:///undici/test.mjs:14:11)
    at Object.resolve (<anonymous>)
    at [kChunk] (node:internal/webstreams/readablestream:771:27)
    at readableStreamDefaultControllerPullSteps (node:internal/webstreams/readablestream:2304:24)
    at [kPull] (node:internal/webstreams/readablestream:1052:5)
    at readableStreamDefaultReaderRead (node:internal/webstreams/readablestream:2138:39)
    at ReadableStreamDefaultReader.read (node:internal/webstreams/readablestream:841:5)
    at file:///undici/test.mjs:19:33
    at ModuleJob.run (node:internal/modules/esm/module_job:193:25)

Additional information

This is a WPT that I discovered working on fetch, https://github.com/web-platform-tests/wpt/blob/master/fetch/api/response/response-stream-with-broken-then.any.js

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions