From eb9e34a2ac4e2f1d45e83984cadf86a50b6b6a16 Mon Sep 17 00:00:00 2001 From: Daniel Ehrenberg Date: Sun, 10 Feb 2019 02:49:19 +0100 Subject: [PATCH 1/4] Top-level await integration The purpose of this patch is to nail down how HTML would adjust to the needs of top-level await. The relevant change is, the module.Evaluate() method will return a Promise that resolves when the module is ready. --- source | 65 +++++++++++++++++++++++++--------------------------------- 1 file changed, 28 insertions(+), 37 deletions(-) diff --git a/source b/source index 2529743aa6e..c26f8b330ff 100644 --- a/source +++ b/source @@ -2653,6 +2653,8 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute sequence of Unicode scalar values
  • overload resolution algorithm
  • exposed
  • +
  • a promise rejected with
  • +
  • upon rejection
  • [LegacyFactoryFunction]
  • [LegacyLenientThis]
  • [LegacyNullToEmptyString]
  • @@ -2866,6 +2868,9 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute

    Users agents that support JavaScript must also implement ECMAScript Internationalization API.

    + +

    User agents that support JavaScript must also implement the top-level await + proposal.

    @@ -90435,10 +90440,10 @@ document.querySelector("button").addEventListener("click", bound);

    To run a module script given a module script script, - with an optional rethrow errors boolean:

    + with an optional report errors boolean:

      -
    1. If rethrow errors is not given, let it be false.

    2. +
    3. If report errors is not given, let it be true.

    4. Let settings be the settings object of script.

    5. @@ -90447,12 +90452,10 @@ document.querySelector("button").addEventListener("click", bound);
    6. Prepare to run script given settings.

    7. -
    8. Let evaluationStatus be null.

    9. -
    10. If script's error to - rethrow is not null, then set evaluationStatus to Completion { [[Type]]: throw, - [[Value]]: script's error to - rethrow, [[Target]]: empty }.

    11. + rethrow is not null, then let evaluationPromise be a promise rejected + with script's error to + rethrow.

    12. Otherwise:

      @@ -90462,35 +90465,26 @@ document.querySelector("button").addEventListener("click", bound); data-x="concept-script-record">record.

    13. -

      Set evaluationStatus to record.Let evaluationPromise be record.Evaluate().

      This step will recursively evaluate all of the module's dependencies.

      If Evaluate fails to complete as a result of the user agent - aborting the running script, then set - evaluationStatus to Completion { [[Type]]: throw, [[Value]]: a new - "QuotaExceededError" DOMException, [[Target]]: empty - }.

      + aborting the running script, then let + evaluationPromise be a promise rejected with a new + "QuotaExceededError" DOMException.

    -
  • -

    If evaluationStatus is an abrupt completion, then:

    - -
      -
    1. If rethrow errors is true, rethrow the exception given by - evaluationStatus.[[Value]].

    2. - -
    3. Otherwise, report the exception given by - evaluationStatus.[[Value]] for script.

    4. -
    -
  • +
  • If report errors is true, then upon rejection of + evaluationPromise with reason, report the exception given by + reason for script.

  • Clean up after running script with settings.

  • -
  • Return evaluationStatus.

  • +
  • Return evaluationPromise.

  • The steps to check if we can run script with an environment settings @@ -91245,26 +91239,20 @@ import "https://example.com/foo/../module2.mjs";

    If result is null, then:

      -
    1. Let completion be Completion { [[Type]]: throw, [[Value]]: a new - TypeError, [[Target]]: empty }.

    2. +
    3. Let promise be a promise rejected with a new TypeError.

    4. Perform FinishDynamicImport(referencingScriptOrModule, - specifier, promiseCapability, completion).

    5. + specifier, promiseCapability, promise).

      -
    6. Return.

    7. +
    8. Return undefined.

    -
  • Run the module script result, with - the rethrow errors boolean set to true.

  • +
  • Let promise be the result of running a + module script given result and false.

  • -
  • If running the module script throws an exception, then perform - FinishDynamicImport(referencingScriptOrModule, specifier, - promiseCapability, the thrown exception completion).

  • - -
  • Otherwise, perform - FinishDynamicImport(referencingScriptOrModule, specifier, - promiseCapability, NormalCompletion(undefined)).

  • +
  • Perform FinishDynamicImport(referencingScriptOrModule, + specifier, promiseCapability, promise).

  • Return undefined.

  • @@ -123109,6 +123097,9 @@ INSERT INTERFACES HERE
    [JSINTL]
    ECMAScript Internationalization API Specification. Ecma International.
    +
    [JSTLA]
    +
    Top Level Await. Ecma International.
    +
    [JSON]
    The JavaScript Object Notation (JSON) Data Interchange Format, T. Bray. IETF.
    From d7d09934aca9cd31e1c4b9cda411a1c374fec5e0 Mon Sep 17 00:00:00 2001 From: Domenic Denicola Date: Mon, 12 Oct 2020 14:58:56 -0400 Subject: [PATCH 2/4] Fix promise return value --- source | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source b/source index c26f8b330ff..5a839c93fe9 100644 --- a/source +++ b/source @@ -90448,7 +90448,7 @@ document.querySelector("button").addEventListener("click", bound);
  • Let settings be the settings object of script.

  • Check if we can run script with settings. If this returns "do - not run" then return NormalCompletion(empty).

  • + not run", then return a promise resolved with undefined.

  • Prepare to run script given settings.

  • From d4c51cee3e1a1366abdb076dc2355ade8cd4fce9 Mon Sep 17 00:00:00 2001 From: Domenic Denicola Date: Mon, 12 Oct 2020 15:08:52 -0400 Subject: [PATCH 3/4] Tweaks - Link "a promise rejected with" more consistently - Change optional boolean argument handling to be consistent with https://infra.spec.whatwg.org/#algorithm-params --- source | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/source b/source index 5a839c93fe9..d76bf5327b3 100644 --- a/source +++ b/source @@ -90358,11 +90358,9 @@ document.querySelector("button").addEventListener("click", bound);
    Calling scripts

    To run a classic script given a classic script script - and an optional rethrow errors boolean:

    + and an optional boolean rethrow errors (default false):

      -
    1. If rethrow errors is not given, let it be false.

    2. -
    3. Let settings be the settings object of script.

    4. Check if we can run script with settings. If this returns "do @@ -90439,12 +90437,10 @@ document.querySelector("button").addEventListener("click", bound);

    -

    To run a module script given a module script script, - with an optional report errors boolean:

    +

    To run a module script given a module script script + and an optional boolean preventErrorReporting (default false):

      -
    1. If report errors is not given, let it be true.

    2. -
    3. Let settings be the settings object of script.

    4. Check if we can run script with settings. If this returns "do @@ -90472,13 +90468,13 @@ document.querySelector("button").addEventListener("click", bound);

      If Evaluate fails to complete as a result of the user agent aborting the running script, then let - evaluationPromise be a promise rejected with a new + evaluationPromise be a promise rejected with a new "QuotaExceededError" DOMException.

    -
  • If report errors is true, then upon rejection of +

  • If preventErrorReporting is false, then upon rejection of evaluationPromise with reason, report the exception given by reason for script.

  • @@ -91239,7 +91235,8 @@ import "https://example.com/foo/../module2.mjs";

    If result is null, then:

      -
    1. Let promise be a promise rejected with a new TypeError.

    2. +
    3. Let promise be a promise rejected with a new + TypeError.

    4. Perform FinishDynamicImport(referencingScriptOrModule, specifier, promiseCapability, promise).

    5. @@ -91249,7 +91246,7 @@ import "https://example.com/foo/../module2.mjs";
    6. Let promise be the result of running a - module script given result and false.

    7. + module script given result and true.

    8. Perform FinishDynamicImport(referencingScriptOrModule, specifier, promiseCapability, promise).

    9. From 714a7e710d0a871477fd2143edf9d1dfe4f2af5d Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Thu, 19 Nov 2020 14:17:51 +0100 Subject: [PATCH 4/4] Fix review comments. --- source | 33 +++++++++++++-------------------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/source b/source index d76bf5327b3..5b48e3cb727 100644 --- a/source +++ b/source @@ -2869,7 +2869,7 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute

      Users agents that support JavaScript must also implement ECMAScript Internationalization API.

      -

      User agents that support JavaScript must also implement the top-level await +

      User agents that support JavaScript must also implement the Top-Level Await proposal.

      @@ -90448,8 +90448,10 @@ document.querySelector("button").addEventListener("click", bound);
    10. Prepare to run script given settings.

    11. +
    12. Let evaluationPromise be null.

    13. +
    14. If script's error to - rethrow is not null, then let evaluationPromise be a promise rejected + rethrow is not null, then set evaluationPromise to a promise rejected with script's error to rethrow.

    15. @@ -90461,14 +90463,14 @@ document.querySelector("button").addEventListener("click", bound); data-x="concept-script-record">record.

    16. -

      Let evaluationPromise be record.Set evaluationPromise to record.Evaluate().

      This step will recursively evaluate all of the module's dependencies.

      If Evaluate fails to complete as a result of the user agent - aborting the running script, then let - evaluationPromise be a promise rejected with a new + aborting the running script, then set + evaluationPromise to a promise rejected with a new "QuotaExceededError" DOMException.

    @@ -91231,22 +91233,13 @@ import "https://example.com/foo/../module2.mjs"; URL, settings object, and fetch options. Wait until the algorithm asynchronously completes with result.

    -
  • -

    If result is null, then:

    - -
      -
    1. Let promise be a promise rejected with a new - TypeError.

    2. +
    3. Let promise be null. -

    4. Perform FinishDynamicImport(referencingScriptOrModule, - specifier, promiseCapability, promise).

    5. - -
    6. Return undefined.

    7. -
    -
  • +
  • If result is null, then set promise to a promise rejected + with a new TypeError.

  • -
  • Let promise be the result of running a - module script given result and true.

  • +
  • Otherwise, set promise to the result of running a module script given result and true.

  • Perform FinishDynamicImport(referencingScriptOrModule, specifier, promiseCapability, promise).

  • @@ -123095,7 +123088,7 @@ INSERT INTERFACES HERE
    ECMAScript Internationalization API Specification. Ecma International.
    [JSTLA]
    -
    Top Level Await. Ecma International.
    +
    Top-Level Await. Ecma International.
    [JSON]
    The JavaScript Object Notation (JSON) Data Interchange Format, T. Bray. IETF.