diff --git a/xhr.bs b/xhr.bs index 0849986..4f7cdd7 100644 --- a/xhr.bs +++ b/xhr.bs @@ -791,45 +791,45 @@ return this's cross-origin credentials.
  • If this's state is not opened or this's send() flag is unset, then return. +

  • Let uploadedBytesLength be 0. +

  • -

    Let processRequestBody, given a request, be these steps: +

    Let processRequestBody, given a bytesLength, be these steps:

      +
    1. Increase uploadedBytesLength by bytesLength. +

    2. If not roughly 50ms have passed since these steps were last invoked, then return.

    3. If this's upload listener flag is set, then fire a progress event named progress at this's upload object with - request's body's transmitted bytes and - request's body's total bytes. + uploadedBytesLength and req's body's + total bytes.

    These steps are only invoked when new bytes are transmitted.

  • -

    Let processRequestEndOfBody, given a request, be these steps: +

    Let processRequestEndOfBody be these steps:

    1. Set this's upload complete flag.

    2. If this's upload listener flag is unset, then return. -

    3. Let transmitted be request's - body's - transmitted bytes. - -

    4. Let length be request's +

    5. Let length be req's body's total bytes.

    6. Fire a progress event named progress at this's - upload object with transmitted and length. + upload object with uploadedBytesLength and length.

    7. Fire a progress event named load at this's - upload object with transmitted and length. + upload object with uploadedBytesLength and length.

    8. Fire a progress event named loadend at this's - upload object with transmitted and length. + upload object with uploadedBytesLength and length.

    @@ -856,52 +856,37 @@ return this's cross-origin credentials. response, and then return.
  • -

    Let reader be the result of getting a reader for - this's response's body's - stream. - -

    This operation will not throw an exception. +

    Let processBodyChunk given bytes be these steps: -

  • -

    Let readRequest be the following read request: - -

    -
    chunk steps, given chunk -
    -
      -
    1. Append chunk to this's received bytes. +

        +
      1. Append bytes to this's received bytes. -

      2. If not roughly 50ms have passed since these steps were last invoked, then return. +

      3. If not roughly 50ms have passed since these steps were last invoked, then return. -

      4. If this's state is headers received, then set this's - state to loading. +

      5. If this's state is headers received, then set this's + state to loading. -

      6. -

        Fire an event named readystatechange at this. +

      7. +

        Fire an event named readystatechange at this. -

        Web compatibility is the reason - readystatechange fires more often than this's - state changes. +

        Web compatibility is the reason readystatechange + fires more often than this's state changes. -

      8. Fire a progress event named progress at this - with this's response's body's - transmitted bytes and this's response's - body's total bytes. -

      +
    2. Fire a progress event named progress at this + with this's received bytes's length and + this's response's body's + total bytes. +

    -
    close steps -
    -
    1. Run handle response end-of-body for this and this's - response.

    +
  • Let processEndOfBody be this step: run handle response end-of-body for + this and this's response. -

    error steps -
    -
    1. Run handle errors for this and this's - response.

    -
  • +
  • Let processBodyError be this step: run handle errors for this + and this's response. -

  • Read a chunk from reader given - readRequest. +

  • Incrementally read this's response's + body, given processBodyChunk, processEndOfBody, + processBodyError, and this's relevant global object.

  • Fetch req with processRequestBody set to @@ -938,16 +923,21 @@ return this's cross-origin credentials.

  • Let processedResponse be false.

  • -

    Let processResponse, given a fetchResponse, be these steps: +

    Let processResponseEndOfBody, given a fetchResponse and + nullOrFailureOrBytes, be these steps:

    1. Set response to fetchResponse. +

    2. If nullOrFailureOrBytes is a byte sequence, then append + nullOrFailureOrBytes to this's received bytes. +

    3. Set processedResponse to true.

    -
  • Fetch req with processResponse - set to processResponse and useParallelQueue set to true. +

  • Fetch req with processResponseEndOfBody + set to processResponseEndOfBody and useParallelQueue set to + true.

  • Let now be the present time. @@ -959,23 +949,6 @@ return this's cross-origin credentials.

  • If processedResponse is false, then set this's timed out flag and terminate fetching. -

  • If response's body is null, then run - handle response end-of-body for this and response, and then return. - -

  • -

    Let reader be the result of getting a reader for - response's body's stream. - -

    This operation will not throw an exception. - -

  • Let promise be the result of - reading all bytes from reader. - -

  • Pause until promise is fulfilled or rejected. - -

  • If promise is fulfilled with bytes, then append bytes - to this's received bytes. -

  • Run handle response end-of-body for this and response. @@ -996,8 +969,8 @@ steps:

  • If xhr's synchronous flag is unset, then update xhr's response's body using response. -

  • Let transmitted be response's body's - transmitted bytes. +

  • Let transmitted be xhr's received bytes's + length.

  • Let length be response's body's total bytes.