From 20d9f165cb42a79f5a0b4fba2c1c7439ff661209 Mon Sep 17 00:00:00 2001 From: Anne van Kesteren Date: Mon, 15 Feb 2021 07:38:08 +0100 Subject: [PATCH] Editorial: adopt Fetch's new approach to callbacks See https://github.com/whatwg/fetch/pull/1165 for context. --- xhr.bs | 91 ++++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 56 insertions(+), 35 deletions(-) diff --git a/xhr.bs b/xhr.bs index dc6d6db..2fed42e 100644 --- a/xhr.bs +++ b/xhr.bs @@ -756,8 +756,6 @@ return this's cross-origin credentials.
This's request body.
client
This's relevant settings object. -
synchronous flag -
Set if this's synchronous flag is set.
mode
"cors".
use-CORS-preflight flag @@ -794,27 +792,10 @@ return this's cross-origin credentials. send() flag is unset, then return.
  • -

    Fetch req. - Handle the tasks - queued on the - networking task source per below. - -

    Run these steps in parallel: +

    Let processRequestBody, given a request, be these steps:

      -
    1. Wait until either req's done flag is set or this's - timeout is not 0 and this's timeout milliseconds have passed since these - steps started. - -

    2. If req's done flag is unset, then set this's - timed out flag and terminate fetching. -

    - -

    To process request body for request, run these steps: - -

      -
    1. If not roughly 50ms have passed since these steps were last invoked, - terminate these steps. +

    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 @@ -825,12 +806,13 @@ return this's cross-origin credentials.

      These steps are only invoked when new bytes are transmitted. -

      To process request end-of-body for request, run these steps: +

    4. +

      Let processRequestEndOfBody, given a request, be these steps:

      1. Set this's upload complete flag. -

      2. If this's upload listener flag is unset, then terminate these steps. +

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

      4. Let transmitted be request's body's @@ -851,12 +833,14 @@ return this's cross-origin credentials.

      -

      To process response for response, run these steps: +

    5. +

      Let processResponse, given a response, be these steps:

      1. Set this's response to response. -

      2. Handle errors fo this and response. +

      3. Handle errors for this and this's + response.

      4. If this's response is a network error, then return. @@ -876,7 +860,7 @@ return this's cross-origin credentials. this's response's body's stream. -

        This operation will not throw an exception. +

        This operation will not throw an exception.

      5. Let readRequest be the following read request: @@ -887,8 +871,7 @@ return this's cross-origin credentials.

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

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

        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. @@ -920,6 +903,26 @@ return this's cross-origin credentials.

        5. Read a chunk from reader given readRequest.

        + +
      6. Fetch req with processRequestBody set to + processRequestBody, processRequestEndOfBody set to + processRequestEndOfBody, and processResponse set to + processResponse. + +

      7. Let now be the present time. + + +

      8. +

        Run these steps in parallel: + +

          +
        1. Wait until either req's done flag is set or this's + timeout is not 0 and this's timeout milliseconds have passed since + now. + +

        2. If req's done flag is unset, then set this's + timed out flag and terminate fetching. +

    6. @@ -930,13 +933,31 @@ return this's cross-origin credentials. is not allowed to use the "sync-xhr" feature, then run handle response end-of-body for this and a network error, and then return. +
    7. Let response be a network error. + +

    8. Let processedResponse be false. +

    9. -

      Let response be the result of - fetching req. +

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

        +
      1. Set response to fetchResponse. + +

      2. Set processedResponse to true. +

      + +
    10. Fetch req with processResponse + set to processResponse and useParallelQueue set to true. + +

    11. Let now be the present time. + + +

    12. Pause until either processedResponse is true or this's + timeout is not 0 and this's timeout milliseconds have passed since + now. -

      If this's timeout is not 0, then set this's timed out flag and - terminate fetching if it has not returned within this's - timeout milliseconds. +

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

    14. If response's body is null, then run handle response end-of-body for this and response, and then return. @@ -945,12 +966,12 @@ return this's cross-origin credentials.

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

      This operation will not throw an exception. +

      This operation will not throw an exception.

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

    16. Wait for promise to be fulfilled or rejected. +

    17. Pause until promise is fulfilled or rejected.

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