diff --git a/source b/source index 736eb813282..cbb74d3480b 100644 --- a/source +++ b/source @@ -92911,43 +92911,53 @@ document.querySelector("button").addEventListener("click", bound);
-

The algorithms below can be customized by optionally supplying a custom perform the fetch - hook, which takes a request, an is top-level flag, and a processCustomFetchResponse - algorithm. The perform the fetch algorithm - must run processCustomFetchResponse with a - response (which may be a network - error), either synchronously (when using fetch a classic worker-imported - script) or asynchronously (otherwise). The is - top-level flag will be set for all classic script fetches, and for the initial - fetch when fetching an external module script - graph, fetching a module worker script - graph, or fetching an import() module - script graph, but not for the fetches resulting from import - statements encountered throughout the graph.

+

Several of the below algorithms can be customized with a perform the fetch + hook algorithm, in one of the following forms:

-
-

By default, not supplying the perform the - fetch will cause the below algorithms to simply fetch - the given request, with algorithm-specific customizations - to the request and validations of the resulting response.

- -

To layer your own customizations on top of these algorithm-specific ones, supply a perform the fetch hook that modifies the given - request, fetches it, - and then performs specific validations of the resulting response (completing with a network error if the - validations fail).

- -

The hook can also be used to perform more subtle customizations, such as keeping a cache of - responses and avoiding performing a fetch at all.

-
+
+
asynchronous perform the fetch hook
+ +

It takes a request, a boolean isTopLevel, and a processCustomFetchResponse + algorithm. It runs processCustomFetchResponse with a + response (which may be a network + error).

+ +
synchronous perform the fetch hook
+ +

It takes a request and a boolean isTopLevel, and returns a response (which may be a network error).

+
+ +

In both cases, isTopLevel will be true for all classic + script fetches, and for the initial fetch when fetching an external module script graph, fetching a module worker script graph, or fetching an import() module script graph, but false for the fetches + resulting from import statements encountered throughout the graph.

+ +

By default, not supplying a perform the fetch + hook will cause the below algorithms to simply fetch + the given request, with algorithm-specific customizations + to the request and validations of the resulting response.

+ +

To layer your own customizations on top of these algorithm-specific ones, supply a perform the fetch hook that modifies the given + request, fetches it, + and then performs specific validations of the resulting response (completing with a network error if the + validations fail).

+ +

The hook can also be used to perform more subtle customizations, such as keeping a cache of + responses and avoiding performing a fetch at all.

Service Workers is an example of a specification that runs these algorithms with its own options for the hook.

