From 94dfbb0ecd9e2b62ff9b2aab5f16537b374b333c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Ribaudo?= Date: Wed, 28 Sep 2022 15:18:34 +0200 Subject: [PATCH 1/7] Explicitly pass around the "perform the fetch" hook --- source | 484 +++++++++++++++++++++++++++++---------------------------- 1 file changed, 244 insertions(+), 240 deletions(-) diff --git a/source b/source index 736eb813282..7e0748c854a 100644 --- a/source +++ b/source @@ -92911,34 +92911,47 @@ 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.

+

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

+ +
+
asynchronous perform the fetch hook
+ +

It takes a request, an is top-level flag, and a processCustomFetchResponse + algorithm. It runs runs processCustomFetchResponse with a + response (which may be a network + error).

+ +
synchronous perform the fetch hook
+ +

It takes a request and an is top-level flag, and returns a response (which may be a network error).

+
+ +

In both cases, 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.

-

By default, not supplying the perform the - fetch will cause the below algorithms to simply fetch +

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 + data-x="fetching-scripts-perform-fetch">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 @@ -92958,7 +92971,8 @@ document.querySelector("button").addEventListener("click", bound);

To fetch a classic script given a url, a settings object, some options, a CORS setting, a character - encoding, and an onComplete algorithm, run these steps. onComplete + encoding, 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).

@@ -92975,75 +92989,76 @@ 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.

    +

    If performFetch was given, run performFetch with request, + with the is top-level flag set, 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.

    + +

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

    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 return.

      -

      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, + with the is top-level flag set, 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 + processResponse as processResponseConsumeBody.

      -
    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. -
          -
        • 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 run onComplete given null, and return.

          - -
        • -

          If both of the following conditions are met:

          +
        • response's status is not an + ok status,

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

        • +

          then run onComplete given null, and return.

          + +
        • +

          If both of the following conditions are met:

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

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

        • -

          then run onComplete given null, and return.

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

          +
        -

        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.

        - +

        then run onComplete given null, and return.

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

      7. +

        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.

        + -
      8. 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.

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

      11. + +
      12. 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.

      13. -
      14. Run onComplete given script.

      15. +
      16. Run onComplete given script.

      17. +
      +
    -

    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 +93150,16 @@ 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:

      - -
        -
      1. Set response to customFetchResponse.

      2. -
      +

      If performFetch was given, let response be the result of running + performFetch given request with the is top-level flag set.

      -

      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 @@ -93195,8 +93201,9 @@ document.querySelector("button").addEventListener("click", bound);

    To fetch an external module script graph - given a url, a settings object, some options, and an - onComplete algorithm, run these steps. onComplete must be an algorithm + given a url, a settings object, some options, 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).

      @@ -93214,17 +93221,15 @@ document.querySelector("button").addEventListener("click", bound);
    1. Fetch the descendants of and link result given settings object, "script", visited set, and onComplete.

    2. + data-x="">script", visited set, and 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 an import() module script graph given a moduleRequest, a - base URL, a settings object, some options, and an - onComplete algorithm, run these steps. onComplete must be an algorithm + base URL, a settings object, some options, 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).

      @@ -93262,9 +93267,7 @@ document.querySelector("button").addEventListener("click", bound); visited set, and onComplete.

    -

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

    +

    If performFetch was given, pass it along as well.

    @@ -93337,9 +93340,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 with the following asynchronous perform + the fetch hook given response 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).

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

    3. + 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.

    +

    If performFetch was given, pass it 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).

    @@ -93577,13 +93580,16 @@ document.querySelector("button").addEventListener("click", bound);
  • Run onComplete given result.

  • + +

    If performFetch was given, pass it along as well.

    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, @@ -93667,9 +93673,8 @@ 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.

    +

    If performFetch was given, pass it along to 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.

    @@ -93679,7 +93684,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).

    @@ -93710,19 +93716,19 @@ document.querySelector("button").addEventListener("click", bound);
  • Fetch the descendants of result given fetch client settings object, destination, - visited set, and with onComplete.

  • + 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.

    +

    If performFetch was given, pass it 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. + top-level module fetch flag, 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).

    @@ -93778,76 +93784,78 @@ document.querySelector("button").addEventListener("click", bound);
  • -

    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, + setting the is top-level flag if the + top-level module fetch flag is set, 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.

    -
  • +

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

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

  • +

    response is always CORS-same-origin.

    -
  • -

    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 return.

      + -
    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,18 +103797,18 @@ 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:

      @@ -104593,11 +104601,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 sequence<DOMString> urls, and an optional synchronous perform + the fetch hook performFetch, run these steps.

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

        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 +104645,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.

    From 28e1a21ae78bdec5fffb78bc555dcb9e5547da9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Ribaudo?= Date: Wed, 28 Sep 2022 15:29:28 +0200 Subject: [PATCH 2/7] Delete unused hook from some algorithms --- source | 32 ++++++++++---------------------- 1 file changed, 10 insertions(+), 22 deletions(-) diff --git a/source b/source index 7e0748c854a..aef8193df63 100644 --- a/source +++ b/source @@ -92971,8 +92971,7 @@ document.querySelector("button").addEventListener("click", bound);

    To fetch a classic script given a url, a settings object, some options, a CORS setting, a character - encoding, an onComplete algorithm, and an optional asynchronous perform the - fetch hook performFetch, run these steps. onComplete + encoding, and an onComplete algorithm, run these steps. onComplete must be an algorithm accepting null (on failure) or a classic script (on success).

    @@ -92989,16 +92988,9 @@ document.querySelector("button").addEventListener("click", bound);
  • -

    If performFetch was given, run performFetch with request, - with the is top-level flag set, and with - processResponse as defined below.

    - -

    Otherwise, fetch request with - processResponse as processResponseConsumeBody.

    - -

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

    +

    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.

    @@ -93201,9 +93193,8 @@ document.querySelector("button").addEventListener("click", bound);

    To fetch an external module script graph - given a url, a settings object, some options, an - onComplete algorithm, and an optional asynchronous perform the fetch hook - performFetch, run these steps. onComplete must be an algorithm + given a url, a settings object, some options, and an + onComplete algorithm, run these steps. onComplete must be an algorithm accepting null (on failure) or a module script (on success).

      @@ -93221,15 +93212,14 @@ document.querySelector("button").addEventListener("click", bound);
    1. Fetch the descendants of and link result given settings object, "script", visited set, and onComplete. If - performFetch was given, pass it along as well.

    2. + data-x="">script", visited set, and onComplete.

    +
  • To fetch an import() module script graph given a moduleRequest, a - base URL, a settings object, some options, an - onComplete algorithm, and an optional asynchronous perform the fetch hook - performFetch, run these steps. onComplete must be an algorithm + base URL, a settings object, some options, and an + onComplete algorithm, run these steps. onComplete must be an algorithm accepting null (on failure) or a module script (on success).

      @@ -93266,8 +93256,6 @@ document.querySelector("button").addEventListener("click", bound); of and link result given settings object, destination, visited set, and onComplete.

    - -

    If performFetch was given, pass it along as well.

    From 92948a2df20f2a5d2e229aa1c54b06d320747dca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Ribaudo?= Date: Mon, 3 Oct 2022 15:58:14 +0200 Subject: [PATCH 3/7] Make "is top-level" a boolean --- source | 60 ++++++++++++++++++++++++++-------------------------------- 1 file changed, 27 insertions(+), 33 deletions(-) diff --git a/source b/source index aef8193df63..0cb6ea640f6 100644 --- a/source +++ b/source @@ -92918,8 +92918,8 @@ document.querySelector("button").addEventListener("click", bound);
    asynchronous perform the fetch hook
    -

    It takes a request, an is top-level flag, and a request, a boolean isTopLevel, and a processCustomFetchResponse algorithm. It runs runs synchronous perform the fetch hook -

    It takes a request and an is top-level flag, and returns a

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

    -

    In both cases, 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.

    +

    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 @@ -93066,8 +93065,7 @@ document.querySelector("button").addEventListener("click", bound);

  • If performFetch was given, run performFetch with request, - with the is top-level flag set, and with - processResponse as defined below.

    + true, and with processResponse as defined below.

    Otherwise, fetch request with processResponse as

    If performFetch was given, let response be the result of running - performFetch given request with the is top-level flag set.

    + performFetch given request and true.

    Otherwise, let response be the result of fetching request.

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

      @@ -93244,8 +93241,8 @@ document.querySelector("button").addEventListener("click", bound);
    1. 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. @@ -93268,7 +93265,7 @@ document.querySelector("button").addEventListener("click", bound);
      3. 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:

          @@ -93500,8 +93497,7 @@ document.querySelector("button").addEventListener("click", bound);
        1. 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 with the following steps given result:

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

          2. @@ -93696,8 +93692,8 @@ 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 with the following steps given + result:

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

            2. @@ -93714,11 +93710,11 @@ document.querySelector("button").addEventListener("click", bound);

              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, 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).

              + 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. @@ -93773,9 +93769,7 @@ document.querySelector("button").addEventListener("click", bound);
              3. If performFetch was given, run performFetch with request, - setting the is top-level flag if the - top-level module fetch flag is set, and with processResponse as defined - below.

                + isTopLevel, and with processResponse as defined below.

                Otherwise, fetch request with processResponse as SharedWorkerGlobalScope : WorkerGlobalScope data-x="fetching-scripts-processCustomFetchResponse">processCustomFetchResponse:

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

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

                3. From 4754f57bb18c2c1dc2d1d0f314cc92151961f989 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Ribaudo?= Date: Mon, 3 Oct 2022 16:11:16 +0200 Subject: [PATCH 4/7] Review by domenic --- source | 45 ++++++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/source b/source index 0cb6ea640f6..673b41fd9ee 100644 --- a/source +++ b/source @@ -92911,7 +92911,7 @@ document.querySelector("button").addEventListener("click", bound);
                  -

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

                  @@ -92922,7 +92922,7 @@ document.querySelector("button").addEventListener("click", bound); data-x="fetching-scripts-is-top-level">isTopLevel, and a processCustomFetchResponse - algorithm. It runs runs processCustomFetchResponse with a response (which may be a network error).

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

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

                  -

                  Otherwise, fetch request with - processResponse as processResponseConsumeBody.

                  +

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

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

                  @@ -93325,8 +93325,8 @@ 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, onComplete, and with the following asynchronous perform - the fetch hook given response and , onComplete, and the following asynchronous perform + the fetch hook given request and processCustomFetchResponse:

                    @@ -93497,7 +93497,10 @@ document.querySelector("button").addEventListener("click", bound);
                  1. Fetch a single module script given url, fetch client settings object, destination, options, module map settings object, - "client", true, 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. @@ -93510,8 +93513,6 @@ document.querySelector("button").addEventListener("click", bound); object, destination, visited set, and onComplete. If performFetch was given, pass it along as well.

                    - -

                    If performFetch was given, pass it along as well.

                  @@ -93526,7 +93527,10 @@ document.querySelector("button").addEventListener("click", bound);
                4. 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. @@ -93564,8 +93568,6 @@ document.querySelector("button").addEventListener("click", bound);
                  2. Run onComplete given result.

                  - -

                  If performFetch was given, pass it along as well.

                @@ -93640,8 +93642,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. @@ -93657,9 +93661,6 @@ document.querySelector("button").addEventListener("click", bound); script.

                -

                If performFetch was given, pass it along to 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.

              4. @@ -93692,8 +93693,10 @@ document.querySelector("button").addEventListener("click", bound);
              5. Fetch a single module script given url, fetch client settings object, destination, options, module map settings object, - referrer, moduleRequest, false, 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. @@ -93704,7 +93707,7 @@ document.querySelector("button").addEventListener("click", bound); pass it along as well.

                -

                If performFetch was given, pass it along as well.

                +

              From 01a8014f25f3d2e0ef6607a41fba0cfa69f11e63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Ribaudo?= Date: Mon, 3 Oct 2022 17:47:24 +0200 Subject: [PATCH 5/7] Export sync/async variants of the hook, for SW --- source | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source b/source index 673b41fd9ee..fe85c740c31 100644 --- a/source +++ b/source @@ -92916,7 +92916,7 @@ document.querySelector("button").addEventListener("click", bound); hook algorithm, in one of the following forms:

              -
              asynchronous perform the fetch hook
              +
              asynchronous perform the fetch hook

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

              -
              synchronous perform the fetch hook
              +
              synchronous perform the fetch hook

              It takes a request and a boolean isTopLevel, and returns a Date: Tue, 4 Oct 2022 15:31:29 +0900 Subject: [PATCH 6/7] Small fixes, some to preexisting text --- source | 76 ++++++++++++++++++++++++++++++---------------------------- 1 file changed, 40 insertions(+), 36 deletions(-) diff --git a/source b/source index fe85c740c31..b4270d726d7 100644 --- a/source +++ b/source @@ -92942,24 +92942,22 @@ document.querySelector("button").addEventListener("click", bound); module script graph">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.

              -
              +

              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.

              @@ -93005,7 +93003,7 @@ document.querySelector("button").addEventListener("click", bound);

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

              + 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.

              @@ -93037,7 +93035,7 @@ document.querySelector("button").addEventListener("click", bound);
            3. Let script be the result of creating a classic script given source text, settings object, response's url, options, and muted + data-x="concept-response-url">URL, options, and muted errors.

            4. Run onComplete given script.
            5. @@ -93092,13 +93090,14 @@ document.querySelector("button").addEventListener("click", bound); ok status,

              -

              then run onComplete given null, and return.

              +

              then run onComplete given null, and abort these steps.

              +
            6. If both of the following conditions are met:

                -
              • response's url's

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

              • the result of extracting a MIME type from @@ -93106,7 +93105,7 @@ document.querySelector("button").addEventListener("click", bound); JavaScript MIME type,

              -

              then run onComplete given null, and return.

              +

              then run onComplete given null, and abort these steps.

              Other fetch schemes are exempted from MIME type checking for historical web-compatibility reasons. We might be able to tighten this in the @@ -93118,7 +93117,7 @@ document.querySelector("button").addEventListener("click", bound);

            7. 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 + data-x="concept-response-url">URL, and the default classic script fetch options.

            8. Run onComplete given script.

            9. @@ -93183,7 +93182,7 @@ document.querySelector("button").addEventListener("click", bound);
            10. 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.

            11. Return script.

            12. @@ -93202,7 +93201,8 @@ document.querySelector("button").addEventListener("click", bound); 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. @@ -93245,7 +93245,8 @@ document.querySelector("button").addEventListener("click", bound); 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. @@ -93503,7 +93504,8 @@ document.querySelector("button").addEventListener("click", bound);

                  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. @@ -93535,7 +93537,7 @@ document.querySelector("button").addEventListener("click", bound);
                    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.

                      @@ -93699,7 +93701,8 @@ document.querySelector("button").addEventListener("click", bound);

                      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, @@ -93800,7 +93803,8 @@ document.querySelector("button").addEventListener("click", bound);

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

                        + moduleType)] to null, run onComplete given null, and abort these + steps.

                      5. Let source text be the result of UTF-8 @@ -93816,7 +93820,7 @@ document.querySelector("button").addEventListener("click", bound);

                      6. 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, + settings object, response's URL, and options.

                      7. If the MIME type essence of MIME type is "text/css" @@ -104586,9 +104590,9 @@ interface SharedWorker : EventTarget { and urls.

                        To import scripts into worker global scope, given a - WorkerGlobalScope object worker global scope, a sequence<DOMString> urls, and an optional synchronous perform - the fetch hook performFetch, run these steps.

                        + 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 From 5979594d26eaf0926c8d12da5eec56fa74425a30 Mon Sep 17 00:00:00 2001 From: Domenic Denicola Date: Tue, 4 Oct 2022 15:33:22 +0900 Subject: [PATCH 7/7] A bit of rewrapping --- source | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/source b/source index b4270d726d7..cbb74d3480b 100644 --- a/source +++ b/source @@ -93009,14 +93009,14 @@ document.querySelector("button").addEventListener("click", bound); unlike the other script-fetching algorithms in this section.

                          2. -
                          3. Let potentialMIMETypeForEncoding be the result of extracting a MIME type given response's

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

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

                            + encoding">legacy extracting an encoding given potentialMIMETypeForEncoding + and character encoding.

                            This intentionally ignores the MIME type essence.

                          5. @@ -93101,19 +93101,20 @@ document.querySelector("button").addEventListener("click", bound); data-x="concept-url-scheme">scheme is an HTTP(S) scheme; and

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

                            + response's header list is not + a JavaScript MIME type,

                            then run onComplete given null, and abort these steps.

                            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.

                            + type checking for historical web-compatibility reasons. We might be able to tighten this in + the future; see issue #3255.

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

                          8. + decoding response's body.

                          9. Let script be the result of creating a classic script using source text, script settings object, response's

                          10. -

                            Fetch a single module script given url, settings - object, "script", options, settings object, - "client", true, 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 abort these