From 07fb2c0449540a69221f81cd4e5b24bf1fcccd41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Ribaudo?= Date: Fri, 21 Oct 2022 00:06:13 +0200 Subject: [PATCH 1/7] Fix usage of processResponseConsumeBody --- source | 253 ++++++++++++++++++++++++++++++++------------------------- 1 file changed, 144 insertions(+), 109 deletions(-) diff --git a/source b/source index 4d8cb26a588..1f8d9321af5 100644 --- a/source +++ b/source @@ -14750,24 +14750,34 @@ interface HTMLLinkElement : HTMLElement {
  • Fetch request with processResponseConsumeBody set to the following steps - given response response:

    + given response response and null, failure, or + a byte sequence bytesOrNull:

    1. Finalize and report timing with response, el's node document's relevant global object, and initiatorType.

    2. +
    3. Let success be true.

    4. +
    5. -

      If response is a network error or its status is not an ok - status, set success to false.

      +

      If either of the following conditions are met:

      + +
        +
      • bytesOrNull is null or failure; or

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

      • +
      + +

      then set success to false.

      Note that content-specific errors, e.g., CSS parse errors or PNG decoding errors, do not affect success.

    6. -

      If success is true, wait for the link +

      Otherwise, wait for the link resource's critical subresources to finish loading.

      The specification that defines a link type's critical subresources @@ -14777,8 +14787,9 @@ interface HTMLLinkElement : HTMLElement { be fetched and processed, with the expectation that this will be done correctly.

    7. -
    8. Process the linked resource given el, - success, and response.

    9. + +
    10. Process the linked resource given el, success, and + response.

  • @@ -93037,8 +93048,8 @@ document.querySelector("button").addEventListener("click", bound); data-x="fetching-scripts-processCustomFetchResponse">processCustomFetchResponse algorithm. It runs processCustomFetchResponse with a - response (which may be a network - error).

    + response and either null (on failure) or a byte + sequence containing the response body.

    synchronous perform the fetch hook
    @@ -93100,7 +93111,8 @@ document.querySelector("button").addEventListener("click", bound);
  • Fetch request with the following processResponseConsumeBody steps given - response response:

    + response response and null, failure, or a + byte sequence bytesOrNull:

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

    @@ -93113,10 +93125,16 @@ document.querySelector("button").addEventListener("click", bound);
  • Set response to response's unsafe response.

  • -

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

    +

    If either of the following conditions are met:

    + + + +

    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.

    @@ -93136,8 +93154,8 @@ document.querySelector("button").addEventListener("click", bound);
  • Let source text be the result of decoding - response's body to Unicode, using - character encoding as the fallback encoding.

    + bytesOrNull to Unicode, using character encoding as the fallback + encoding.

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

    @@ -93176,14 +93194,14 @@ document.querySelector("button").addEventListener("click", bound);
  • If performFetch was given, run performFetch with request, - true, and with processResponse as defined below.

    + true, and with processResponseConsumeBody as defined below.

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

    + data-x="processResponseConsumeBody">processResponseConsumeBody as defined below.

    -

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

    +

    In both cases, let processResponseConsumeBody given response response and null, failure, or a byte + sequence bytesOrNull be the following algorithm:

    1. Finalize and report timing with response, fetch client @@ -93196,8 +93214,7 @@ document.querySelector("button").addEventListener("click", bound);

      If either of the following conditions are met:

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

      • +
      • bytesOrNull is null or failure; or

      • response's status is not an ok status,

      • @@ -93226,8 +93243,7 @@ document.querySelector("button").addEventListener("click", bound);
      • Let source text be the result of UTF-8 - decoding response's body.

      • + decoding bytesOrNull.

      • Let script be the result of creating a classic script using source text, script settings object, response's To fetch a worklet script graph given a url, a fetch client settings object, a destination, a credentials mode, a module map settings - 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 the following asynchronous perform - the fetch hook given request and , a module responses map + moduleResponsesMap, 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 the following asynchronous perform the fetch + hook given request and processCustomFetchResponse:

          @@ -93461,9 +93478,19 @@ document.querySelector("button").addEventListener("click", bound); queue a task on the networking task source to proceed with running the following steps.

          -
        1. If moduleResponsesMap[requestURL] exists, then run processCustomFetchResponse with - moduleResponsesMap[requestURL] and return.

        2. +
        3. +

          If moduleResponsesMap[requestURL] exists, then:

          + +
            +
          1. Let cached be moduleResponsesMap[requestURL].

          2. + +
          3. Run processCustomFetchResponse with cached[0] and + cached[1].

          4. + +
          5. Return.

          6. +
          +
        4. Set moduleResponsesMap[requestURL] to "fetching".

        5. @@ -93471,13 +93498,15 @@ document.querySelector("button").addEventListener("click", bound);
        6. Fetch request, with processResponseConsumeBody set to the following steps - given response response:

          + given response response and null, failure, or a + byte sequence bytesOrNull:

            -
          1. Set moduleResponsesMap[requestURL] to - response.

          2. +
          3. Set moduleResponsesMap[requestURL] to (response, + bytesOrNull).

          4. -
          5. Run processCustomFetchResponse with response.

          6. +
          7. Run processCustomFetchResponse with response and + bytesOrNull.

        @@ -93896,14 +93925,14 @@ document.querySelector("button").addEventListener("click", bound);
      • If performFetch was given, run performFetch with request, - isTopLevel, and with processResponse as defined below.

        + isTopLevel, and with processResponseConsumeBody as defined below.

        -

        Otherwise, fetch request with - processResponse as processResponseConsumeBody.

        +

        Otherwise, fetch request with processResponseConsumeBody as defined below.

        -

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

        +

        In both cases, let processResponseConsumeBody given response response and null, failure, or a + byte sequence bytesOrNull be the following algorithm:

        response is always CORS-same-origin.

        @@ -93916,11 +93945,10 @@ document.querySelector("button").addEventListener("click", bound);

        If either of the following conditions are met:

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

        • +
        • bytesOrNull is null or failure; or

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

        • + ok status,

        then set moduleMap[(url, @@ -93929,8 +93957,7 @@ document.querySelector("button").addEventListener("click", bound);

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

      • + decoding bytesOrNull.

      • Let MIME type be the result of extracting a MIME type from response's SharedWorkerGlobalScope : WorkerGlobalScope

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

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

        2. + request with processResponseConsumeBody + and abort these steps.

        3. Set request's reserved client to inside settings.
        4. -
        5. Fetch request. Return from this - algorithm, and run the remaining steps as part of the fetch's process response for - the response response.

        6. +
        7. +

          Fetch request with with processResponseConsumeBody set to the following steps + given response response and null, failure, or + a byte sequence bytesOrNull:

          -
        8. Set worker global scope's url to response's url.

        9. +
            +
          1. Set worker global scope's url to response's url.

          2. -
          3. Initialize worker global scope's - policy container given worker global scope, response, and - inside settings.

          4. +
          5. Initialize worker global scope's + policy container given worker global scope, response, and + inside settings.

          6. -
          7. If the Run CSP initialization for a global object algorithm returns "Blocked" when executed upon worker global scope, set - response to a network error.

          8. +
          9. If the Run CSP initialization for a global object algorithm returns "Blocked" when executed upon worker global scope, set + response to a network error.

          10. -
          11. -

            If worker global scope's embedder policy's value is compatible with cross-origin - isolation and is shared is true, then set agent's agent - cluster's cross-origin isolation - mode to "logical" or "concrete". The one chosen is - implementation-defined.

            - -

            This really ought to be set when the agent cluster is created, which requires a - redesign of this section.

            -
          12. +
          13. +

            If worker global scope's embedder policy's value is compatible with cross-origin + isolation and is shared is true, then set agent's agent + cluster's cross-origin isolation + mode to "logical" or "concrete". The one chosen is + implementation-defined.

            + +

            This really ought to be set when the agent cluster is created, which requires a + redesign of this section.

            +
          14. -
          15. If the result of checking a - global object's embedder policy with worker global scope, outside - settings, and response is false, then set response to a - network error.

          16. +
          17. If the result of checking a + global object's embedder policy with worker global scope, outside + settings, and response is false, then set response to a + network error.

          18. -
          19. Set worker global scope's cross-origin isolated - capability to true if agent's agent cluster's cross-origin isolation mode is "concrete".

          20. +
          21. Set worker global scope's cross-origin isolated + capability to true if agent's agent cluster's cross-origin isolation mode is "concrete".

          22. -
          23. If is shared is false and owner's cross-origin isolated - capability is false, then set worker global scope's cross-origin isolated - capability to false.

          24. +
          25. If is shared is false and owner's cross-origin isolated + capability is false, then set worker global scope's cross-origin isolated + capability to false.

          26. -
          27. -

            If is shared is false and response's - url's scheme is "data", then set - worker global scope's cross-origin isolated - capability to false.

            - -

            This is a conservative default for now, while we figure out how workers in - general, and data: URL workers in particular (which are - cross-origin from their owner), will be treated in the context of permissions policies. See - w3c/webappsec-permissions-policy - issue #207 for more details.

            -
          28. +
          29. +

            If is shared is false and response's + url's scheme is "data", then set + worker global scope's cross-origin isolated + capability to false.

            + +

            This is a conservative default for now, while we figure out how workers in + general, and data: URL workers in particular (which are + cross-origin from their owner), will be treated in the context of permissions policies. See + w3c/webappsec-permissions-policy + issue #207 for more details.

            +
          30. -
          31. Run processCustomFetchResponse with response.

          32. +
          33. Run processCustomFetchResponse with response and + bytesOrNull.

          34. +
          +

        In both cases, let onComplete given script be the following steps:

        @@ -106326,8 +106359,10 @@ dictionary WorkletOptions {

        A Worklet has a module responses map, which is an ordered map from URLs to - responses, initially empty. Access to this map should be - thread-safe.

        + either "fetching" or tuples consisting of a + response and either null, failure, or a byte + sequence representing the response body. This map is initially empty, and access to it + should be thread-safe.

        The added modules list and Date: Thu, 27 Oct 2022 17:59:34 +0200 Subject: [PATCH 2/7] Review by Domenic --- source | 85 ++++++++++++++++++++++++++++++---------------------------- 1 file changed, 44 insertions(+), 41 deletions(-) diff --git a/source b/source index 1f8d9321af5..7707bb4f4ea 100644 --- a/source +++ b/source @@ -14751,7 +14751,7 @@ interface HTMLLinkElement : HTMLElement {

        Fetch request with processResponseConsumeBody set to the following steps given response response and null, failure, or - a byte sequence bytesOrNull:

        + a byte sequence bodyBytes:

        1. Finalize and report timing with response, @@ -14764,7 +14764,7 @@ interface HTMLLinkElement : HTMLElement {

          If either of the following conditions are met:

            -
          • bytesOrNull is null or failure; or

          • +
          • bodyBytes is null or failure; or

          • response's status is not an ok status,

          • @@ -14787,9 +14787,9 @@ interface HTMLLinkElement : HTMLElement { be fetched and processed, with the expectation that this will be done correctly.

            - -
          • Process the linked resource given el, success, and - response.

          • + +
          • Process the linked resource given el, success, + response, and bodyBytes.

    @@ -14845,9 +14845,10 @@ interface HTMLLinkElement : HTMLElement {

    Similar to the fetch and process the linked resource algorithm, all external resource links have a process the linked resource algorithm which takes a link element el, boolean - success, and response response. - Individual link types may provide their own process the linked resource algorithm, - but unless explicitly stated, that algorithm does nothing.

    + success, a response response, and a + byte sequence bodyBytes. Individual link types may provide their own + process the linked resource algorithm, but unless explicitly stated, that algorithm + does nothing.

    Unless otherwise specified for a given rel keyword, the element must delay the load event of the element's node document until @@ -25562,15 +25563,16 @@ document.body.appendChild(wbr);

    To process this type of linked resource given - a link element el, boolean success, and response response:

    + a link element el, boolean success, response response, and byte sequence + bodyBytes:

    1. If response's Content-Type metadata is not a JSON MIME type, then set success to false.

    2. -
    3. If success is true, then process the manifest given el - and response.

    4. +
    5. If success is true, then process the manifest given el, + response, and bodyBytes.

    The process a link header steps for this type of linked resource are to do @@ -26223,13 +26225,13 @@ document.body.appendChild(wbr);

    Fetch request, with processResponseConsumeBody set to the following steps given a response response and null, failure, - or a byte sequence bytesOrNull:

    + or a byte sequence bodyBytes:

    1. -

      If bytesOrNull is a byte sequence, then set response's +

      If bodyBytes is a byte sequence, then set response's body to the first return value of safely extracting bytesOrNull.

      + data-x="body safely extract">safely extracting bodyBytes.

      By using processResponseConsumeBody, we have extracted the entire link element is currently render-blocking.

      To process this type of linked resource - given a link element el, boolean success, and response response, the user agent must run these - steps:

      + given a link element el, boolean success, response response, and byte sequence + bodyBytes, the user agent must run these steps:

    2. Process the linked resource given el, success, response, and bodyBytes.

    From d9c9596dc7695ef7baa8a9d1f1ae6138729ef526 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Ribaudo?= Date: Thu, 27 Oct 2022 18:54:00 +0200 Subject: [PATCH 5/7] Remove note about sync hook, since service workers will do it async --- source | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/source b/source index 71e57c0458e..731d9bff4d0 100644 --- a/source +++ b/source @@ -93281,12 +93281,10 @@ document.querySelector("button").addEventListener("click", bound);
  • -

    If respnse is null, pause until it is not null.

    +

    Pause until response is not null.

    Unlike other algorithms in this section, the fetching process is synchronous - here. If performFetch was given and it synchronously runs processResponseConsumeBody, response will - already be not null without pausing.

    + here.

  • Finalize and report timing with response, settings From 00b1401c4b61aadd2558e86cc10f04f629db5ed4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Ribaudo?= Date: Fri, 28 Oct 2022 16:19:16 +0200 Subject: [PATCH 6/7] Review by Domenic --- source | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/source b/source index 731d9bff4d0..475d993551e 100644 --- a/source +++ b/source @@ -2206,6 +2206,7 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute

  • tuple
  • noncharacter
  • byte sequence
  • +
  • as a body
  • string, code unit, code unit prefix, @@ -26229,8 +26230,8 @@ document.body.appendChild(wbr);
    1. If bodyBytes is a byte sequence, then set response's - body to the first return value of safely extracting bodyBytes.

      + body to bodyBytes as a + body.

      By using processResponseConsumeBody, we have extracted the entire

      To process this type of linked resource given a link element el, boolean success, response response, and byte sequence - bodyBytes, the user agent must run these steps:

      + bodyBytes: