From 1bda54532c11b51963796ad77f783e5d8e136ea8 Mon Sep 17 00:00:00 2001 From: Anne van Kesteren Date: Tue, 28 Aug 2018 07:59:24 +0200 Subject: [PATCH] Make extract throw for a disturbed/locked ReadableStream This also introduces "safely extract" which mainly serves to make it explicit which extraction operations cannot throw. Tests: https://github.com/web-platform-tests/wpt/pull/12639. Fixes #792. --- fetch.bs | 61 +++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 38 insertions(+), 23 deletions(-) diff --git a/fetch.bs b/fetch.bs index c2e0ccf8e..8c96991b3 100644 --- a/fetch.bs +++ b/fetch.bs @@ -3585,12 +3585,11 @@ optional CORS flag and CORS-preflight flag, run these steps:
  • If request's body is non-null, then set request's - body to the first part of extracting + body to the first return value of safely extracting request's body's source.

    request's body's source's - nullity has already been checked. The extracting operation cannot - throw as it was called for the same source before. + nullity has already been checked.

  • Append actualResponse's location URL to request's URL list. @@ -4008,13 +4007,9 @@ Range Requests. [[HTTP-RANGE]] However, this is not widely supported by b

  • If request's body's source is null, then return a network error. -

  • -

    Set request's body to the first part of - extracting request's body's - source. - -

    The extracting operation cannot - throw as it was called for the same source before. +

  • Set request's body to the first return value of + safely extracting request's body's + source.

  • @@ -4952,6 +4947,24 @@ method, when invoked, must run these steps:
     typedef (Blob or BufferSource or FormData or URLSearchParams or ReadableStream or USVString) BodyInit;
    +

    To safely extract a body and a +`Content-Type` value from object, run these steps: + +

      +
    1. +

      If object is a {{ReadableStream}} object, then: + +

        +
      1. Assert: object is neither disturbed nor + locked. +

      + +
    2. Return the results of extracting object. +

    + +

    The safely extract operation is a subset of the +extract operation that is guaranteed to not throw an exception. +

    To extract a body and a `Content-Type` value from object, with an optional keepalive flag, run these steps: @@ -5026,15 +5039,18 @@ typedef (Blob or BufferSource or FormData or URLSearchParams or ReadableStream o

    Set source to object.

    {{ReadableStream}} -

    Set stream to object. - +

    +

    If the keepalive flag is set, then throw a {{TypeError}}. + +

    If object is disturbed or + locked, then throw a {{TypeError}}. -

  • If keepalive flag is set and object's type is a {{ReadableStream}} - object, then throw a {{TypeError}}. +

    Set stream to object. +

  • -

    If action is non-null, run action in - parallel: +

    If action is non-null, run action in parallel: +

    1. Whenever one or more bytes are available, let bytes be the bytes and enqueue a Uint8Array object @@ -5722,11 +5738,11 @@ constructor must run these steps:

    2. Let Content-Type be null.

    3. If init["{{RequestInit/keepalive}}"] exists and is true, then - set body and Content-Type to the result of extracting + set body and Content-Type to the result of extracting init["{{RequestInit/body}}"], with the keepalive flag set.

    4. Otherwise, set body and Content-Type to the result of - extracting init["{{RequestInit/body}}"]. + extracting init["{{RequestInit/body}}"].

    5. If Content-Type is non-null and r's headers's header list does not contain @@ -5751,7 +5767,7 @@ constructor must run these steps:

    6. -

      If inputBody is non-null and inputBody is body, then: +

      If inputBody is body and inputBody is non-null, then:

      1. @@ -5761,7 +5777,7 @@ constructor must run these steps:

        This will be specified more precisely once transform stream and piping are precisely defined. - See the issue. + See issue #463.

        This makes inputBody's stream locked and disturbed immediately. @@ -5956,9 +5972,8 @@ constructor, when invoked, must run these steps:

      2. Let Content-Type be null. -

      3. Set r's response's - body and Content-Type to the result of - extracting body. +

      4. Set r's response's body and + Content-Type to the result of extracting body.

      5. If Content-Type is non-null and r's response's header list does not contain