diff --git a/source b/source index 8f5faa6d09f..5856b214772 100644 --- a/source +++ b/source @@ -85853,7 +85853,7 @@ interface NavigatorOnLine {

A Source Text Module Record representing the parsed module, ready to be - evaluated.

+ evaluated, or null if there was a parsing error.

@@ -85868,24 +85868,12 @@ interface NavigatorOnLine { -
A state
- -
- -

One of "uninstantiated", "errored", or "instantiated", used to prevent reinvocation of ModuleDeclarationInstantiation on modules that - failed to instantiate previously, and to ensure errors during parsing, instantiation, or - evaluation are remembered and propagated correctly.

- -
- -
An error
+
A parse error

A JavaScript value, which has meaning only if the state is "errored".

+ data-x="concept-module-script-module-record">module record is null.

@@ -85918,32 +85906,23 @@ interface NavigatorOnLine { -

To error a module script script with a given value error, - perform the following steps:

- -
    -
  1. Assert: script's state is not - "errored".

  2. - -
  3. -

    If script's module - record is set, then:

    - -
      -
    1. Set script module - record's [[HostDefined]] field to undefined.

    2. +

      We say that a module script is + errored if either its module + record is null, or its module + record's [[Status]] field has the value "errored".

      -
    3. Set script's module - record to null.

    4. -
    -
  4. +

    When a module script is + errored, we say that its error is either + its parse error, when its module record is null, or its module record's [[ErrorCompletion]] field's + [[Value]] field, otherwise.

    -
  5. Set script's state to - "errored".

  6. - -
  7. Set script's error to - error.

  8. -
+

We say that a module script has instantiated if its module record is not null, and its module record's [[Status]] field is either + "instantiated" or "evaluated".


@@ -86376,23 +86355,22 @@ interface NavigatorOnLine { module script">fetching a single module script asynchronously completes with result:

-
  • If result is null, asynchronously complete this algorithm with null and abort - these steps.

  • - -
  • If result's state is "instantiated" or "errored", asynchronously complete this - algorithm with result, and abort these steps.

  • +
  • If result is null, is + errored, or has instantiated, + asynchronously complete this algorithm with result, and abort these steps.

  • -
  • Assert: result's state is - "uninstantiated".

  • +
  • Assert: result's module + record's [[Status]] is "uninstantiated".

  • -
  • Fetch the - descendants of and instantiate result given destination and an - ancestor list obtained by appending url to ancestor list.

  • +
  • If the top-level module fetch flag is set, fetch the descendants of and instantiate + result given destination and an ancestor list obtained by appending + url to ancestor list. Otherwise, fetch the descendants of result given the same + arguments.

  • -
  • When the fetch the descendants of and instantiate a module script algorithm - asynchronously completes with final result, asynchronously complete this algorithm - with final result.

  • +
  • When the appropriate algorithm asynchronously completes with final result, + asynchronously complete this algorithm with final result.

  • To fetch a single module script, given a url, a fetch client @@ -86490,20 +86468,18 @@ interface NavigatorOnLine { -

    To fetch the descendants of and instantiate a module script module - script, given a destination and an optional ancestor list, run these - steps. The algorithm will asynchronously complete with either null (on failure) or with - module script (on success).

    +

    To fetch the descendants of a module script module script, given a + destination and an optional ancestor list, run these steps. The algorithm + will asynchronously complete with either null (on failure) or with module script (on + success).

    1. If ancestor list was not given, let it be the empty list.

    2. -
    3. If module script's state is - "instantiated" or "errored", asynchronously - complete this algorithm with module script, and abort these steps.

    4. - -
    5. Assert: module script's state - is "uninstantiated".

    6. +
    7. If module script is + errored or has instantiated, + asynchronously complete this algorithm with module script, and abort these + steps.

    8. Let record be module script's module record.

    9. @@ -86521,28 +86497,17 @@ interface NavigatorOnLine {
    10. Let url be the result of resolving a module specifier given module script and requested.

    11. -
    12. -

      If url is failure:

      - -
        -
      1. Let error be a new TypeError exception.

      2. - -
      3. Error module script with - error.

      4. - -
      5. Abort this algorithm, and asynchronously complete it with module - script.

      6. -
      -
    13. +
    14. Assert: url is never failure, because resolving a module specifier must have been previously successful with these same two + arguments.

    15. -
    16. Otherwise, if ancestor list does not contain url, append - url to urls.

    17. +
    18. If ancestor list does not contain + url, append url to + urls.

    -
  • Let descendants result be null.

  • -
  • For each url in urls, perform the internal module script graph fetching procedure given url, module @@ -86560,132 +86525,61 @@ interface NavigatorOnLine { be performed in parallel to each other.

    If any invocation of the internal module script graph fetching procedure - asynchronously completes with null, then optionally abort all other invocations, set - descendants result to null, and proceed to the next step. (The un-fetched descendant - will cause errors during instantiation.)

    + asynchronously completes with null, then optionally abort all other invocations and + asynchronously complete this algorithm with null.

    -

    If any invocation of the internal module script graph fetching procedure - asynchronously completes with a module script whose state is "errored", then - optionally abort all other invocations, set descendants result to module - script, and proceed to the next step. (The errored descendant will cause errors during - instantiation.)

    +

    Otherwise, if any invocation of the internal module script graph fetching + procedure asynchronously completes with a module script that is errored, then optionally abort all other + invocations, and asynchronously complete this algorithm with module script.

    Otherwise, wait for all of the internal module script graph fetching procedure invocations to asynchronously complete, with module scripts - whose states are not "errored". Then, set descendants result to module script, - and proceed to the next step.

    -
  • - -
  • -

    Let instantiationStatus be record.ModuleDeclarationInstantiation().

    - -

    This step will recursively call ModuleDeclarationInstantiation all of the - module's uninstantiated dependencies.

    -
  • - -
  • -

    For each script in module script's uninstantiated inclusive - descendant module scripts, perform the following steps:

    - -
      -
    1. If instantiationStatus is an abrupt completion, then error script with - instantiationStatus.[[Value]].

    2. - -
    3. Otherwise, set script's state to "instantiated".

    4. -
    -
  • - -
  • -

    Asynchronously complete this algorithm with descendants result.

    - -

    It is intentional that we complete with descendants result here, and - not module script, as this allows us to notify the caller of fetching errors.

    + that are not errored. Then, + asynchronously complete this algorithm with module script.

  • -

    In the above algorithm, a module script script's uninstantiated - inclusive descendant module scripts is a set of module scripts determined as follows:

    +

    To fetch the descendants of and instantiate a module script module + script, given a destination and an optional ancestor list, run these + steps. The algorithm will asynchronously complete with either null (on failure) or with + module script (on success).

      -
    1. If script's module - record is null, return the empty set.

    2. - -
    3. Let moduleMap be script's settings object's - module map.

    4. +
    5. Fetch the descendants of + module script, given destination and ancestor list.

    6. -
    7. Let stack be the stack « script ».

    8. - -
    9. Let inclusive descendants be an empty set.

    10. +
    11. Return from this algorithm, and run the following steps when fetching the descendants of a module script asynchronously + completes with result.

    12. -

      While stack is not empty:

      - -
        -
      1. Let current the result of popping from - stack.

      2. - -
      3. Assert: current is a module script (i.e., it is not "fetching" or null).

      4. - -
      5. -

        If inclusive descendants and stack both do not contain current, then:

        - -
          -
        1. Append current to - inclusive descendants.

        2. +

          If result is null or is + errored, then asynchronously complete this algorithm with result.

          -
        3. Let child specifiers be the value of current's module record's [[RequestedModules]] - internal slot.

        4. - -
        5. Let child URLs be the list obtained by calling - resolve a module specifier once for each item of child specifiers, - given current and that item. Omit any failures.

        6. - -
        7. Let child modules be the list obtained by getting each value in moduleMap whose key is given by an - item of child URLs.

        8. - -
        9. -

          For each s of child modules:

          +

          In this case, there was an error fetching the descendants, or one of them + failed to parse, or was previously marked as errored. We will not attempt to instantiate.

          +
        10. -
            -
          1. If inclusive descendants already contains s, continue.

          2. +
          3. Let record be result's module record.

          4. -
          5. If s is null, continue.

          6. +
          7. +

            Perform record.ModuleDeclarationInstantiation().

            -
          8. Assert: s is a module script (i.e., it is not - "fetching", since by this point all child modules must have been - fetched).

          9. +

            This step will recursively call ModuleDeclarationInstantiation all of the + module's uninstantiated dependencies.

            -
          10. Push s onto stack.

          11. -
          -
        -
      6. -
      +

      If this throws an exception, ignore it for now; it is stored as result's error, and will be reported when we run result.

    13. -
    14. Return a set containing all items of inclusive descendants whose - state is "uninstantiated".

    15. +
    16. Asynchronously complete this algorithm with result.

    -

    The above algorithm gives a depth-first search of the module dependency graph. The - main interesting part is in how the "edges" of this graph are determined. The actual search - implementation is not important; any other technique for exploring the graph will suffice, given - that the output is a set only used for membership testing and whose order is thus not - important.

    -
    Creating scripts

    To create a classic script, given some script @@ -86721,7 +86615,8 @@ interface NavigatorOnLine {

    1. Let script be a new module script that this algorithm will - subsequently initialize.

    2. + subsequently initialize, with its module + record initially set to null.

    3. Set script's settings object to the environment settings object provided.

    4. @@ -86747,15 +86642,42 @@ interface NavigatorOnLine {

      If result is a List of errors, then:

        -
      1. Error script with - errors[0].

      2. +
      3. Set script's parse + error to errors[0].

      4. Return script.

      -
    5. Set script's state to "uninstantiated".

    6. +
    7. +

      For each string requested of + record.[[RequestedModules]]:

      + +
        +
      1. Let url be the result of resolving + a module specifier given module script and requested.

      2. + +
      3. +

        If url is failure:

        + +
          +
        1. Let error be a new TypeError exception.

        2. + +
        3. Set record's [[HostDefined]] field to undefined.

        4. + +
        5. Set script's parse + error to error.

        6. + +
        7. Return script.

        8. +
        +
      4. +
      + +

      This step is essentially validating all of the requested module specifiers. We + treat a module with unresolvable module specifiers the same as one that cannot be parsed; in + both cases, a syntactic issue makes it impossible to ever contemplate instantiating the module + later.

      +
    8. Set script's module record to result.

    9. @@ -86853,20 +86775,15 @@ interface NavigatorOnLine {
    10. Check if we can run script with settings. If this returns "do not run" then abort these steps.

    11. -
    12. If s's state is "errored", then report the exception given by s's error for s and abort these - steps.

    13. +
    14. If s is errored, then + report the exception given by s's error and abort these steps.

    15. -
    16. Assert: s's state is "instantiated" (and thus its module record is not null).

    17. +
    18. Prepare to run script given settings.

    19. Let record be s's module record.

      -
    20. Prepare to run script given settings.

    21. -
    22. Let evaluationStatus be record.ModuleEvaluation().

      @@ -86879,17 +86796,8 @@ interface NavigatorOnLine { "QuotaExceededError" DOMException, [[Target]]: empty }.
    23. -
    24. -

      If evaluationStatus is an abrupt completion, then:

      - -
        -
      1. Error script with - evaluationStatus.[[Value]].

      2. - -
      3. Report the exception given by evaluationStatus.[[Value]] for - s.

        -
      -
    25. +
    26. If evaluationStatus is an abrupt completion, then report the + exception given by evaluationStatus.[[Value]] for s.

    27. Clean up after running script with settings.

    @@ -87739,44 +87647,38 @@ import "https://example.com/foo/../module2.js"; specifier.

  • Assert: url is never failure, because resolving a module specifier must have been previously successful with these - same two arguments during the appropriate invocation of fetch the descendants of and - instantiate a module script.

  • + specifier">resolving a module specifier must have been previously successful with these + same two arguments.

  • Let resolved module script be moduleMap[url]. (This entry must exist for us to have gotten to this point.)

  • +
  • Assert: resolved module script is a module script (i.e., is not + null or "fetching").

  • +
  • -

    If resolved module script is null, then throw a TypeError - exception and abort these steps.

    +

    If resolved module script's module record is null, then throw + resolved module script's parse + error.

    -

    This occurs when we have previously tried to fetch url, and failed, but are now rediscovering that fact in a new - module script graph. For example, given a file module.js whose contents +

    This occurs when we have previously fetched url, but attempting to parse its + contents failed, and now a new module script graph also depends on that module script. For + example, given a file module.js whose contents are

    -
    import "./404.js";
    +
    import "./syntax-error.js";
    -

    then we could get here as part of fetching the - graph for the second script element in the following HTML:

    +

    then we could get here as part of instantiating the graph for the second script + element in the following HTML:

    -
    <script type="module" src="404.js"></script>
    +     
    <script type="module" src="syntax-error.js"></script>
     <script type="module" src="module.js"></script>
  • -
  • Assert: resolved module script is a module script (i.e., is not - "fetching").

  • - -
  • If resolved module script's state is "errored", then throw - resolved module script's error.

  • - -
  • Assert: resolved module script's module record is not null.

  • -
  • Return resolved module script's module record.