diff --git a/source b/source index 83c2f45d482..3b9d4e5c192 100644 --- a/source +++ b/source @@ -2755,6 +2755,7 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
  • JavaScript execution context
  • JavaScript execution context stack
  • JavaScript realm
  • +
  • JobCallback Record
  • EnvironmentRecord
  • NewTarget
  • running JavaScript execution context
  • @@ -2810,9 +2811,11 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
  • The GetActiveScriptOrModule abstract operation
  • The GetFunctionRealm abstract operation
  • The HasOwnProperty abstract operation
  • +
  • The HostCallJobCallback abstract operation
  • The HostEnqueuePromiseJob abstract operation
  • The HostEnsureCanCompileStrings abstract operation
  • The HostImportModuleDynamically abstract operation
  • +
  • The HostMakeJobCallback abstract operation
  • The HostPromiseRejectionTracker abstract operation
  • The HostResolveImportedModule abstract operation
  • The InitializeHostDefinedRealm abstract operation
  • @@ -89656,10 +89659,130 @@ dictionary PromiseRejectionEventInit : EventInit { operations, that vary depending on the host environment. This section defines them for user agent hosts.

    +
    HostEnsureCanCompileStrings(callerRealm, calleeRealm)
    + +

    JavaScript contains an implementation-defined HostEnsureCanCompileStrings(callerRealm, + calleeRealm) abstract operation. User agents must use the following implementation: + + +

      +
    1. Perform ? EnsureCSPDoesNotBlockStringCompilation(callerRealm, + calleeRealm).

    2. +
    + +
    HostPromiseRejectionTracker(promise, operation)
    + +

    JavaScript contains an implementation-defined HostPromiseRejectionTracker(promise, + operation) abstract operation. User agents must use the following implementation: +

    + +
      +
    1. Let script be the running script.

    2. + +
    3. If script's muted errors is true, terminate these steps.

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

      +
    6. + +
    7. +

      If operation is "reject", + +

        +
      1. Add promise to settings object's about-to-be-notified + rejected promises list.

      2. +
      +
    8. + +
    9. +

      If operation is "handle", + +

        +
      1. If settings object's about-to-be-notified rejected promises + list contains promise, then remove promise from that list and + return.

      2. + +
      3. If settings object's outstanding rejected promises weak set + does not contain promise, then return.

      4. + +
      5. Remove promise from settings object's outstanding rejected + promises weak set.

      6. + +
      7. Let global be settings object's global object.

      8. + +
      9. Queue a global task on the DOM manipulation task source given + global to fire an event named rejectionhandled at global, using + PromiseRejectionEvent, with the promise attribute initialized to + promise, and the reason + attribute initialized to the value of promise's [[PromiseResult]] internal slot.

      10. +
      +
    10. +
    + + + +
    Job-related host hooks
    + +

    The JavaScript specification defines Jobs to be scheduled and run later by the host, as well as + JobCallback Records which encapsulate JavaScript + functions that are called as part of jobs. The JavaScript specification contains a number of + implementation-defined abstract operations that lets the host define how jobs are + scheduled and how JobCallbacks are handled. This section defines them for user agent hosts.

    + +
    HostCallJobCallback(callback, V, + argumentsList)
    + +

    JavaScript contains an implementation-defined HostCallJobCallback(callback, V, + argumentsList) abstract operation to let hosts restore state when invoking JavaScript + callbacks from inside tasks. HTML restores the incumbent settings object and the + active script. User agents must use the following implementation:

    + +
      +
    1. Let incumbent settings be + callback.[[HostDefined]].[[IncumbentSettings]].

    2. + +
    3. Let script execution context be + callback.[[HostDefined]].[[ActiveScriptContext]].

    4. + +
    5. +

      Prepare to run a callback with incumbent settings.

      + +

      This affects the incumbent + concept while the callback runs.

      +
    6. + +
    7. +

      If script execution context is not null, then push script execution context onto the JavaScript execution + context stack.

      + +

      This affects the active script while the callback runs.

      +
    8. + +
    9. Let result be Call(callback.[[Callback]], V, + argumentsList).

    10. + +
    11. If script execution context is not null, then pop script execution context from the JavaScript execution context + stack.

    12. + +
    13. Clean up after running a callback with incumbent + settings.

    14. + +
    15. Return result.

    16. +
    + -
    HostEnqueuePromiseJob(job, - realm)
    +
    HostEnqueuePromiseJob(job, + realm)

    JavaScript contains an implementation-defined HostEnqueuePromiseJob(job, realm) @@ -89687,58 +89810,6 @@ dictionary PromiseRejectionEventInit : EventInit { -

  • Let incumbent settings be the incumbent settings object.

  • - -
  • Let active script be the active script.

  • - -
  • Let script execution context be null.

  • - -
  • -

    If active script is not null, set script execution context to a new - JavaScript execution context, with its Function field set to null, its Realm field - set to active script's settings object's Realm, and its ScriptOrModule set to active script's - record.

    - -

    As seen below, this is used in order to propagate the current active - script forward to the time when the job is executed.

    - -
    -

    A case where active script is non-null, and saving it in this way is useful, is - the following:

    - -
    Promise.resolve('import(`./example.mjs`)').then(eval);
    - -

    Without this step (and the steps below that use it), there would be no active - script when the import() expression is evaluated, since eval() - is a built-in function that does not originate from any particular script.

    - -

    With this step in place, the active script is propagated from the above code into the job, - allowing import() to use the original script's base URL appropriately.

    -
    - -
    -

    active script can be null if the user clicks on the following button:

    - -
    <button onclick="Promise.resolve('import(`./example.mjs`)').then(eval)">Click me</button>
    - -

    In this case, the JavaScript function for the event - handler will be created by the get the current value of the event handler algorithm, which creates a function - with null [[ScriptOrModule]] value. Thus, when the promise machinery calls - HostEnqueuePromiseJob, there will be no active script to pass - along.

    - -

    As a consequence, this means that when the import() expression is evaluated, - there will still be no active script. Fortunately that is handled by our - implementations of HostResolveImportedModule and - HostImportModuleDynamically, by falling back to using the current settings - object's API base URL.

    -
    -
  • -
  • Queue a microtask on the surrounding agent's event loop to perform the following steps:

    @@ -89755,35 +89826,18 @@ dictionary PromiseRejectionEventInit : EventInit { while the job runs.

  • -
  • -

    Prepare to run a callback with incumbent settings.

    - -

    This affects the incumbent - concept while the job runs.

    -
  • - -
  • -

    If script execution context is not null, then push script execution context onto the JavaScript execution - context stack.

    - -

    As explained above, this affects the active script while the job - runs.

    -
  • -
  • Let result be job().

    job is an abstract closure returned by - NewPromiseReactionJob or NewPromiseResolveThenableJob.

    -
  • - -
  • If script execution context is not null, then pop script execution context from the JavaScript execution context - stack.

  • - -
  • Clean up after running a callback with incumbent - settings.

  • + NewPromiseReactionJob or NewPromiseResolveThenableJob. The promise's + handler function when job is returned by NewPromiseReactionJob, and + the then function when job is returned by + NewPromiseResolveThenableJob, are wrapped in JobCallback Records. HTML saves the incumbent settings object and + a JavaScript execution context for to the active script in + HostMakeJobCallback and restores them in HostCallJobCallback.

    +
  • If job settings is not null, then clean up after running script with job settings.

  • @@ -89794,72 +89848,74 @@ dictionary PromiseRejectionEventInit : EventInit { -
    HostEnsureCanCompileStrings(callerRealm, calleeRealm)
    +
    HostMakeJobCallback(callable)

    JavaScript contains an implementation-defined HostEnsureCanCompileStrings(callerRealm, - calleeRealm) abstract operation. User agents must use the following implementation: - + data-x="js-HostMakeJobCallback">HostMakeJobCallback(callable) abstract operation + to let hosts attach state to JavaScript callbacks that are called from inside tasks. HTML tracks the incumbent settings + object in promises by saving the incumbent settings object and a + JavaScript execution context for the active script. User agents must use + the following implementation:

      -
    1. Perform ? EnsureCSPDoesNotBlockStringCompilation(callerRealm, - calleeRealm).

    2. -
    - -
    HostPromiseRejectionTracker(promise, operation)
    +
  • Let incumbent settings be the incumbent settings object.

  • -

    JavaScript contains an implementation-defined HostPromiseRejectionTracker(promise, - operation) abstract operation. User agents must use the following implementation: -

    +
  • Let active script be the active script.

  • -
      -
    1. Let script be the running script.

    2. +
    3. Let script execution context be null.

    4. -
    5. If script's muted errors is true, terminate these steps.

    6. +
    7. +

      If active script is not null, set script execution context to a new + JavaScript execution context, with its Function field set to null, its Realm field + set to active script's settings object's Realm, and its ScriptOrModule set to active script's + record.

      -
    8. Let settings object be script's settings object.

      -
    9. +

      As seen below, this is used in order to propagate the current active + script forward to the time when the job callback is invoked.

      -
    10. -

      If operation is "reject", +

      +

      A case where active script is non-null, and saving it in this way is useful, is + the following:

      -
        -
      1. Add promise to settings object's about-to-be-notified - rejected promises list.

      2. -
      -
    11. +
      Promise.resolve('import(`./example.mjs`)').then(eval);
      -
    12. -

      If operation is "handle", +

      Without this step (and the steps that use it in HostCallJobCallback), there + would be no active script when the import() expression is evaluated, + since eval() is a built-in function that does not originate from any particular + script.

      -
        -
      1. If settings object's about-to-be-notified rejected promises - list contains promise, then remove promise from that list and - return.

      2. +

        With this step in place, the active script is propagated from the above code into the job, + allowing import() to use the original script's base URL appropriately.

        + -
      3. If settings object's outstanding rejected promises weak set - does not contain promise, then return.

      4. +
        +

        active script can be null if the user clicks on the following button:

        -
      5. Remove promise from settings object's outstanding rejected - promises weak set.

      6. +
        <button onclick="Promise.resolve('import(`./example.mjs`)').then(eval)">Click me</button>
        -
      7. Let global be settings object's global object.

      8. +

        In this case, the JavaScript function for the event + handler will be created by the get the current value of the event handler algorithm, which creates a function + with null [[ScriptOrModule]] value. Thus, when the promise machinery calls + HostMakeJobCallback, there will be no active script to pass + along.

        -
      9. Queue a global task on the DOM manipulation task source given - global to fire an event named rejectionhandled at global, using - PromiseRejectionEvent, with the promise attribute initialized to - promise, and the reason - attribute initialized to the value of promise's [[PromiseResult]] internal slot.

      10. -
      +

      As a consequence, this means that when the import() expression is evaluated, + there will still be no active script. Fortunately that is handled by our + implementations of HostResolveImportedModule and + HostImportModuleDynamically, by falling back to using the current settings + object's API base URL.

      +
    13. -
    - +
  • Return the JobCallback Record { [[Callback]]: callable, + [[HostDefined]]: { [[IncumbentSettings]]: incumbent settings, [[ActiveScriptContext]]: + script execution context } }.

  • +
    Module-related host hooks