diff --git a/source b/source index c50fd94f57e..5d53e5da021 100644 --- a/source +++ b/source @@ -86253,11 +86253,20 @@ interface NavigatorOnLine { script">module scripts; or null. In the former two cases, it represents a parsed script; null represents a failure parsing.

-
A parse - error
+
An error
-

A JavaScript value, which has meaning only if the record is null.

+
+

A JavaScript value representing an error that will prevent evaluation from succeeding. It + will be re-thrown by any attempts to run the script.

+ +

There are two main categories of such errors: errors parsing the script's source + text, in which case the script's record will + be null; or more general errors in dependencies of a module script. This + distinction is used by the algorithm for finding the first parse error.

+ +

Since this exception value is provided by the JavaScript specification, we know + that it is never null, so we use null to signal that no error has occurred.

+
@@ -86316,41 +86325,6 @@ interface NavigatorOnLine { -

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

- -

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

- -

To set the pre-instantiation - error of a module script script:

- -
    -
  1. Let moduleRecord be script's record.

  2. - -
  3. If moduleRecord is not null, set moduleRecord.[[HostDefined]] to - undefined.

  4. - -
  5. Set script's record to - null.

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

  8. -
- -

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

-

An environment is an object that identifies the settings of a @@ -86781,13 +86755,6 @@ interface NavigatorOnLine { module script">fetching a single module script asynchronously completes with result:

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

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

  • -
  • If the top-level module fetch flag is set, fetch the descendants of and instantiate result given destination and visited set. Otherwise, @@ -86898,9 +86865,8 @@ interface NavigatorOnLine { success).

      -
    1. If module script is - errored or has instantiated, - asynchronously complete this algorithm with module script, and abort these +

    2. If module script's record is null, + then asynchronously complete this algorithm with module script and abort these steps.

    3. Let record be module script's NavigatorOnLine {

      These invocations of the internal module script graph fetching procedure should be performed in parallel to each other.

      -

      Wait for all invocations of the internal module script graph fetching procedure - to asynchronously complete, and let results be a list of the results, - corresponding to the same order they appeared in urls. Then, for each result of results:

      - -
        -
      1. If result is null, asynchronously complete this algorithm with null, aborting - these steps.

      2. - -
      3. If result is errored, - then set the pre-instantiation - error for module script to result's error. Asynchronously complete this algorithm with - module script, aborting these steps.

      4. -
      - -
      -

      It is important to wait for all invocations to complete, and then iterate the results in - order, so that any fetching or pre-instantiation errors are deterministically surfaced to the - developer. Otherwise, a module script graph with multiple errors would surface a - nondeterministically chosen error, making debugging quite difficult.

      - -

      As an unobservable optimization, implementations can quit early if an invocation returns - null or an errored module - script, and all previous invocations have completed already. However, this is optimizing - for the rare failure case, so likely not worth the trouble.

      -
      +

      If any of the invocations of the internal module script graph fetching procedure + asynchronously complete with null, asynchronously complete this algorithm with null, aborting + these steps.

      -

      If we've reached this point, all of the internal module script graph fetching - procedure invocations have asynchronously completed, with module scripts that are not errored. Asynchronously complete this algorithm - with module script.

      +

      Otherwise, wait until all of the internal module script graph fetching procedure + invocations have asynchronously completed. Asynchronously complete this algorithm with + module script.

    @@ -87006,30 +86946,100 @@ interface NavigatorOnLine { completes with result.

  • -

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

    +

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

    -

    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.

    +

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

  • -
  • Let record be result's record.

  • +
  • Let parse error be the result of finding the first parse error + given result.

  • + +
  • If parse error is not null, then set result's error to parse error.

  • -

    Perform record.Instantiate().

    +

    Otherwise:

    + +
      +
    1. Let record be result's record.

    2. + +
    3. +

      Perform record.Instantiate().

      -

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

      +

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

      -

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

      +

      If this throws an exception, set result's error to that exception.

      +
    4. +
  • Asynchronously complete this algorithm with result.

  • +

    To find the first parse error given a root + moduleScript and an optional discoveredSet:

    + +
      +
    1. Let moduleMap be moduleScript's settings object's + module map.

    2. + +
    3. If discoveredSet was not given, let it be an empty set.

    4. + +
    5. Append moduleScript to + discoveredSet.

    6. + +
    7. +

      If moduleScript's record is null, + then return moduleScript's error.

      + +

      It's important that we check if moduleScript's record is null, and not simply check that + moduleScript's error is non-null. This + ensures we only catch errors from parsing moduleScript, and not instantiation errors + or errors from parsing its dependencies that were stored in the error field for later re-throwing.

      +
    8. + +
    9. Let childSpecifiers be the value of moduleScript's record's [[RequestedModules]] internal slot.

    10. + +
    11. Let childURLs be the list obtained by calling resolve a + module specifier once for each item of childSpecifiers, + given moduleScript and that item. (None of these will ever fail, as otherwise + moduleScript would have been marked as itself having a parse error.)

    12. + +
    13. Let childModules be the list obtained by getting each value in moduleMap whose key is given by an + item of childURLs.

    14. + +
    15. +

      For each childModule of + childModules:

      + +
        +
      1. Assert: childModule is a module script (i.e., it is not "fetching" or null); by now all module + scripts in the graph rooted at moduleScript will have successfully been + fetched.

      2. + +
      3. If discoveredSet already contains + childModule, continue.

      4. + +
      5. Let childParseError be the result of finding the first parse + error given childModule and discoveredSet.

      6. + +
      7. If childParseError is not null, return childParseError.

      8. +
      +
    16. + +
    17. Return null.

    18. +
    +
    Creating scripts

    To create a classic script, given a @@ -87060,10 +87070,10 @@ interface NavigatorOnLine {

  • If result is a List of errors, then set script's parse error to result[0].

  • + data-x="concept-script-error">error to result[0].

  • Otherwise, set script's record to - result.

  • + result and its error to null.

  • Return script.

  • @@ -87099,7 +87109,7 @@ interface NavigatorOnLine {

    If result is a List of errors, then:

      -
    1. Set script's parse error to +

    2. Set script's error to result[0].

    3. Return script.

    4. @@ -87120,8 +87130,8 @@ interface NavigatorOnLine {
      1. Let error be a new TypeError exception.

      2. -
      3. Set script's parse error - to error.

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

      6. Return script.

      @@ -87137,6 +87147,8 @@ interface NavigatorOnLine {
    5. Set script's record to result.

    6. +
    7. Set script's error to null.

    8. +
    9. Set script's base URL to baseURL.

    10. @@ -87169,10 +87181,10 @@ interface NavigatorOnLine {
    11. Let evaluationStatus be null.

    12. -
    13. If script's parse error is not +

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

    15. + script's error, [[Target]]: empty + }.

    16. Otherwise, set evaluationStatus to NavigatorOnLine {

    17. Let evaluationStatus be null.

    18. -
    19. If script is errored, - then set evaluationStatus to Completion { [[Type]]: throw, [[Value]]: - script's error, [[Target]]: - empty }.

    20. +
    21. If script's error is not + null, then set evaluationStatus to Completion { [[Type]]: throw, [[Value]]: + script's error, [[Target]]: empty + }.

    22. Otherwise:

      @@ -88140,8 +88152,8 @@ import "https://example.com/foo/../module2.js";
    23. Assert: resolved module script is a module script (i.e., is not null or "fetching").

    24. -
    25. Assert: resolved module script is not errored.

      +
    26. Assert: resolved module script's record is not null.

    27. Return resolved module script's record.