diff --git a/images/asyncdefer.svg b/images/asyncdefer.svg index 80da42c1cf5..8c22fc50bf4 100644 --- a/images/asyncdefer.svg +++ b/images/asyncdefer.svg @@ -1,4 +1,4 @@ - + - - - - - - + + + + + + + + + + @@ -89,35 +93,88 @@ - <script> - Scripting: - HTML Parser: - - - - - - - - <script defer> - Scripting: - HTML Parser: - - - - - - <script async> - Scripting: - HTML Parser: - - - - - - - - + + <script> + + + Scripting: + HTML Parser: + + + + + + + + + + + <script defer> + + + Scripting: + HTML Parser: + + + + + + + + + <script async> + + + Scripting: + HTML Parser: + + + + + + + + + + + <script type="module"> + + + Scripting: + HTML Parser: + + + + + + + + + + + + + + <script type="module" async> + + + Scripting: + HTML Parser: + + + + + + + + + + + + + + + parser @@ -128,5 +185,5 @@ execution - runtime → + runtime → diff --git a/source b/source index 27f442a0d79..e7988d0e8b1 100644 --- a/source +++ b/source @@ -2784,10 +2784,14 @@ a.setAttribute('href', 'http://example.com/'); // change the content attribute d -

...let the script block's type for this script element be +

...let the script block's type string for this script element be "text/javascript".

Otherwise, if the script element has a type attribute, let the script block's type for - this script element be the value of that attribute with any leading or trailing - sequences of space characters removed.

Otherwise, the element has a non-empty language - attribute; let the script block's type for this script element be the - concatenation of the string "text/" followed by the value of the language attribute.

+ attribute; let the script block's type string for this script element + be the concatenation of the string "text/" followed by the value of the + language attribute.

