New issue
Advanced search Search tips

Issue 801227 link

Starred by 1 user

Issue metadata

Status: WontFix
Owner:
Closed: Jan 2018
Components:
EstimatedDays: ----
NextAction: ----
OS: Linux
Pri: 3
Type: Compat



Sign in to add a comment

Can't wrap a ReadableStream

Project Member Reported by rsk@google.com, Jan 11 2018

Issue description

UserAgent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36

Steps to reproduce the problem:
1. Get/create a ReadableStream>

  /**
   * Creates a ReadableStream that delivers a simple stream of data:
   *   <start><pull 1><pull 2>...<pull ${pullIters}>
   */
  function newReadableStream(pullIters) {
    const encoder = new TextEncoder();
    let iter = 0;

    return new ReadableStream({
      start(controller) {
        controller.enqueue(encoder.encode('<start>'));
      },

      pull(controller) {
        if (iter < pullIters) {
          controller.enqueue(encoder.encode(`<pull ${++iter}>`));
        } else {
          controller.close();
        }
      },
    });
  }

2. Confirm that it works with Response:

  async test_direct() {
    const stream = newReadableStream(3);
    const response = new Response(stream);
    const text = await response.text();
    assertEquals('<start><pull 1><pull 2><pull 3>', text);
  }

3. Create a class that wraps a ReadableStream:

  class ReadableStreamWrapper {
    constructor(stream) {
      this.stream_ = stream;
    }

    get locked() {
      return this.stream_.locked;
    }

    cancel(...args) {
      return this.stream.cancel(...args);
    }

    getReader(...args) {
      return this.stream.getReader(...args);
    }

    pipeThrough(...args) {
      return this.stream.pipeThrough(...args);
    }

    pipeTo(...args) {
      return this.stream.pipeTo(...args);
    }

    tee(...args) {
      return this.stream.tee(...args);
    }
  }

4. Try the test again again with the wrapper:

  async test_direct() {
    const stream = new ReadableStreamWrapper(newReadableStream(3));
    const response = new Response(stream);
    const text = await response.text();
    assertEquals('<start><pull 1><pull 2><pull 3>', text);
  }

What is the expected behavior?
In step 4, I expect to get the text of the underlying ReadableStream.

What went wrong?
In step 4, response.text() resolves to "[object Object]" instead of correct text.

Did this work before? N/A 

Chrome version: 63.0.3239.132  Channel: stable
OS Version: Linux 4.9.0-5-amd64 #1 SMP Debian 4.9.65-3+deb9u2 (2018-01-04) x86_64 GNU/Linu
Flash Version:
 

Comment 1 by tkent@chromium.org, Jan 12 2018

Components: -Blink Blink>Network

Comment 2 by ricea@chromium.org, Jan 12 2018

Labels: -Type-Bug -Pri-2 Pri-3 Type-Compat
Owner: yhirano@chromium.org
Status: Assigned (was: Unconfirmed)
That's not expected to work. The body has to be an actual ReadableStream, not a wrapper.

I don't know off the top of my head whether stringifying to "[object Object]" is the expected behaviour according to the standard. Sending to yhirano@ to verify that point. If "[object Object]" is the expected output then there's nothing else to do here.
Status: WontFix (was: Assigned)
Yes it's working as expected. BodyInit is defined as follows:

typedef (Blob or BufferSource or FormData or URLSearchParams or ReadableStream or USVString) BodyInit;

So, if the value is none of Blob, BufferSource, FormData, URLSearchParams and ReadableStream, it should be converted to a string using ToString.

Sign in to add a comment