@@ -92975,75 +92985,69 @@ document.querySelector("button").addEventListener("click", bound);
  • -

    If the caller specified custom steps to perform - the fetch, perform them on request, with the is top-level flag set. Return from this algorithm, - and run the remaining steps as part of the perform - the fetch's processCustomFetchResponse given response response.

    - -

    Otherwise, fetch request. Return from this - algorithm, and run the remaining steps as part of the fetch's processResponseConsumeBody given response response.

    +

    Fetch request with + the following processResponseConsumeBody steps given + response response:

    response can be either CORS-same-origin or CORS-cross-origin. This only affects how error reporting happens.

    -
  • -
  • Finalize and report timing with response, settings - object's global object, and "script".

  • +
      +
    1. Finalize and report timing with response, settings + object's global object, and "script".

    2. -
    3. Set response to response's unsafe response.

    4. +
    5. Set response to response's unsafe response.

    6. -
    7. -

      If response's type is "error", or response's status is not an ok status, then - run onComplete given null, and return.

      +
    8. +

      If response's type is "error", or response's status is not an ok status, then + run onComplete given null, and abort these steps.

      -

      For historical reasons, this algorithm does not include MIME type checking, - unlike the other script-fetching algorithms in this section.

      -
    9. +

      For historical reasons, this algorithm does not include MIME type checking, + unlike the other script-fetching algorithms in this section.

      + -
    10. Let potentialMIMETypeForEncoding be the result of extracting a MIME type given response's header list.

    11. +
    12. Let potentialMIMETypeForEncoding be the result of extracting a MIME type given response's header list.

    13. -
    14. -

      Set character encoding to the result of legacy extracting an encoding given potentialMIMETypeForEncoding and - character encoding.

      +
    15. +

      Set character encoding to the result of legacy extracting an encoding given potentialMIMETypeForEncoding + and character encoding.

      -

      This intentionally ignores the MIME type essence.

      -
    16. +

      This intentionally ignores the MIME type essence.

      + -
    17. -

      Let source text be the result of decoding - response's body to Unicode, using - character encoding as the fallback encoding.

      +
    18. +

      Let source text be the result of decoding + response's body to Unicode, using + character encoding as the fallback encoding.

      -

      The decode algorithm overrides character encoding if - the file contains a BOM.

      -
    19. +

      The decode algorithm overrides character encoding if + the file contains a BOM.

      + -
    20. Let muted errors be true if response was - CORS-cross-origin, and false otherwise.

    21. +
    22. Let muted errors be true if response was + CORS-cross-origin, and false otherwise.

    23. -
    24. Let script be the result of creating a classic script given - source text, settings object, response's url, options, and muted - errors.

    25. +
    26. Let script be the result of creating a classic script given + source text, settings object, response's URL, options, and muted + errors.

    27. -
    28. Run onComplete given script.
    29. +
    30. Run onComplete given script.
    31. +
    +

    To fetch a classic worker script given a url, a fetch client - settings object, a destination, a script settings object, and an - onComplete algorithm, run these steps. onComplete must be an algorithm - accepting null (on failure) or a classic script (on success).

    + settings object, a destination, a script settings object, an + onComplete algorithm, and an optional asynchronous perform the fetch hook + performFetch, run these steps. onComplete must be an algorithm accepting + null (on failure) or a classic script (on success).

    1. Let request be a new request whose

    2. -

      If the caller specified custom steps to perform - the fetch, perform them on request, with the is top-level flag set. Return from this algorithm, - and run the remaining steps as part of the perform - the fetch's processCustomFetchResponse given response response.

      +

      If performFetch was given, run performFetch with request, + true, and with processResponse as defined below.

      -

      Otherwise, fetch request. Return from this - algorithm, and run the remaining steps as part of the fetch's processResponseConsumeBody given response response.

      -

    3. +

      Otherwise, fetch request with processResponseConsumeBody set to + processResponse as defined below.

      -
    4. Finalize and report timing with response, fetch client - settings object's global object, and - "other".

    5. +

      In both cases, let processResponse given response response be the following algorithm:

      -
    6. Set response to response's unsafe response.

    7. +
        +
      1. Finalize and report timing with response, fetch client + settings object's global object, and + "other".

      2. -
      3. -

        If either of the following conditions are met:

        +
      4. Set response to response's unsafe response.

      5. - + - +
      6. +

        If both of the following conditions are met:

        -

        then run onComplete given null, and return.

        +
          +
        • response's URL's scheme is an HTTP(S) scheme; and

        • -

          Other fetch schemes are exempted from MIME - type checking for historical web-compatibility reasons. We might be able to tighten this in the - future; see issue #3255.

          - +
        • the result of extracting a MIME type from + response's header list is not + a JavaScript MIME type,

          +
        -
      7. Let source text be the result of UTF-8 - decoding response's body.

      8. +

        then run onComplete given null, and abort these steps.

        -
      9. Let script be the result of creating a classic script using - source text, script settings object, response's url, and the default classic script fetch - options.

      10. +

        Other fetch schemes are exempted from MIME + type checking for historical web-compatibility reasons. We might be able to tighten this in + the future; see issue #3255.

        + + +
      11. Let source text be the result of UTF-8 + decoding response's body.

      12. -
      13. Run onComplete given script.

      14. +
      15. Let script be the result of creating a classic script using + source text, script settings object, response's URL, and the default classic script fetch + options.

      16. + +
      17. Run onComplete given script.

      18. +
      +
    -

    To fetch a classic worker-imported script given a url and a - settings object, run these steps. The algorithm will synchronously complete with a +

    To fetch a classic worker-imported script given a url, a + settings object, and an optional synchronous perform the fetch hook + performFetch, run these steps. The algorithm will synchronously complete with a classic script on success, or throw an exception on failure.

      @@ -93134,26 +93140,15 @@ document.querySelector("button").addEventListener("click", bound); parser-inserted", synchronous flag is set, and whose use-URL-credentials flag is set.

      -
    1. Let response be null.

    2. -
    3. -

      If the caller specified custom steps to perform - the fetch, perform them on request, with the is top-level flag set, and with the following processCustomFetchResponse steps given - response customFetchResponse:

      +

      If performFetch was given, let response be the result of running + performFetch given request and true.

      -
        -
      1. Set response to customFetchResponse.

      2. -
      - -

      Otherwise, fetch request, and set - response to the result.

      +

      Otherwise, let response be the result of fetching request.

      Unlike other algorithms in this section, the fetching process is synchronous - here. Thus any perform the fetch steps will - also run processCustomFetchResponse - synchronously, and response will have been set when this step completes.

      + here.

    4. Finalize and report timing with response, settings @@ -93188,7 +93183,7 @@ document.querySelector("button").addEventListener("click", bound);

    5. Let script be the result of creating a classic script given source text, settings object, response's url, the default classic script fetch options, + data-x="concept-response-url">URL, the default classic script fetch options, and muted errors.

    6. Return script.

    7. @@ -93201,13 +93196,13 @@ document.querySelector("button").addEventListener("click", bound);
      1. -

        Fetch a single module script given url, settings - object, "script", options, settings object, - "client", with the top-level module fetch flag set, and with - the following steps given result:

        +

        Fetch a single module script given url, settings object, + "script", options, settings object, "client", true, and with the following steps given result:

          -
        1. If result is null, run onComplete given null, and return.

        2. +
        3. If result is null, run onComplete given null, and abort these + steps.

        4. Let visited set be « (url, "javascript") ».

        5. @@ -93216,10 +93211,7 @@ document.querySelector("button").addEventListener("click", bound); and link result given settings object, "script", visited set, and onComplete.

        - -

        If the caller of this algorithm specified custom perform the fetch steps, pass those along as - well.

        +

      To fetch an import() module script graph given a moduleRequest, a @@ -93249,11 +93241,12 @@ document.querySelector("button").addEventListener("click", bound);

    8. Fetch a single module script given url, settings object, "script", options, settings object, - "client", moduleRequest, with the top-level module fetch - flag set, and with the following steps given result:

      + "client", moduleRequest, true, and with the following steps + given result:

        -
      1. If result is null, run onComplete with null, and return.

      2. +
      3. If result is null, run onComplete with null, and abort these + steps.

      4. Let visited set be « (url, moduleType) ».

      5. @@ -93261,10 +93254,6 @@ document.querySelector("button").addEventListener("click", bound); of and link result given settings object, destination, visited set, and onComplete.

      - -

      If the caller of this algorithm specified custom perform the fetch steps, pass those along as - well.

    @@ -93277,7 +93266,7 @@ document.querySelector("button").addEventListener("click", bound);
  • Fetch a single module script given url, settings object, destination, options, settings object, "client", with the top-level module fetch flag set, and with the + data-x="">client", true, and with the following steps given result:

      @@ -93337,9 +93326,9 @@ document.querySelector("button").addEventListener("click", bound); object, a module responses map, and an onComplete algorithm, fetch a worklet/module worker script graph given url, fetch client settings object, destination, credentials mode, module map - settings object, and onComplete. Use the following custom steps to perform the fetch given response and - processCustomFetchResponse:

      + settings object, onComplete, and the following asynchronous perform + the fetch hook given request and processCustomFetchResponse:

      1. Let requestURL be request's To fetch a worklet/module worker script graph given a url, a fetch client settings object, a destination, a credentials mode, a - module map settings object, and an onComplete algorithm, run these steps. + module map settings object, an onComplete algorithm, and an optional + asynchronous perform the fetch hook performFetch, run these steps. onComplete must be an algorithm accepting null (on failure) or a module script (on success).

        @@ -93508,11 +93498,14 @@ document.querySelector("button").addEventListener("click", bound);
      2. Fetch a single module script given url, fetch client settings object, destination, options, module map settings object, - "client", with the top-level module fetch flag set, and with - the following steps given result:

        + "client", true, and onSingleFetchComplete as defined below. If + performFetch was given, pass it along as well. + +

        onSingleFetchComplete given result is the following algorithm:

          -
        1. If result is null, run onComplete given null, and return.

        2. +
        3. If result is null, run onComplete given null, and abort these + steps.

        4. Let visited set be « (url, "javascript") ».

        5. @@ -93520,18 +93513,15 @@ document.querySelector("button").addEventListener("click", bound);
        6. Fetch the descendants of and link result given fetch client settings object, destination, visited set, and - onComplete.

        7. + onComplete. If performFetch was given, pass it along as well.

        - -

        If the caller of this algorithm specified custom perform the fetch steps, pass those along as - well.

      To fetch the descendants of and link a module script module script, given a fetch client settings object, a destination, a - visited set, and an onComplete algorithm, run these steps. + visited set, an onComplete algorithm, and an optional asynchronous + perform the fetch hook performFetch, run these steps. onComplete must be an algorithm accepting null (on failure) or a module script (on success).

      @@ -93539,12 +93529,15 @@ document.querySelector("button").addEventListener("click", bound);
    1. Fetch the descendants of module script, given fetch client settings object, destination, - visited set, and with the following steps given result:

      + visited set, and onFetchDescendantsComplete as defined below. If + performFetch was given, pass it along as well.

      + +

      onFetchDescendantsComplete given result is the following algorithm:

      1. If result is null, then run onComplete given result, and - return.

        + abort these steps.

        In this case, there was an error fetching one or more of the descendants. We will not attempt to link.

        @@ -93581,9 +93574,10 @@ document.querySelector("button").addEventListener("click", bound);

      To fetch the descendants of a module script module script, given a - fetch client settings object, a destination, a visited set, and - an onComplete algorithm, run these steps. onComplete must be an algorithm - accepting null (on failure) or a module script (on success).

      + fetch client settings object, a destination, a visited set, an + onComplete algorithm, and an optional asynchronous perform the fetch hook + performFetch, run these steps. onComplete must be an algorithm accepting + null (on failure) or a module script (on success).

      1. If module script's record is null, @@ -93650,8 +93644,10 @@ document.querySelector("button").addEventListener("click", bound); procedure given moduleRequest, fetch client settings object, destination, options, module script's settings object, visited set, module script's base URL, and the following steps given - result:

        + data-x="concept-script-base-url">base URL, and onInternalFetchingComplete as + defined below. If performFetch was given, pass it along as well.

        + +

        onInternalFetchingComplete given result is the following algorithm:

        1. If failed is true, then abort these steps.

        2. @@ -93667,10 +93663,6 @@ document.querySelector("button").addEventListener("click", bound); script.

        -

        If the caller of this algorithm specified custom perform the fetch steps, pass those along while - performing the internal module script graph fetching procedure.

        -

        The fetches performed by the internal module script graph fetching procedure are performed in parallel to each other.

      2. @@ -93679,7 +93671,8 @@ document.querySelector("button").addEventListener("click", bound);

        To perform the internal module script graph fetching procedure given a moduleRequest, a fetch client settings object, a destination, some options, a module map settings object, a visited set, a - referrer, and an onComplete algorithm, run these steps. + referrer, an onComplete algorithm, and an optional asynchronous + perform the fetch hook performFetch, run these steps. onComplete must be an algorithm accepting null (on failure) or a module script (on success).

        @@ -93702,29 +93695,32 @@ document.querySelector("button").addEventListener("click", bound);
      3. Fetch a single module script given url, fetch client settings object, destination, options, module map settings object, - referrer, moduleRequest, with the top-level module fetch flag - unset, and with the following steps given result:

        + referrer, moduleRequest, false, and onSingleFetchComplete as + defined below. If performFetch was given, pass it along as well.

        + +

        onSingleFetchComplete given result is the following algorithm:

          -
        1. If result is null, run onComplete with null, and return.

        2. +
        3. If result is null, run onComplete with null, and abort these + steps.

        4. Fetch the descendants of result given fetch client settings object, destination, - visited set, and with onComplete.

        5. + visited set, and with onComplete. If performFetch was given, + pass it along as well.

        -

        If the caller of this algorithm specified custom perform the fetch steps, pass those along as - well.

        +

      To fetch a single module script, given a url, a fetch client settings object, a destination, some options, a module map - settings object, a referrer, an optional moduleRequest, a - top-level module fetch flag, and an onComplete algorithm, run these steps. - onComplete must be an algorithm accepting null (on failure) or a module - script (on success).

      + settings object, a referrer, an optional moduleRequest, a boolean + isTopLevel, an onComplete + algorithm, and an optional asynchronous perform the fetch hook + performFetch, run these steps. onComplete must be an algorithm accepting + null (on failure) or a module script (on success).

      1. Let moduleType be "javascript".

      2. @@ -93778,76 +93774,77 @@ document.querySelector("button").addEventListener("click", bound);
      3. -

        If the caller specified custom steps to perform - the fetch, perform them on request, setting the is top-level flag if the top-level module - fetch flag is set. Return from this algorithm, and run the remaining steps as part of the - perform the fetch's processCustomFetchResponse given response response.

        +

        If performFetch was given, run performFetch with request, + isTopLevel, and with processResponse as defined below.

        -

        Otherwise, fetch request. Return from this - algorithm, and run the remaining steps as part of the fetch's processResponseConsumeBody given response response.

        +

        Otherwise, fetch request with + processResponse as processResponseConsumeBody.

        -

        response is always CORS-same-origin.

        -
      4. +

        In both cases, let processResponse given response response be the following algorithm:

        -
      5. Finalize and report timing with response, fetch client - settings object's global object, and - "other".

      6. +

        response is always CORS-same-origin.

        -
      7. -

        If either of the following conditions are met:

        +
          +
        1. Finalize and report timing with response, fetch client + settings object's global object, and + "other".

        2. -
            -
          • response's type is "error"; or

          • +
          • +

            If either of the following conditions are met:

            -
          • response's status is not an - ok status.

          • -
          +
            +
          • response's type is "error"; or

          • -

            then set moduleMap[(url, - moduleType)] to null, run onComplete given null, and return.

            - +
          • response's status is not an + ok status.

          • +
          -
        3. Let source text be the result of UTF-8 - decoding response's body.

        4. +

          then set moduleMap[(url, + moduleType)] to null, run onComplete given null, and abort these + steps.

          + -
        5. Let MIME type be the result of extracting a - MIME type from response's header - list.

        6. +
        7. Let source text be the result of UTF-8 + decoding response's body.

        8. -
        9. Let module script be null.

        10. +
        11. Let MIME type be the result of extracting + a MIME type from response's header list.

        12. -
        13. If MIME type is a JavaScript MIME type and moduleType - is "javascript", then set module script to the result of - creating a JavaScript module script given source text, module map - settings object, response's url, and - options.

        14. +
        15. Let module script be null.

        16. -
        17. If the MIME type essence of MIME type is "text/css" - and moduleType is "css", then set module script to - the result of creating a CSS module script given source text and - module map settings object.

        18. +
        19. If MIME type is a JavaScript MIME type and moduleType + is "javascript", then set module script to the result of + creating a JavaScript module script given source text, module map + settings object, response's URL, + and options.

        20. -
        21. If MIME type essence is a JSON MIME type and moduleType - is "json", then set module script to the result of - creating a JSON module script given source text and module map - settings object.

        22. +
        23. If the MIME type essence of MIME type is "text/css" + and moduleType is "css", then set module script to + the result of creating a CSS module script given source text and + module map settings object.

        24. -
        25. -

          Set moduleMap[(url, - moduleType)] to module script, and run onComplete given - module script.

          +
        26. If MIME type essence is a JSON MIME type and + moduleType is "json", then set module script to + the result of creating a JSON module script given source text and + module map settings object.

        27. -

          It is intentional that the module map is keyed by the request URL, whereas the base URL for the module script is - set to the response URL. The former is used to - deduplicate fetches, while the latter is used for URL resolution.

          +
        28. +

          Set moduleMap[(url, + moduleType)] to module script, and run onComplete given + module script.

          + +

          It is intentional that the module map is keyed by the request URL, whereas the base URL for the module script is + set to the response URL. The former is used to + deduplicate fetches, while the latter is used for URL resolution.

          +
        29. +
      @@ -103789,22 +103786,22 @@ interface SharedWorkerGlobalScope : WorkerGlobalScope
      "classic"
      Fetch a classic worker script given url, outside settings, destination, inside settings, and with - onComplete as defined below.
      + onComplete and performFetch as defined below.
      "module"
      Fetch a module worker script graph given url, outside settings, destination, the value of the credentials - member of options, inside settings, and with onComplete as - defined below.
      + member of options, inside settings, and with onComplete and + performFetch as defined below. -

      In both cases, to perform the fetch - given request, is top-level and In both cases, let performFetch be the following asynchronous perform the + fetch hook given request, is + top-level and processCustomFetchResponse:

        -
      1. If is top-level is not set, fetch +

      2. If isTopLevel is false, fetch request with processCustomFetchResponse as processResponseConsumeBody and return.

      3. @@ -104593,11 +104590,9 @@ interface SharedWorker : EventTarget { and urls.

        To import scripts into worker global scope, given a - WorkerGlobalScope object worker global scope and a sequence<DOMString> urls, run these steps. The algorithm may - optionally be customized by supplying custom perform - the fetch hooks, which if provided will be used when invoking fetch a classic - worker-imported script.

        + WorkerGlobalScope object worker global scope, a list of + scalar value strings urls, and an optional + synchronous perform the fetch hook performFetch:

        1. If worker global scope's SharedWorker : EventTarget {

        2. For each url in the resulting URL - records, run these substeps:

          + records:

          1. Fetch a classic worker-imported script given url and - settings object, passing along any custom perform the fetch steps provided. If this + settings object, passing along performFetch if provided. If this succeeds, let script be the result. Otherwise, rethrow the exception.

          2. @@ -104640,8 +104634,7 @@ interface SharedWorker : EventTarget {

          Service Workers is an example of a specification that runs this - algorithm with its own options for the perform the - fetch hook.

          + algorithm with its own synchronous perform the fetch hook.