@@ -59533,9 +59788,22 @@ dictionary RelatedEventInit : EventInit { conforming, and is always ignored if there is a type attribute present.

-

Determine whether the the script block's type is an ASCII - case-insensitive match for any JavaScript MIME type. If this is not the - case, then the user agent must abort these steps at this point. No script is executed.

+

Determine the script's type as follows:

+ + @@ -59549,26 +59817,22 @@ dictionary RelatedEventInit : EventInit {
  • -

    The user agent must set the element's "already started" flag.

    - -

    The state of the element at this moment is later used to determine the script source.

    +

    Set the element's "already started" flag.

  • If the element is flagged as "parser-inserted", but the element's - node document is not the Document of the parser that created the element, - then abort these steps.

    + node document is not the Document of the parser that created the + element, then abort these steps.

  • If scripting is disabled for the script - element, then the user agent must abort these steps at this point. The script is not - executed.

    + element, then abort these steps at this point. The script is not executed.

    The definition of scripting is disabled means that, amongst others, the following scripts will not execute: scripts in @@ -59587,13 +59851,15 @@ dictionary RelatedEventInit : EventInit { data-x="attr-script-src">src content attribute, and the Should element's inline behavior be blocked by Content Security Policy? algorithm returns "Blocked" when executed upon the script element and "script", then the user agent must abort these steps. The script is not executed. -

  • + data-x="">script", then abort these steps. The script is not executed.

  • If the script element has an event - attribute and a for attribute, then run these substeps:

    + attribute and a for attribute, and the script's type is "classic", then + run these substeps:

      @@ -59607,13 +59873,13 @@ dictionary RelatedEventInit : EventInit { for.

    1. If for is not an ASCII case-insensitive match for the - string "window", then the user agent must abort these steps at this - point. The script is not executed.

    2. + string "window", then abort these steps at this point. The script is + not executed.

    3. If event is not an ASCII case-insensitive match for either the string "onload" or the string "onload()", then the user agent must abort these steps at this point. The script - is not executed.

    4. + data-x="">onload()", then abort these steps at this point. The script is not + executed.

    @@ -59622,19 +59888,25 @@ dictionary RelatedEventInit : EventInit {
  • If the script element has a charset - attribute, then let the script block's character - encoding for this script element be the result of getting an - encoding from the value of the charset - attribute.

    + attribute, then let encoding be the result of getting an encoding from + the value of the charset attribute.

    -

    Otherwise, let the script block's fallback - character encoding for this script element be the same as the encoding of the document itself.

    +

    If the script element does not have a charset attribute, or if getting an encoding + failed, let encoding be the same as the + encoding of the document itself.

    -

    Only one of these two pieces of state is set.

    +

    If the script's type is "module", this encoding will be ignored.

  • +
  • Let CORS setting be the current state of the element's crossorigin content attribute.

  • + +
  • Let settings be the element's node document's + Window object's environment settings object.

  • +
  • If the element has a src content attribute, run these @@ -59649,32 +59921,40 @@ dictionary RelatedEventInit : EventInit { a simple event named error at the element, and abort these steps.

  • +
  • Set the element's from an external file + flag.

  • +
  • Resolve src relative to the element.

  • If the previous step failed, queue a task to fire a simple event named error at the element, and abort these - steps.

  • + steps. Otherwise, let url be the resulting parsed URL.

    -
  • Let request be the result of creating a potential-CORS request given the - resulting parsed URL and the current state of the element's - crossorigin content attribute.

  • +
  • +

    Switch on the script's type:

    -
  • Set request's client to the - element's node document's Window object's environment settings - object and type to "script".

  • +
    +
    "classic"
    +
    +

    Fetch a classic script given url, CORS setting, + settings, and encoding.

    +
    -
  • -

    Fetch request.

    +
    "module"
    +
    +

    Fetch a module script tree given url, CORS setting, + and settings.

    +
    +
  • -

    The resource obtained in this fashion can be either CORS-same-origin or - CORS-cross-origin. This only affects how error reporting happens.

    +

    When the chosen algorithm asynchronously completes, set the script's script to the result. At that time, + the script is ready.

    -

    For performance reasons, user agents may start fetching the script (as defined above) as - soon as the src attribute is set, instead, in the hope - that the element will be inserted into the document (and that the For performance reasons, user agents may start fetching the classic script or module tree + (as defined above) as soon as the src attribute is set, + instead, in the hope that the element will be inserted into the document (and that the crossorigin attribute won't change value in the meantime). Either way, once the element is inserted into the document, the load must have started as described in this @@ -59691,59 +59971,92 @@ dictionary RelatedEventInit : EventInit { - +

  • -
  • +

    If the element does not have a src content attribute, + run these substeps:

    -

    Then, the first of the following options that describes the situation must be followed:

    +
      +
    1. Let source text be the value of the text IDL attribute.

    2. -
      +
    3. +

      Switch on the script's type:

      -
      If the element has a src - attribute, and the element has a defer attribute, and - the element has been flagged as "parser-inserted", and the element does not have - an async attribute
      +
      +
      "classic"
      +
      +
        +
      1. Let script be the result of creating a classic script using + source text and settings.

      2. -
        +
      3. Set the script's script to + script.

      4. -

        The element must be added to the end of the list of scripts that will execute when the - document has finished parsing associated with the Document of the parser - that created the element.

        +
      5. The script is ready.

      6. +
      +
      -

      The task that the networking task source - places on the task queue once fetching has completed must set the element's - "ready to be parser-executed" flag. The parser will handle executing the - script.

      +
      "module"
      +
      +
        +
      1. Let base URL be the script element's node + document's document base URL.

      2. -
      +
    4. Let script be the result of creating a module script using + source text, settings, base URL, and CORS + setting.

    5. +
    6. If this returns null, set the script's + script to null and abort these substeps; the script is ready.

    7. -
      If the element has a src attribute, and the element has been flagged as +
    8. Fetch the + descendants of script. When this asynchronously completes, set + the script's script to the result. At that + time, the script is ready.

    9. +
    + + +
  • + + + + + +
  • + +

    Then, follow the first of the following options that describes the situation:

    + +
    + +
    If the script's + type is "classic", and the element has a src attribute, and the element has a defer attribute, and the element has been flagged as "parser-inserted", and the element does not have an async attribute
    +
    If the script's type is "module", and + the element has been flagged as "parser-inserted", and the element does not have + an async attribute
    +
    -

    The element is the pending parsing-blocking script of the - Document of the parser that created the element. (There can only be one such - script per Document at a time.)

    +

    Add the element to the end of the list of scripts that will execute when the document + has finished parsing associated with the Document of the parser that + created the element.

    -

    The task that the networking task source - places on the task queue once fetching has completed must set the element's - "ready to be parser-executed" flag. The parser will handle executing the - script.

    +

    When the script is ready, set the element's "ready to be + parser-executed" flag. The parser will handle executing the script.

    - -
    If the element does not have a If the script's + type is "classic", and the element has a src attribute, and the element has been flagged as - "parser-inserted", and either the parser that created the script is - an XML parser or it's an HTML parser whose script nesting - level is not greater than one, and the Document of the HTML - parser or XML parser that created the script element has - a style sheet that is blocking scripts
    + "parser-inserted", and the element does not have an async attribute
    @@ -59751,26 +60064,29 @@ dictionary RelatedEventInit : EventInit { Document of the parser that created the element. (There can only be one such script per Document at a time.)

    -

    Set the element's "ready to be parser-executed" flag. The parser will handle - executing the script.

    +

    When the script is ready, set the element's "ready to be + parser-executed" flag. The parser will handle executing the script.

    +
    If the script's + type is "classic", and the element has a src attribute, and the element does not have an async attribute, and the element does not have the + "non-blocking" flag set
    -
    If the element has a src attribute, does not have an async attribute, and does not have the +
    If the script's + type is "module", and the element does not have an async attribute, and the element does not have the "non-blocking" flag set
    -

    The element must be added to the end of the list of scripts that will execute in order - as soon as possible associated with the node document of the script +

    Add the element to the end of the list of scripts that will execute in order as soon + as possible associated with the node document of the script element at the time the prepare a script algorithm started.

    -

    The task that the networking task source - places on the task queue once fetching has completed must run the following - steps:

    +

    When the script is ready, run the following steps:

      @@ -59794,27 +60110,51 @@ dictionary RelatedEventInit : EventInit {
    -
    If the element has a src - attribute
    +
    If the script's type + is "classic", and the element has a src attribute
    + +
    If the script's + type is "module"

    The element must be added to the set of scripts that will execute as soon as - possible of the node document of the script element at the time the - prepare a script algorithm started.

    + possible of the node document of the script element at the + time the prepare a script algorithm started.

    -

    The task that the networking task source - places on the task queue once fetching has completed must execute the - script block and then remove the element from the set of scripts that will - execute as soon as possible.

    +

    When the script is ready, execute the script block and then + remove the element from the set of scripts that will execute as soon as + possible.

    + +
    + + + +
    If the element does not have a src attribute, and the element has been flagged as + "parser-inserted", and either the parser that created the script is + an XML parser or it's an HTML parser whose script nesting + level is not greater than one, and the Document of the HTML + parser or XML parser that created the script element has + a style sheet that is blocking scripts
    + +
    + +

    The element is the pending parsing-blocking script of the + Document of the parser that created the element. (There can only be one such + script per Document at a time.)

    + +

    Set the element's "ready to be parser-executed" flag. The parser will handle + executing the script.

    Otherwise
    -
    The user agent must immediately execute the script block, even if other - scripts are already executing.
    +
    Immediately execute the script block, even if other scripts are + already executing.
    @@ -59822,12 +60162,6 @@ dictionary RelatedEventInit : EventInit { - -

    Fetching an external script must delay the load event of the element's node document - until the task that is queued - by the networking task source once the resource has been fetched (defined above) has - been run.

    -

    The pending parsing-blocking script of a Document is used by the Document's parser(s).

    @@ -59847,7 +60181,7 @@ dictionary RelatedEventInit : EventInit { defined in terms of which style sheets are blocking which scripts -->

    When the user agent is required to execute a script - block, it must run the following steps:

    + block, it must run the following steps.

      @@ -59861,293 +60195,117 @@ dictionary RelatedEventInit : EventInit {
    1. -

      Jump to the appropriate set of steps from the list below:

      - -
      - -
      If the load resulted in an error (for example a DNS error, or an HTTP 404 error)
      - -

      Executing the script block must just consist of firing - a simple event named error at the element.

      - -
      If the load was successful
      - - -
      - -

      Executing the script block must consist of running the following steps. For the purposes of - these steps, the script is considered to be from an external file if, while the - prepare a script algorithm above was running for this script, the - script element had a src attribute - specified.

      - -
        - -
      1. - -

        Initialise the script block's source - as follows:

        - -
        - -
        If the script is from an external file
        - -
        - -

        The contents of that file, interpreted as a Unicode string, are the script source.

        - -

        To obtain the Unicode string, the user agent run the following steps:

        - -
          - -
        1. If the resource's Content Type metadata, if any, - specifies a character encoding, and the user agent supports that encoding, then let character encoding be that encoding, and jump to the bottom step in this - series of steps.

        2. - -
        3. If the algorithm above set the script - block's character encoding, then let character encoding be - that encoding, and jump to the bottom step in this series of steps.

        4. - -
        5. Let character encoding be the script block's fallback character - encoding.

        6. - -
        7. - -

          Decode the file to Unicode, using character - encoding as the fallback encoding.

          - -

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

          - -
        8. - -
        - -
        - -
        If the script is inline
        - -
        - -

        The value of the text IDL attribute at the time - the element's "already started" flag was last set is the script source.

        - -
        - -
        - -
      2. - -
      3. - -

        Fire a simple event named beforescriptexecute that bubbles and is cancelable - at the script element.

        - -

        If the event is canceled, then abort these steps.

        - -
      4. - -
      5. - -

        If the script is from an external file, then increment the - ignore-destructive-writes counter of the script element's - node document. Let neutralised doc be that - Document.

        - -
      6. - -
      7. - -

        Let old script element be the value to which the script - element's node document's currentScript object was most recently - initialised.

        - -
      8. - -
      9. - -

        Initialise the script element's node document's currentScript object to the script - element.

        +

        If the script's script is null, fire a + simple event named error at the element, and abort + these steps.

        -
      10. + -
      11. + -

        Create a script, using the script - block's source, the URL from which the script was obtained, and the - environment settings object of the script element's node - document's Window object.

        +
      12. -

        If the script came from a resource that was fetched in the steps above, and the resource - was CORS-cross-origin, then pass the muted errors flag to the - create a script algorithm as well.

        +

        Fire a simple event named beforescriptexecute that bubbles and is cancelable + at the script element.

        -

        This is where the script is compiled and actually executed.

        +

        If the event is canceled, then abort these steps.

        -
      13. + -
      14. +
      15. -

        Initialise the script element's node document's currentScript object to old script - element.

        +

        If the script is from an external file, or + the script's type is "module", + then increment the ignore-destructive-writes counter of the script + element's node document. Let neutralised doc be that + Document.

        -
      16. + -
      17. +
      18. -

        Decrement the ignore-destructive-writes counter of neutralised doc, if it was incremented in the earlier step.

        +

        Let old script element be the value to which the script + element's node document's currentScript object was most recently + initialised.

        -
      19. + -
      20. +
      21. -

        Fire a simple event named afterscriptexecute that bubbles (but is not - cancelable) at the script element.

        +

        Initialise the script element's node document's currentScript object to the script + element.

        -
      22. + -
      23. +
      24. -

        If the script is from an external file, fire a simple event named load at the script element.

        +

        Let settings object be the environment settings object of the + script element's node document's Window object.

        -

        Otherwise, the script is internal; queue a task to fire a simple - event named load at the script - element.

        +
      25. - +
      26. -
      +

      Switch on the script's type:

      +
      +
      "classic"
      +
      +

      Run the classic script given by the script's script.

      +
      "module"
      +
      +

      Run the module script given by the script's script.

      +
    2. -
    - -

    The IDL attributes src, type, charset, defer, and nonce, must each reflect the respective - content attributes of the same name.

    - -

    The crossOrigin IDL attribute must - reflect the crossorigin content attribute.

    - -

    The async IDL attribute controls whether the - element will execute asynchronously or not. If the element's "non-blocking" flag is - set, then, on getting, the async IDL attribute must return - true, and on setting, the "non-blocking" flag must first be unset, and then the - content attribute must be removed if the IDL attribute's new value is false, and must be set to - the empty string if the IDL attribute's new value is true. If the element's - "non-blocking" flag is not set, the IDL attribute must reflect - the async content attribute.

    - - - - -
    - -
    script . text [ = value ]
    - -
    - -

    Returns the contents of the element, ignoring child nodes that aren't Text - nodes.

    - -

    Can be set, to replace the element's children with the given value.

    - -
    +
  • -
  • +

    Initialise the script element's node document's currentScript object to old script + element.

    -
    +
  • -

    The IDL attribute text must return a - concatenation of the contents of all the Text nodes that are children of the - script element (ignoring any other nodes such as comments or elements), in tree - order. On setting, it must act the same way as the textContent IDL attribute.

    +
  • - - +

    Decrement the ignore-destructive-writes counter of neutralised doc, if it was incremented in the earlier step.

    -

    When inserted using the document.write() - method, script elements execute (typically blocking further script execution or HTML parsing), but when inserted using - innerHTML and outerHTML - attributes, they do not execute at all.

    +
  • -
    +
  • -

    In this example, two script elements are used. One embeds an external script, and - the other includes some data.

    +

    Fire a simple event named afterscriptexecute that bubbles (but is not + cancelable) at the script element.

    -
    <script src="game-engine.js"></script>
    -<script type="text/x-game-map">
    -........U.........e
    -o............A....e
    -.....A.....AAA....e
    -.A..AAA...AAAAA...e
    -</script>
    +
  • -

    The data in this case might be used by the script to generate the map of a video game. The - data doesn't have to be used that way, though; maybe the map data is actually embedded in other - parts of the page's markup, and the data block here is just used by the site's search engine to - help users who are looking for particular features in their game maps.

    +
  • -
  • +

    If the script's type is "classic" and the script is + from an external file, fire a simple + event named load at the script + element.

    -
    +

    Otherwise queue a task to fire a simple event named load at the script element.

    -

    The following sample shows how a script element can be used to define a function that is then - used by other parts of the document. It also shows how a script element can be used - to invoke script while the document is being parsed, in this case to initialise the form's - output.

    + -
    <script>
    - function calculate(form) {
    -   var price = 52000;
    -   if (form.elements.brakes.checked)
    -     price += 1000;
    -   if (form.elements.radio.checked)
    -     price += 2500;
    -   if (form.elements.turbo.checked)
    -     price += 5000;
    -   if (form.elements.sticker.checked)
    -     price += 250;
    -   form.elements.result.value = price;
    - }
    -</script>
    -<form name="pricecalc" onsubmit="return false" onchange="calculate(this)">
    - <fieldset>
    -  <legend>Work out the price of your car</legend>
    -  <p>Base cost: £52000.</p>
    -  <p>Select additional options:</p>
    -  <ul>
    -   <li><label><input type=checkbox name=brakes> Ceramic brakes (£1000)</label></li>
    -   <li><label><input type=checkbox name=radio> Satellite radio (£2500)</label></li>
    -   <li><label><input type=checkbox name=turbo> Turbo charger (£5000)</label></li>
    -   <li><label><input type=checkbox name=sticker> "XZ" sticker (£250)</label></li>
    -  </ul>
    -  <p>Total: £<output name=result></output></p>
    - </fieldset>
    - <script>
    -  calculate(document.forms.pricecalc);
    - </script>
    -</form>
    +
    -
    Scripting languages

    A JavaScript MIME type is a MIME type string that is one of the @@ -60332,7 +60490,8 @@ if (player < script) { ... } if (script > player) { ... }

    Doing this also avoids a different pitfall as well: for related historical reasons, the string - "<!--" in JavaScript is actually treated as a line comment start, just like "//".

    + "<!--" in classic scripts is actually treated as a line + comment start, just like "//".

    @@ -78379,6 +78538,113 @@ dictionary DragEventInit : MouseEventInit { +
    + +

    Script settings for browsing contexts

    + +

    When the user agent is required to set up a browsing context environment settings + object, given a JavaScript execution context execution context, it + must run the following steps:

    + +
      +
    1. Let window be execution context's global object.

    2. + +
    3. Let url be a copy of the address + of the Document with which window associated.

    4. + +
    5. +

      Let settings object be a new environment settings object whose + algorithms are defined as follows:

      + +
      + +
      The realm execution context
      +
      + +

      Return execution context.

      + +
      + +
      The responsible browsing context
      +
      + +

      Return the browsing context with which window is associated.

      + +
      + +
      The responsible event loop
      +
      + +

      Return the event loop that is associated with the unit of related + similar-origin browsing contexts to which window's browsing + context belongs.

      + +
      + +
      The responsible document
      +
      + +

      Return the Document with which window is currently associated.

      + +
      + +
      The API URL character encoding
      +
      + +

      Return the current character encoding of + the Document with which window is currently associated.

      + +
      + +
      The API base URL
      +
      + +

      Return the current base URL of the + Document with which window is currently associated.

      + +
      + +
      The origin
      +
      + +

      Return the origin of the Document with which window + is currently associated.

      + +
      + +
      The effective script origin
      +
      + +

      Return the effective script origin of the Document with which + window is currently associated.

      + +
      + +
      The creation URL
      +
      + +

      Return url.

      + +
      + +
      The HTTPS state
      +
      + +

      Return the HTTPS state of the + Document with which window is currently associated.

      + +
      + +
      +
    6. + +
    7. Return settings object.

    8. +
    + +
    + +

    The Window object

    @@ -81722,29 +81988,22 @@ State: <OUTPUT NAME=I>1</OUTPUT> <INPUT VALUE="Increment" TYPE=BUTTON O http://software.hixie.ch/utilities/js/live-dom-viewer/saved/2639 -> about:blank http://software.hixie.ch/utilities/js/live-dom-viewer/saved/2640 -> javascript:'test' in Firefox, about:blank otherwise --> +
  • Let address be the address of the active document of the browsing context being navigated.

  • -
  • - -

    Create a script, using script source as the script - source, address as the script source URL, and the environment settings - object of the Window object of the active document of the - browsing context being navigated.

    - -

    Let result be the return value of the code entry-point - of this script. If an exception was thrown, let result be void instead. (The result will be void also if scripting is disabled.)

    - -
  • +
  • Let result be the result of running the classic script + script. If an exception was thrown, let result be void instead. (The + result will be void also if scripting is + disabled.)

  • -

    Process results: If the result of executing the script is void (there is no return - value), then the result of obtaining the resource for the URL is a response whose - status is 204.

    +

    Process results: If result is void (there is no return value), then + the result of obtaining the resource for the URL is a response whose status is 204.

    Otherwise, the result of obtaining the resource for the URL is a response whose NavigatorOnLine {

    Definitions
    -

    A script has:

    +

    A script is one of two possible structures. All scripts + have:

    -
    A code entry-point
    +
    A settings object
    + +
    + +

    An environment settings object, containing various settings that are shared + with other scripts in the same context.

    + +
    + +
    + + +

    A classic script additionally has:

    + +
    + +
    Source text
    -

    A code entry-point is either a string containing a block of executable code to be evaluated, - or a JavaScript function object. The latter case is used for event handlers.

    +

    A string containing a block of executable code to be evaluated as a JavaScript Script.

    @@ -85829,12 +86105,37 @@ interface NavigatorOnLine { -
    A settings object
    +
    + +

    A module script additionally has:

    + +
    + +
    A module record
    + +
    + +

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

    + +
    + +
    A base URL
    + +
    + +

    A base URL used for resolving module specifiers when resolving a module specifier. This will either be the URL from which the + script was obtained, for external module scripts, or the document base URL of the + containing document, for inline module scripts.

    + +
    + +
    A CORS setting
    -

    An environment settings object, various settings that are shared with other scripts in - the same context.

    +

    A CORS settings attribute state used to fetch imported modules.

    @@ -85852,11 +86153,23 @@ interface NavigatorOnLine {

    A JavaScript execution context shared by all scripts that use this settings object, i.e. all scripts in a given - realm. When we jump to a code-entry point, this execution context becomes the - top of the JavaScript execution context stack, on top of which another execution - context specific to the script in question is pushed. (This setup ensures ParseScript and ScriptEvaluation knows which Realm to use.)

    + realm. When we run a classic script or run a module script, + this execution context becomes the top of the JavaScript execution context stack, + on top of which another execution context specific to the script in question is pushed. (This + setup ensures ScriptEvaluation and ModuleEvaluation know which Realm to use.)

    + + + +
    A module map
    + +
    + +

    A map of absolute URLs to values that are either a module script, + null, or a placeholder value "fetching". The map must be initially + empty. It is used to ensure that imported JavaScript modules are only fetched, parsed, and + evaluated once.

    +
    A responsible browsing context
    @@ -85964,186 +86277,420 @@ interface NavigatorOnLine {

    This is typically a Window object or a WorkerGlobalScope object.

    +

    An environment settings object's Realm is its realm execution context's Realm component.

    +

    The relevant settings object for a global object o is the environment settings object whose global object is o. (There is always a 1:1 mapping of global objects to environment settings objects.)

    -

    The relevant settings object for a script s is the - settings object of s.

    -

    The script corresponding to the running execution context is the script in the [[HostDefined]] slot of the running JavaScript execution context's ScriptOrModule.

    -
    Script settings for browsing contexts
    -

    When the user agent is required to set up a browsing context environment settings - object, given a JavaScript execution context execution context, it - must run the following steps:

    +
    Fetching scripts
    + +

    To fetch a classic script for a script element element, + given a url, a CORS setting, a settings object, and a + character encoding, run these steps. The algorithm will asynchronously complete with + either null (on failure) or a new classic script (on success).

      -
    1. Let window be execution context's global object.

    2. +
    3. Let request be the result of creating a potential-CORS request given url and CORS + setting.

    4. + +
    5. Set request's client to + settings object, and its type to "script".

    6. + + +
    7. Fetch request.

    8. Let url be a copy of the address of the Document with which window is associated.

    9. -

      Let settings object be a new environment settings object whose - algorithms are defined as follows:

      +

      Return from this algorithm, and run the remaining steps as part of the fetch's + process response for the response + response.

      -
      +

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

      +
    10. -
      The realm execution context
      -
      +
    11. If response's type is "error", or response's status is not an ok status, asynchronously + complete this algorithm with null, and abort these steps.

    12. -

      Return execution context.

      +
    13. If response's Content Type metadata, if + any, specifies a character encoding, and the user agent supports that encoding, then set + character encoding to that encoding (ignoring the passed-in value).

    14. -
      +
    15. +

      Let source text be the result of decoding + response's body to Unicode, using + character encoding as the fallback encoding.

      -
      The responsible browsing context
      -
      +

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

      +
    16. -

      Return the browsing context with which window is associated.

      +
    17. +

      Let script be the result of creating a classic script using + source text and settings object.

      - +

      If response was CORS-cross-origin, then pass the muted + errors flag to the create a classic + script algorithm as well.

      +
    18. -
      The responsible event loop
      -
      +
    19. Asynchronously complete this algorithm with script.
    20. +
    -

    Return the event loop that is associated with the unit of related - similar-origin browsing contexts to which window's browsing - context belongs.

    +

    To fetch a module script tree given a url, a CORS setting, + and a settings object, run these steps. The algorithm will asynchronously complete + with either null (on failure) or a new module script (on success).

    - +
      +
    1. Fetch a single module script given url, CORS setting, + and settings object.

      -
      The responsible document
      -
      +
    2. Return from this algorithm and run the following steps when fetching a single module script asynchronously completes with + result:

    3. -

      Return the Document with which window is currently associated.

      +
    4. If result is null, asynchronously complete this algorithm with null and abort + these steps.

    5. -
      +
    6. Otherwise, result is a module script. Fetch the descendants of result.

    7. -
      The API URL character encoding
      -
      +
    8. When fetching the descendants of + a module script asynchronously completes with descendants result, + asynchronously complete this algorithm with descendants result.

    9. +
    -

    Return the current character encoding of - the Document with which window is currently associated.

    +

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

    - +
      +
    1. Let record be module script's module record.

    2. -
      The API base URL
      -
      +
    3. If record.[[RequestedModules]] is empty, asynchronously complete this + algorithm with module script.

    4. -

      Return the current base URL of the - Document with which window is currently associated.

      +
    5. Let urls be a new empty list.

    6. -
      +
    7. +

      For each string requested of record.[[RequestedModules]],

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

      2. -

        Return the origin of the Document with which window - is currently associated.

        +
      3. +

        If the result is error:

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

      2. -
        The effective script origin
        -
        +
      3. Report the exception error for module + script.

      4. -

        Return the effective script origin of the Document with which - window is currently associated.

        +
      5. Abort this algorithm, and asynchronously complete it with null.

      6. +
      +
    8. - +
    9. Otherwise, add url to urls.

    10. +
    +
  • -
    The creation URL
    -
    +
  • +

    For each url in urls, fetch a module script tree given + url, module script's CORS setting, and + module script's settings object.

    -

    Return url.

    +

    If any of the fetch a module script tree invocations asynchronously complete + with null, the user agent may terminate any or + all of the other fetches, and must then asynchronously complete this algorithm with null.

    -
  • +

    Once all of the fetch a module script tree invocations asynchronously + complete with a module script, asynchronously complete this algorithm with + module script.

    + + -
    The HTTPS state
    -
    +

    To fetch a single module script, given a url, a CORS setting, + and a settings object, run these steps. The algorithm will asynchronously complete + with either null (on failure) or a new module script (on success).

    -

    Return the HTTPS state of the - Document with which window is currently associated.

    +
      +
    1. Let module map be settings's module map.

    2. -
    +
  • If module map contains an entry with key url whose value is "fetching", wait (in parallel) until that entry's value changes, + then proceed to the next step.

  • + +
  • If module map contains an entry with key url, asynchronously + complete this algorithm with that entry's value, and abort these steps.

  • + +
  • Create an entry in module map with key url and value "fetching".

    + +
  • +

    Let credentials mode be determined by switching on CORS setting: +

    +
    No CORS
    +
    "omit"
    + +
    Anonymous
    +
    "same-origin"
    + +
    Use Credentials
    +
    "include"
  • -
  • Return settings object.

  • +
  • Let request be a new request whose + url is url, destination is "subresource", + type is "script", mode is "cors", credentials mode is credentials + mode, and client is + settings object.

  • + + +
  • Fetch request.

  • + +
  • +

    Return from this algorithm, and run the remaining steps as part of the fetch's + process response for the response + response.

    + +

    response is always CORS-same-origin.

    +
  • + +
  • +

    If any of the following conditions are met, set the value of the entry in module + map whose key is url to null, asynchronously complete this algorithm with + null, and abort these steps:

    + +
      +
    • response's type is "error"

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

    • + +
    • +

      The result of extracting a MIME type from + response's header list + (ignoring parameters) is not a JavaScript MIME type.

      + +

      For historical reasons, fetching a + classic script does not include MIME type checking. In contrast, module scripts will + fail to load if they are not of a correct MIME type.

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

  • + +
  • Let module script be the result of creating a module script given + source text, settings object, response's url, and CORS setting.

  • + +
  • +

    Set the value of the entry in module map whose key is url to + module script, and asynchronously complete this algorithm with 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.

    +
  • -
    Calling scripts
    +
    Creating scripts
    -

    When a user agent is to jump to a code entry-point for a script s, given an optional rethrow errors - flag, the user agent must run the following steps:

    +

    To create a classic script, given some script + source, an environment settings object, and an optional muted errors + flag:

      -
    1. Let settings be the settings object of s.

    2. +
    3. Let script be a new classic script that this algorithm will + subsequently initialise.

    4. + +
    5. Set script's settings object to the environment + settings object provided.

    6. + +
    7. If scripting is disabled for the given + environment settings object's responsible browsing context, then set + script's source text to the + empty string. Otherwise, set script's source text to the supplied script + source.

    8. -
    9. Assert: s's code entry-point is a string of source text; this - algorithm should never be reached when it is a function.

    10. +
    11. If the muted errors flag was set, then set script's muted + errors flag.

    12. -
    13. Prepare to run a callback with settings. If this returns "do not - run" then abort these steps.

    14. +
    15. Return script.

    16. -
    17. Let result be ParseScript(s's - code entry-point, s).

    18. +
    -
  • -

    If result is a List of errors, then:

    +

    To create a module script, given some script + source, an environment settings object, a script base URL, and a CORS settings + attribute state:

    -
      -
    1. If the rethrow errors flag is set and s's muted errors - flag is not set, rethrow the error given by the first element of result.

    2. +
        -
      1. If the rethrow errors flag is set and s's muted - errors flag is set, throw a NetworkError exception.

      2. +
      3. Let script be a new module script that this algorithm will + subsequently initialise.

      4. -
      5. If the rethrow errors flag is not set, report the exception - given by the first element in result for the script s.

      6. +
      7. Set script's settings object to the environment + settings object provided.

      8. -
      9. In all cases, go to the step labeled cleanup.

      10. -
      - +
    3. Let realm be the provided environment settings object's Realm.

    4. + +
    5. If scripting is disabled for the given + environment settings object's responsible browsing context, then let + script source be the empty string. Otherwise, let script source be the + provided script source.

    6. + +
    7. Let result be ParseModule(script source, realm, + script).

    8. + +
    9. If result is a List of errors, report the exception given by the + first element of result for script, return null, and abort these + steps.

    10. + +
    11. Set script's module + record to result.

    12. + +
    13. Set script's base URL to + the script base URL provided.

    14. + +
    15. Set script's CORS + setting to the CORS settings attribute state provided.

    16. + +
    17. Return script.

    18. -
    19. Let status be + +

      Calling scripts
      + +

      To run a classic script given a classic script s and an + optional rethrow errors flag:

      + +
        + +
      1. Let settings be the settings object of s.

      2. + +
      3. Check if we can run script with settings. If this returns "do + not run" then abort these steps.

      4. + +
      5. Let realm be settings's Realm.

      6. + +
      7. Prepare to run script with settings.

      8. + +
      9. Let result be ParseScript(s's source text, realm, + s).

      10. + +
      11. If result is a List of errors, set result to the first element + of result and go to the step labeled error.

      12. + +
      13. Let evaluationStatus be ScriptEvaluation(result).

      14. +
      15. If evaluationStatus is an abrupt completion, set result to + evaluationStatus.[[value]] and go to the step labeled error.

      16. + +
      17. If we have reached this step, skip to the step labeled cleanup.

      18. +
      19. -

        If status is an abrupt completion, then:

        +

        Error: At this point result must be an error object. Perform the following + steps:

          -
        1. If the rethrow errors flag is set and s's muted errors - flag is not set, rethrow the error given by result.[[value]].

        2. +
        3. If the rethrow errors flag is set and s's muted + errors flag is not set, rethrow result.

        4. -
        5. If the rethrow errors flag is set and s's muted - errors flag is set, throw a NetworkError exception.

        6. +
        7. If the rethrow errors flag is set and s's muted + errors flag is set, throw a NetworkError exception.

        8. If the rethrow errors flag is not set, report the exception - given result.[[value]] for the script s.

        9. + given by result for the script s.

      20. -
      21. Cleanup: Clean up after running a callback with +

      22. Cleanup: Clean up after running script with settings.

      23. -
      24. If result exists and is not an abrupt completion, return - result.[[value]]. Otherwise, script execution was unsuccessful, either because an - error occurred during parsing, or an exception occurred during evaluation, or because it was - aborted prematurely.

      25. +
      26. If evaluationStatus exists and is not an abrupt completion, return + evaluationStatus.[[value]]. Otherwise, script execution was unsuccessful, either + because an error occurred during parsing, or an exception occurred during evaluation, or because + it was aborted prematurely.

      27. + +
      + +

      To run a module script given a module script s:

      + +
        + +
      1. Let settings be the settings object of s.

      2. + +
      3. Check if we can run script with settings. If this returns "do + not run" then abort these steps.

      4. + +
      5. Let record be s's module record.

        + +
      6. +

        Let instantiationStatus be record.ModuleDeclarationInstantiation().

        + +

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

        +
      7. + +
      8. If instantiationStatus is an abrupt completion, report the + exception given by instantiationStatus.[[value]] for s and abort + these steps.

      9. + +
      10. Prepare to run script given settings.

      11. + +
      12. +

        Let evaluationStatus be record.ModuleEvaluation().

        + +

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

        +
      13. + +
      14. If evaluationStatus is an abrupt completion, report the exception + given by evaluationStatus.[[value]] for s.

      15. +
      16. Clean up after running script with settings.

      -

      The steps to prepare to run a callback with an environment settings object - settings are as follows. They return either "run" or "do not run".

      +

      The steps to check if we can run script with an environment settings + object settings are as follows. They return either "run" or "do not run".

        @@ -86155,18 +86702,26 @@ interface NavigatorOnLine { responsible browsing context specified by settings, then return "do not run" and abort these steps.

        +
      1. Return "run".

      2. + +
      + +

      The steps to prepare to run script with + an environment settings object settings are as follows:

      + +
        +
      1. Label settings as a candidate entry settings object.

      2. Push settings's realm execution context onto the JavaScript execution context stack; it is now the running JavaScript execution context.

      3. -
      4. Return "run".

      5. -
      -

      The steps to clean up after running a callback with an environment settings - object settings are as follows. are as follows:

      +

      The steps to clean up after running + script with an environment settings object settings are as + follows:

        @@ -86276,45 +86831,6 @@ interface NavigatorOnLine { perform each of the jobs in the global script clean-up jobs list and then empty the list.

        - - - -
        - -
        Creating scripts
        - -

        When the specification says that a script is to be created, given some script source, a script source URL, an - environment settings object, and optionally muted errors and rethrow - errors flag, the user agent must run the following steps:

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

        2. - -
        3. If scripting is disabled for browsing - context passed to this algorithm, then abort these steps, as if the script source - described a program that did nothing but return void.

          - -
        4. Set script's code entry-point to the supplied script - source.

        5. - -
        6. Let script's settings object be the environment - settings object provided.

        7. - -
        8. If the muted errors flag was set, then set script's muted - errors flag.

        9. - -
        10. Jump to script's code - entry-point, passing the rethrow errors flag if it was given.

        11. - -
        - -
        - - -
        Killing scripts
        @@ -86378,18 +86894,19 @@ interface NavigatorOnLine {
        1. Assert: queueName is "PromiseJobs". ("ScriptJobs" must not be used by user agents.)

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

        4. Let settings be the settings object of the script corresponding to the running execution context.

        5. Queue a microtask, on settings's responsible event loop, to perform the following steps:

            -
          1. Prepare to run a callback with settings. If this returns "do +

          2. Check if we can run script with settings. If this returns "do not run" then abort these steps.

          3. +
          4. Prepare to run script with settings.

          5. Performing the abstract operation specified by job, using the elements of arguments as its arguments.

          6. -
          7. Clean up after running a callback with settings.

          8. +
          9. Clean up after running script with settings.

        @@ -86409,6 +86926,70 @@ interface NavigatorOnLine { process of actually initiating the next job will be taken care of by the event loop.

        +
        Integration with the JavaScript module system
        + +

        The JavaScript specification defines a syntax for modules, as well as some host-agnostic parts + of their processing model. This specification defines the rest of their processing model: how the + module system is bootstrapped, via the script element with type attribute set to "module", and how + modules are fetched, resolved, and executed.

        + +

        Although the JavaScript specification speaks in terms of "scripts" versus + "modules", in general this specification speaks in terms of classic + scripts versus module scripts, since both of them use + the script element.

        + +

        To resolve a module specifier given a module script script + and a string specifier, perform the following steps. It will return either an + absolute URL or failure.

        + +
          +
        1. Apply the URL parser to specifier. If the result is not failure, + return the result.

        2. + +
        3. +

          If specifier does not start with the character U+002F SOLIDUS (/), the two-character sequence U+002E FULL STOP, U+002F SOLIDUS (./), or the three-character sequence U+002E FULL STOP, U+002E FULL STOP, + U+002F SOLIDUS (../), return failure and abort these steps.

          + +

          This restriction is in place so that in the future we can allow custom module + loaders to give special meaning to "bare" import specifiers, like import "jquery" or import "web/crypto". For now any + such imports will fail, instead of being treated as relative URLs.

          +
        4. + +
        5. Return the result of applying the URL parser to specifier with + script's base URL as the base + URL.

        6. +
        + +
        HostResolveImportedModule(referencingModule, specifier)
        + +

        JavaScript contains an implementation-defined HostResolveImportedModule abstract operation. User + agents must use the following implementation.

        + +
          +
        1. Let referencing module script be + referencingModule.[[HostDefined]].

        2. + +
        3. Let module map be referencing module script's settings + object's module map.

        4. + +
        5. Let url be the result of resolving a + module specifier given referencing module script and specifier. If + the result is failure, throw a TypeError exception and abort these steps.

        6. + +
        7. Let resolved module script be the value of the entry in module map + whose key is url. If no such entry exists, or if the value is null or "fetching", throw a TypeError exception and abort these + steps.

        8. + +
        9. Return resolved module script's module record.

        10. +
        +
        @@ -87000,7 +87581,7 @@ dictionary PromiseRejectionEventInit : EventInit {

        Run: Run the selected task.

        This might involve invoking scripted callbacks, which eventually calls the - clean up after running a callback steps, which call this perform a microtask + clean up after running script steps, which call this perform a microtask checkpoint algorithm again, which is why we use the performing a microtask checkpoint flag to avoid reentrancy.

        @@ -87642,15 +88223,7 @@ typedef OnBeforeUnloadEventHandlerNonNull? OnBeforeUnloadEvent -
      1. Let script be a new script.

      2. - - -
      3. Let script's code entry-point be function.

      4. - -
      5. Let script's settings object be script - settings.

      6. - +
      7. Set H's value to function.

      @@ -88868,12 +89441,14 @@ interface WindowTimers {
    20. Let script source be the first method argument.

    21. -
    22. Let settings object be method context's environment settings - object.

    23. +
    24. Let settings object be method context's environment + settings object.

    25. -
    26. Create a script using script source as the script source, - the URL where script source can be found, and settings - object as the environment settings object.

    27. +
    28. Let script be the result of creating a classic script using + script source and settings object.

    29. + +
    30. Run the classic script + script.

    @@ -93849,9 +94424,9 @@ interface MessagePort : EventTarget { unaffected to any unshipped port message queue.

    When the user agent is to create a new MessagePort object with a - particular settings object as its owner, it must instantiate a - new MessagePort object, and let its owner be - owner.

    + particular environment settings object as its owner, it must instantiate + a new MessagePort object, and let its owner + be owner.

    When the user agent is to entangle two MessagePort objects, it must run the following steps:

    @@ -95129,9 +95704,9 @@ interface WorkerGlobalScope : EventTarget { it must be removed from the list of the worker's Documents of each worker whose list contains that Document.

    -

    Given a settings object o when creating or obtaining a +

    Given an environment settings object o when creating or obtaining a worker, the list of relevant Document objects to add depends on the type - of global object specified by o's. If o + of global object specified by o. If o specifies a global object that is a WorkerGlobalScope object (i.e. if we are creating a nested worker), then the relevant Documents are the the worker's Documents of the global object specified by o. Otherwise, o specifies a global object that @@ -95301,13 +95876,11 @@ interface WorkerGlobalScope : EventTarget { -

  • Let script be a new script with - code entry-point source and settings object settings - object.

  • +
  • Let script be the result of creating a classic script using + source and settings object.

  • -

    Jump to the script's code entry-point.

    +

    Run the classic script script.

    In addition to the usual possibilities of returning a value or failing due to an exception, this could be prematurely aborted by the "kill a worker" or @@ -95939,18 +96512,22 @@ interface SharedWorker : EventTarget {

  • -

    Create a script using source as the script source, the - URL from which source was obtained, settings object as - the environment settings object, and passing the rethrow errors - flag.

    +

    Let script be the result of creating a classic script using + source and settings object.

    If response is CORS-cross-origin, pass the muted errors - flag to the create a script algorithm as well.

    + flag to the create a classic script algorithm + as well.

    + +
  • + +
  • +

    Run the classic script script, + passing the rethrow errors flag.

    -

    The newly created script will run until - it either returns, fails to parse, fails to catch an exception, or gets prematurely aborted - by the "kill a worker" or "terminate a worker" algorithms defined - above.

    +

    script will run until it either returns, fails to parse, fails to + catch an exception, or gets prematurely aborted by the "kill a worker" or + "terminate a worker" algorithms defined above.

    If an exception was thrown or if the script was prematurely aborted, then abort all these steps, letting the exception or aborting continue to be processed by the calling [XHTMLMOD]

    Modularization of XHTML(TM), M. Altheim, F. Boumphrey, S. Dooley, S. McCarron, S. Schnitzenbaumer, T. Wugofski. W3C.
    +
    [XKCD1288]
    +
    (Non-normative) Substitutions, Randall Munroe. xkcd.
    +
    [XML]
    Extensible Markup Language, T. Bray, J. Paoli, C. Sperberg-McQueen, E. Maler, F. Yergeau. W3C.