From 5aa77835b00b34365281945002bf1b7bd6dc2266 Mon Sep 17 00:00:00 2001 From: Daniel Ehrenberg Date: Fri, 26 Apr 2019 11:53:37 +0200 Subject: [PATCH 01/23] Describe integration with the WeakRefs proposal The main observable semantics here are that both clearing the KeptAlive list and calling the finalization callback on any particular FinalizationGroup happen on individual tasks, on a separate task source. --- source | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/source b/source index e41ebdc81f8..f27734b171a 100644 --- a/source +++ b/source @@ -2865,6 +2865,24 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute + +

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

+ +

User agents that support JavaScript must also implement the BigInt proposal.

+ +

User agents that support JavaScript must also implement the WeakRef proposal. + The following terms are defined there, and used in this specification: .

+ + + @@ -90505,6 +90523,41 @@ import "https://example.com/foo/../module2.mjs"; data-x="concept-script-record">record.

+
Integration with WeakRefs and FinalizationGroups
+ +

The WeakRef proposal allows JavaScript to register objects with + FinalizationGroups, in order to schedule a cleanup action if they are found + to be unreachable by the garbage collector.

+ +

The timing and occurrence cleanup work is implementation-defined. UAs may differ in + when and whether an object is garbage collected, affecting both whether WeakRefs + become undefined, and whether FinalizationGroup cleanup callbacks occur. There are + well-known cases in popular web browsers where objects are not accessible to JavaScript but + remain retained by the garbage collector indefinitely. Authors should not depend on the + timing details of garbage collection implementations.

+ +

Cleanup actions taken by the WeakRef proposal do not take place interspersed + with synchronous JavaScript execution, but rather happen in queued tasks. This includes + both calling FinalizationGroup cleanup callbacks as well as letting the result of + dereferencing a WeakRef to change from an object to undefined. This section + defines the scheduling of those cleanup actions.

+ +

When there is a FinalizationGroup fg such that + CheckForEmptyCells(fg) is true, the user agent may + queue a task to perform FinalizationGroupCleanup(fg).

+ +

When there is an agent agent such that agent.[[KeptAlive]] + is not empty, the user agent may queue a task to perform + ClearKeptObjects(agent).

+ +
The above usage of ClearKeptObjects in a queued task is equivalent + in observable semantics to calling it as the final step of the perform a microtask + checkpoint algorithm.
+ +

The task source for any tasks that are queued in this section is the garbage collection task + source.

+

Event loops

@@ -122785,8 +122838,13 @@ INSERT INTERFACES HERE
[JSINTL]
ECMAScript Internationalization API Specification. Ecma International.
+<<<<<<< HEAD
[JSTLA]
Top-Level Await. Ecma International.
+======= +
[JSWEAKREF]
+
WeakRefs. Ecma International.
+>>>>>>> 1f07b6f5 (Describe integration with the WeakRefs proposal)
[JSON]
The JavaScript Object Notation (JSON) Data Interchange Format, T. Bray. IETF.
From 64762e1896fa8c20a6c3f55edf770395d0db2c31 Mon Sep 17 00:00:00 2001 From: Daniel Ehrenberg Date: Sat, 27 Apr 2019 00:59:32 +0200 Subject: [PATCH 02/23] Editorial: Add cross-reference --- source | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/source b/source index f27734b171a..f261dc00451 100644 --- a/source +++ b/source @@ -90537,10 +90537,11 @@ import "https://example.com/foo/../module2.mjs"; timing details of garbage collection implementations.

Cleanup actions taken by the WeakRef proposal do not take place interspersed - with synchronous JavaScript execution, but rather happen in queued tasks. This includes - both calling FinalizationGroup cleanup callbacks as well as letting the result of - dereferencing a WeakRef to change from an object to undefined. This section - defines the scheduling of those cleanup actions.

+ with synchronous JavaScript execution, but rather happen in queued tasks. This includes both calling FinalizationGroup + cleanup callbacks as well as letting the result of dereferencing a WeakRef to + change from an object to undefined. This section defines the scheduling of those cleanup + actions.

When there is a FinalizationGroup fg such that CheckForEmptyCells(fg) is true, the user agent may From 979b9fb32ec3fe375d8c7e043d56d218cc65d291 Mon Sep 17 00:00:00 2001 From: Daniel Ehrenberg Date: Tue, 30 Apr 2019 16:00:14 +0200 Subject: [PATCH 03/23] Changes from review from Anne and Mathieu --- source | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/source b/source index f261dc00451..e23f195f836 100644 --- a/source +++ b/source @@ -2881,6 +2881,7 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute

  • The FinalizationGroup class
  • The FinalizationGroupCleanup abstract operation
  • The WeakRef class
  • +
  • The WeakRef.prototype.deref() method
  • @@ -90526,15 +90527,16 @@ import "https://example.com/foo/../module2.mjs";
    Integration with WeakRefs and FinalizationGroups

    The WeakRef proposal allows JavaScript to register objects with - FinalizationGroups, in order to schedule a cleanup action if they are found + FinalizationGroup objects, in order to schedule a cleanup action if they are found to be unreachable by the garbage collector.

    -

    The timing and occurrence cleanup work is implementation-defined. UAs may differ in - when and whether an object is garbage collected, affecting both whether WeakRefs - become undefined, and whether FinalizationGroup cleanup callbacks occur. There are - well-known cases in popular web browsers where objects are not accessible to JavaScript but - remain retained by the garbage collector indefinitely. Authors should not depend on the - timing details of garbage collection implementations.

    +

    The timing and occurrence cleanup work is implementation-defined. User agents may differ in + when and whether an object is garbage collected, affecting both whether the return value of the + WeakRef.prototype.deref() method is undefined, and whether + FinalizationGroup cleanup callbacks occur. There are well-known cases in popular web + browsers where objects are not accessible to JavaScript, but they remain retained by the garbage + collector indefinitely. Authors should not depend on the timing details of garbage collection + implementations.

    Cleanup actions taken by the WeakRef proposal do not take place interspersed with synchronous JavaScript execution, but rather happen in queued Date: Tue, 30 Apr 2019 17:22:09 +0200 Subject: [PATCH 04/23] Move WeakRef processing logic back to the WeakRef specification The role of HTML here is strictly limited to being a task scheduling service for JavaScript. --- source | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/source b/source index e23f195f836..305877c8ef8 100644 --- a/source +++ b/source @@ -2876,10 +2876,11 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute The following terms are defined there, and used in this specification: .

    @@ -90545,18 +90546,34 @@ import "https://example.com/foo/../module2.mjs"; change from an object to undefined. This section defines the scheduling of those cleanup actions.

    -

    When there is a FinalizationGroup fg such that - CheckForEmptyCells(fg) is true, the user agent may - queue a task to perform FinalizationGroupCleanup(fg).

    +
    HostClearKeptObjects(agent)
    -

    When there is an agent agent such that agent.[[KeptAlive]] - is not empty, the user agent may queue a task to perform - ClearKeptObjects(agent).

    +

    The WeakRef proposal contains an implementation-defined + HostClearKeptObjects(agent) + abstract operation. User agents must use the + following implementation:

    + +
      +
    1. Queue a task on the garbage collection task source to perform + ClearKeptObjects(agent).

    2. +
    The above usage of ClearKeptObjects in a queued task is equivalent in observable semantics to calling it as the final step of the perform a microtask checkpoint algorithm.
    +
    HostCleanupFinalizationGroup(finalizationGroup)
    + +

    The WeakRef proposal contains an implementation-defined + HostCleanupFinalizationGroup(finalizationGroup) abstract operation. + User agents must use the following implementation:

    + +
      +
    1. Queue a task on the garbage collection task source to perform + CleanupFinalizationGroup(finalizationGroup).

    2. +
    +

    The task source for any tasks that are queued in this section is the garbage collection task source.

    From 37de0137683bb58180721d6097c1dc3784c2f1bc Mon Sep 17 00:00:00 2001 From: Daniel Ehrenberg Date: Fri, 3 May 2019 11:25:35 +0200 Subject: [PATCH 05/23] ClearKeptObjects in microtask checkpoint algorithm --- source | 25 ++++--------------------- 1 file changed, 4 insertions(+), 21 deletions(-) diff --git a/source b/source index 305877c8ef8..20585646336 100644 --- a/source +++ b/source @@ -2879,7 +2879,6 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
  • The ClearKeptObjects abstract operation
  • The CleanupFinalizationGroup abstract operation
  • The FinalizationGroup class
  • -
  • The HostClearKeptObjects abstract operation
  • The HostCleanupFinalizationGroup abstract operation
  • The WeakRef class
  • The WeakRef.prototype.deref() method
  • @@ -90541,26 +90540,8 @@ import "https://example.com/foo/../module2.mjs";

    Cleanup actions taken by the WeakRef proposal do not take place interspersed with synchronous JavaScript execution, but rather happen in queued tasks. This includes both calling FinalizationGroup - cleanup callbacks as well as letting the result of dereferencing a WeakRef to - change from an object to undefined. This section defines the scheduling of those cleanup - actions.

    - -
    HostClearKeptObjects(agent)
    - -

    The WeakRef proposal contains an implementation-defined - HostClearKeptObjects(agent) - abstract operation. User agents must use the - following implementation:

    - -
      -
    1. Queue a task on the garbage collection task source to perform - ClearKeptObjects(agent).

    2. -
    - -
    The above usage of ClearKeptObjects in a queued task is equivalent - in observable semantics to calling it as the final step of the perform a microtask - checkpoint algorithm.
    + data-x="concept-task">tasks. This section defines the scheduling of calling + FinalizationGroup cleanup callbacks.

    HostCleanupFinalizationGroup(finalizationGroup)
    @@ -91141,6 +91122,8 @@ import "https://example.com/foo/../module2.mjs";
  • Cleanup Indexed Database transactions.

  • +
  • Perform ClearKeptObjects().

  • +
  • Set the event loop's performing a microtask checkpoint to false.

  • From 65407e906bb2ab84840b6f87ff7be2abde9559e6 Mon Sep 17 00:00:00 2001 From: Daniel Ehrenberg Date: Mon, 6 May 2019 23:10:52 +0200 Subject: [PATCH 06/23] Report the exception from CleanupFinalizationGroup --- source | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/source b/source index 20585646336..ede8e7b59c4 100644 --- a/source +++ b/source @@ -90552,7 +90552,8 @@ import "https://example.com/foo/../module2.mjs";
    1. Queue a task on the garbage collection task source to perform - CleanupFinalizationGroup(finalizationGroup).

    2. + CleanupFinalizationGroup(finalizationGroup). If this throws an exception, + catch it, and report the exception.

    The task source for any tasks that are Date: Mon, 20 May 2019 13:50:03 +0200 Subject: [PATCH 07/23] Clean up definition of garbage collection task source --- source | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/source b/source index ede8e7b59c4..52348b5d47f 100644 --- a/source +++ b/source @@ -90551,15 +90551,11 @@ import "https://example.com/foo/../module2.mjs"; User agents must use the following implementation:

      -
    1. Queue a task on the garbage collection task source to perform +

    2. Queue a task on the garbage collection task source to perform CleanupFinalizationGroup(finalizationGroup). If this throws an exception, catch it, and report the exception.

    -

    The task source for any tasks that are queued in this section is the garbage collection task - source.

    -

    Event loops

    From 8fda8e0a1b6c7d314c1d0f8c607cc93deb25637b Mon Sep 17 00:00:00 2001 From: Daniel Ehrenberg Date: Tue, 4 Jun 2019 23:29:32 +0200 Subject: [PATCH 08/23] Editorial cleanup in HostCleanupFinalizationGroup --- source | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/source b/source index 52348b5d47f..be3baf4a685 100644 --- a/source +++ b/source @@ -90551,9 +90551,16 @@ import "https://example.com/foo/../module2.mjs"; User agents must use the following implementation:

      -
    1. Queue a task on the garbage collection task source to perform - CleanupFinalizationGroup(finalizationGroup). If this throws an exception, - catch it, and report the exception.

    2. +
    3. +

      Queue a task on the garbage collection task source to perform the + following step:

      +
        +
      1. +

        Perform ? CleanupFinalizationGroup(finalizationGroup).

        +

        If this throws an exception, catch it, and report the exception.

        +
      2. +
      +
    From 5bfbfd2b6673d1933c852590dcd3a345bf18fbac Mon Sep 17 00:00:00 2001 From: Daniel Ehrenberg Date: Fri, 24 Apr 2020 20:22:54 +0200 Subject: [PATCH 09/23] Rename FinalizationGroup to FinalizationRegistry --- source | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/source b/source index be3baf4a685..cd4b7c00902 100644 --- a/source +++ b/source @@ -2877,9 +2877,9 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
    • The ClearKeptObjects abstract operation
    • -
    • The CleanupFinalizationGroup abstract operation
    • -
    • The FinalizationGroup class
    • -
    • The HostCleanupFinalizationGroup abstract operation
    • +
    • The CleanupFinalizationRegistry abstract operation
    • +
    • The FinalizationRegistry class
    • +
    • The HostCleanupFinalizationRegistry abstract operation
    • The WeakRef class
    • The WeakRef.prototype.deref() method
    @@ -90524,16 +90524,16 @@ import "https://example.com/foo/../module2.mjs"; data-x="concept-script-record">record.

    -
    Integration with WeakRefs and FinalizationGroups
    +
    Integration with the WeakRef and FinalizationRegistry API

    The WeakRef proposal allows JavaScript to register objects with - FinalizationGroup objects, in order to schedule a cleanup action if they are found + FinalizationRegistry objects, in order to schedule a cleanup action if they are found to be unreachable by the garbage collector.

    The timing and occurrence cleanup work is implementation-defined. User agents may differ in when and whether an object is garbage collected, affecting both whether the return value of the WeakRef.prototype.deref() method is undefined, and whether - FinalizationGroup cleanup callbacks occur. There are well-known cases in popular web + FinalizationRegistry cleanup callbacks occur. There are well-known cases in popular web browsers where objects are not accessible to JavaScript, but they remain retained by the garbage collector indefinitely. Authors should not depend on the timing details of garbage collection implementations.

    @@ -90541,13 +90541,13 @@ import "https://example.com/foo/../module2.mjs";

    Cleanup actions taken by the WeakRef proposal do not take place interspersed with synchronous JavaScript execution, but rather happen in queued tasks. This section defines the scheduling of calling - FinalizationGroup cleanup callbacks.

    + FinalizationRegistry cleanup callbacks.

    -
    HostCleanupFinalizationGroup(finalizationGroup)
    +
    HostCleanupFinalizationRegistry(finalizationRegistry)

    The WeakRef proposal contains an implementation-defined - HostCleanupFinalizationGroup(finalizationGroup) abstract operation. + HostCleanupFinalizationRegistry(finalizationRegistry) abstract operation. User agents must use the following implementation:

      @@ -90556,7 +90556,7 @@ import "https://example.com/foo/../module2.mjs"; following step:

      1. -

        Perform ? CleanupFinalizationGroup(finalizationGroup).

        +

        Perform ? CleanupFinalizationRegistry(finalizationRegistry).

        If this throws an exception, catch it, and report the exception.

      From ec9b8f13f4306cf1cb983b2abe8041a589222301 Mon Sep 17 00:00:00 2001 From: Daniel Ehrenberg Date: Fri, 24 Apr 2020 20:55:14 +0200 Subject: [PATCH 10/23] cleanupSome must be omitted; follow up in issues --- source | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/source b/source index cd4b7c00902..94d36894796 100644 --- a/source +++ b/source @@ -2869,19 +2869,17 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute

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

      -

      User agents that support JavaScript must also implement the BigInt proposal.

      -

      User agents that support JavaScript must also implement the WeakRef proposal. The following terms are defined there, and used in this specification: .

        -
      • The ClearKeptObjects abstract operation
      • -
      • The CleanupFinalizationRegistry abstract operation
      • -
      • The FinalizationRegistry class
      • -
      • The HostCleanupFinalizationRegistry abstract operation
      • -
      • The WeakRef class
      • -
      • The WeakRef.prototype.deref() method
      • +
      • The ClearKeptObjects abstract operation
      • +
      • The CleanupFinalizationRegistry abstract operation
      • +
      • The FinalizationRegistry class
      • +
      • The FinalizationRegistry.prototype.cleanupSome() method
      • +
      • The HostCleanupFinalizationRegistry abstract operation
      • +
      • The WeakRef class
      • +
      • The WeakRef.prototype.deref() method
      @@ -90563,6 +90561,13 @@ import "https://example.com/foo/../module2.mjs";
    +

    User agents must omit the normative but optional + FinalizationRegistry.prototype.cleanupSome() method.

    + +

    Issue #5446 investigates + under what conditions FinalizationRegistry.prototype.cleanupSome() may be supported + in HTML user agents, if at all.

    +

    Event loops

    @@ -122845,13 +122850,11 @@ INSERT INTERFACES HERE
    [JSINTL]
    ECMAScript Internationalization API Specification. Ecma International.
    -<<<<<<< HEAD
    [JSTLA]
    Top-Level Await. Ecma International.
    -======= +
    [JSWEAKREF]
    -
    WeakRefs. Ecma International.
    ->>>>>>> 1f07b6f5 (Describe integration with the WeakRefs proposal) +
    WeakRefs. Ecma International.
    [JSON]
    The JavaScript Object Notation (JSON) Data Interchange Format, T. Bray. IETF.
    From ec24205cfc48d36b3c2a87e9b72212c1f77c47ca Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Mon, 27 Apr 2020 11:32:28 +0200 Subject: [PATCH 11/23] Editorial changes. --- source | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/source b/source index 94d36894796..f05245751af 100644 --- a/source +++ b/source @@ -90528,13 +90528,13 @@ import "https://example.com/foo/../module2.mjs"; FinalizationRegistry objects, in order to schedule a cleanup action if they are found to be unreachable by the garbage collector.

    -

    The timing and occurrence cleanup work is implementation-defined. User agents may differ in - when and whether an object is garbage collected, affecting both whether the return value of the - WeakRef.prototype.deref() method is undefined, and whether - FinalizationRegistry cleanup callbacks occur. There are well-known cases in popular web - browsers where objects are not accessible to JavaScript, but they remain retained by the garbage - collector indefinitely. Authors should not depend on the timing details of garbage collection - implementations.

    +

    The timing and occurrence of cleanup work is implementation-defined. User agents + may differ in when and whether an object is garbage collected, affecting both whether the return + value of the WeakRef.prototype.deref() method is undefined, and whether + FinalizationRegistry cleanup callbacks occur. There are well-known cases in popular + web browsers where objects are not accessible to JavaScript, but they remain retained by the + garbage collector indefinitely. Authors should not depend on the timing details of garbage + collection implementations.

    Cleanup actions taken by the WeakRef proposal do not take place interspersed with synchronous JavaScript execution, but rather happen in queued

    HostCleanupFinalizationRegistry(finalizationRegistry)
    -

    The WeakRef proposal contains an implementation-defined +

    The WeakRef proposal contains an implementation-defined HostCleanupFinalizationRegistry(finalizationRegistry) abstract operation. User agents must use the following implementation:

    From 78b5ca9ee4d48404af9ad435cf097bde9dafb299 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Wed, 5 Feb 2020 17:54:44 +0100 Subject: [PATCH 12/23] Specify handling of entry and incumbent objects. --- source | 51 ++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 48 insertions(+), 3 deletions(-) diff --git a/source b/source index f05245751af..9e9b95f6d31 100644 --- a/source +++ b/source @@ -90551,11 +90551,56 @@ import "https://example.com/foo/../module2.mjs";
    1. Queue a task on the garbage collection task source to perform the - following step:

      + following steps:

      1. -

        Perform ? CleanupFinalizationRegistry(finalizationRegistry).

        -

        If this throws an exception, catch it, and report the exception.

        +

        Let entry be finalizationGroup.[[CleanupCallback]].[[Realm]]'s + environment settings object.

        +
      2. + +
      3. +

        Check if we can run script with entry. If this returns + "do not run", then return.

        +
      4. + +
      5. +

        Prepare to run script with entry.

        + +

        This affects the entry concept + while the cleanup callback runs.

        +
      6. + +
      7. +

        Let incumbent be some appropriate environment settings object.

        + +

        It is not yet clear how to specify the environment settings + object that should be used here. In practice, this means that the incumbent concept is not correctly specified + while executing a cleanup callback. See discussion in pull + request #4571.

        +
      8. + +
      9. +

        Prepare to run a callback with incumbent.

        +
      10. + +
      11. +

        Let result be the result of performing + CleanupFinalizationRegistry(finalizationRegistry).

        +
      12. + +
      13. +

        Clean up after running a callback with incumbent.

        +
      14. + +
      15. +

        Clean up after running script with entry.

        +
      16. + +
      17. +

        If result is an abrupt completion, then report the + exception given by result.[[Value]].

    2. From b03f37413a35f6134d5ad7e32eef053d8e2b22b1 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Mon, 27 Apr 2020 11:51:38 +0200 Subject: [PATCH 13/23] fixup! Specify handling of entry and incumbent objects. --- source | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source b/source index 9e9b95f6d31..672d92ea881 100644 --- a/source +++ b/source @@ -90554,7 +90554,7 @@ import "https://example.com/foo/../module2.mjs"; following steps:

      1. -

        Let entry be finalizationGroup.[[CleanupCallback]].[[Realm]]'s +

        Let entry be finalizationRegistry.[[CleanupCallback]].[[Realm]]'s environment settings object.

      2. From 906bc7cef218a294cb768d294fd9e875c03ca153 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Mon, 27 Apr 2020 12:00:30 +0200 Subject: [PATCH 14/23] Review comment --- source | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source b/source index 672d92ea881..000e1b99f7f 100644 --- a/source +++ b/source @@ -90611,7 +90611,7 @@ import "https://example.com/foo/../module2.mjs";

        Issue #5446 investigates under what conditions FinalizationRegistry.prototype.cleanupSome() may be supported - in HTML user agents, if at all.

        + in user agents, if at all.

        From 3e6f119cd8903cf80b275e9de7f4a4ed1e393c93 Mon Sep 17 00:00:00 2001 From: Shu-yu Guo Date: Thu, 18 Feb 2021 19:19:17 -0800 Subject: [PATCH 15/23] Remove reference to proposal since WeakRefs have been merged into ecma262 --- source | 28 +++++++--------------------- 1 file changed, 7 insertions(+), 21 deletions(-) diff --git a/source b/source index 000e1b99f7f..6285cc3e864 100644 --- a/source +++ b/source @@ -2775,6 +2775,8 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
      3. The ArrayCreate abstract operation
      4. The Call abstract operation
      5. +
      6. The ClearKeptObjects abstract operation
      7. +
      8. The CleanupFinalizationRegistry abstract operation
      9. The Construct abstract operation
      10. The CopyDataBlockBytes abstract operation
      11. The CreateByteDataBlock abstract operation
      12. @@ -2788,6 +2790,7 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
      13. The GetFunctionRealm abstract operation
      14. The HasOwnProperty abstract operation
      15. The HostCallJobCallback abstract operation
      16. +
      17. The HostEnqueueFinalizationRegistryCleanupJob abstract operation
      18. The HostEnqueuePromiseJob abstract operation
      19. The HostEnsureCanCompileStrings abstract operation
      20. The HostImportModuleDynamically abstract operation
      21. @@ -2834,11 +2837,14 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
      22. The Strict Equality Comparison algorithm
      23. The Atomics object
      24. The Date class
      25. +
      26. The FinalizationRegistry class
      27. The RegExp class
      28. The SharedArrayBuffer class
      29. The TypeError class
      30. The RangeError class
      31. +
      32. The WeakRef class
      33. The eval() function
      34. +
      35. The WeakRef.prototype.deref() function
      36. The [[IsHTMLDDA]] internal slot
      37. import()
      38. import.meta
      39. @@ -2865,23 +2871,6 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
        • WebAssembly.Module
        - -

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

        - -

        User agents that support JavaScript must also implement the WeakRef proposal. - The following terms are defined there, and used in this specification: .

        - -
          -
        • The ClearKeptObjects abstract operation
        • -
        • The CleanupFinalizationRegistry abstract operation
        • -
        • The FinalizationRegistry class
        • -
        • The FinalizationRegistry.prototype.cleanupSome() method
        • -
        • The HostCleanupFinalizationRegistry abstract operation
        • -
        • The WeakRef class
        • -
        • The WeakRef.prototype.deref() method
        • -
        - @@ -90526,7 +90515,7 @@ import "https://example.com/foo/../module2.mjs";

        The WeakRef proposal allows JavaScript to register objects with FinalizationRegistry objects, in order to schedule a cleanup action if they are found - to be unreachable by the garbage collector.

        + to be unreachable by the garbage collector.

        The timing and occurrence of cleanup work is implementation-defined. User agents may differ in when and whether an object is garbage collected, affecting both whether the return @@ -122898,9 +122887,6 @@ INSERT INTERFACES HERE

        [JSTLA]
        Top-Level Await. Ecma International.
        -
        [JSWEAKREF]
        -
        WeakRefs. Ecma International.
        -
        [JSON]
        The JavaScript Object Notation (JSON) Data Interchange Format, T. Bray. IETF.
        From 7d4e6aa87d070e7df1c374e8f589c8b36f46ab4f Mon Sep 17 00:00:00 2001 From: Shu-yu Guo Date: Thu, 18 Feb 2021 19:19:46 -0800 Subject: [PATCH 16/23] Depend on https://github.com/tc39/ecma262/pull/2316 for incumbent machinery --- source | 33 +++++++-------------------------- 1 file changed, 7 insertions(+), 26 deletions(-) diff --git a/source b/source index 6285cc3e864..419b14cc5b3 100644 --- a/source +++ b/source @@ -90530,20 +90530,20 @@ import "https://example.com/foo/../module2.mjs"; data-x="concept-task">tasks. This section defines the scheduling of calling FinalizationRegistry cleanup callbacks.

        -
        HostCleanupFinalizationRegistry(finalizationRegistry)
        +
        HostEnqueueFinalizationRegistryCleanupJob(finalizationRegistry)
        -

        The WeakRef proposal contains an implementation-defined - HostCleanupFinalizationRegistry(finalizationRegistry) abstract operation. - User agents must use the following implementation:

        +

        The WeakRef proposal contains an implementation-defined HostEnqueueFinalizationRegistryCleanupJob(finalizationRegistry) abstract operation. User agents must use the following + implementation:

        1. -

          Queue a task on the garbage collection task source to perform the +

          Queue a task on the JavaScript engine task source to perform the following steps:

          1. -

            Let entry be finalizationRegistry.[[CleanupCallback]].[[Realm]]'s +

            Let entry be finalizationRegistry.[[CleanupCallback]].[[Callback]].[[Realm]]'s environment settings object.

          2. @@ -90559,30 +90559,11 @@ import "https://example.com/foo/../module2.mjs"; while the cleanup callback runs.

            -
          3. -

            Let incumbent be some appropriate environment settings object.

            - -

            It is not yet clear how to specify the environment settings - object that should be used here. In practice, this means that the incumbent concept is not correctly specified - while executing a cleanup callback. See discussion in pull - request #4571.

            -
          4. - -
          5. -

            Prepare to run a callback with incumbent.

            -
          6. -
          7. Let result be the result of performing CleanupFinalizationRegistry(finalizationRegistry).

          8. -
          9. -

            Clean up after running a callback with incumbent.

            -
          10. -
          11. Clean up after running script with entry.

          12. From e0611bb80b9d24fee65c64b71c5feb8fc3cf5af7 Mon Sep 17 00:00:00 2001 From: Shu-yu Guo Date: Thu, 18 Feb 2021 19:20:22 -0800 Subject: [PATCH 17/23] Remove cleanupSome reference since that was split out into separate proposal --- source | 7 ------- 1 file changed, 7 deletions(-) diff --git a/source b/source index 419b14cc5b3..a688febf06a 100644 --- a/source +++ b/source @@ -90576,13 +90576,6 @@ import "https://example.com/foo/../module2.mjs";
          -

          User agents must omit the normative but optional - FinalizationRegistry.prototype.cleanupSome() method.

          - -

          Issue #5446 investigates - under what conditions FinalizationRegistry.prototype.cleanupSome() may be supported - in user agents, if at all.

          -

          Event loops

          From 2bbab4263fa869ce0a89ec9b5779780ee17ebe2b Mon Sep 17 00:00:00 2001 From: Shu-yu Guo Date: Fri, 19 Feb 2021 15:29:06 -0800 Subject: [PATCH 18/23] Address review; move FR hook into job-integration section --- source | 131 +++++++++++++++++++++++++++++---------------------------- 1 file changed, 66 insertions(+), 65 deletions(-) diff --git a/source b/source index a688febf06a..e75786aca03 100644 --- a/source +++ b/source @@ -90056,6 +90056,71 @@ dictionary PromiseRejectionEventInit : EventInit {
        2. Return result.

        +
        HostEnqueueFinalizationRegistryCleanupJob(finalizationRegistry)
        + +

        JavaScript has the ability to register objects with FinalizationRegistry objects, + in order to schedule a cleanup action if they are found to be garbage collected. The JavaScript + specification contains an implementation-defined HostEnqueueFinalizationRegistryCleanupJob(finalizationRegistry) + abstract operation to schedule the cleanup action.

        + +

        The timing and occurrence of cleanup work is implementation-defined + in the JavaScript specification. User agents might differ in when and whether an object is garbage + collected, affecting both whether the return value of the WeakRef.prototype.deref() + method is undefined, and whether FinalizationRegistry cleanup callbacks occur. There + are well-known cases in popular web browsers where objects are not accessible to JavaScript, but + they remain retained by the garbage collector indefinitely. Authors should not + depend on the timing details of garbage collection implementations.

        + +

        Cleanup actions do not take place interspersed with synchronous JavaScript execution, but + rather happen in queued tasks. User agents must use the + following implementation:

        + +
          +
        1. +

          Let global be finalizationRegistry.[[Realm]]'s global object.

          +
        2. + +
        3. +

          Queue a global task on the JavaScript engine task source given + global to perform the following steps:

          + +
            +
          1. +

            Let entry be finalizationRegistry.[[CleanupCallback]].[[Callback]].[[Realm]]'s + environment settings object.

            +
          2. + +
          3. +

            Check if we can run script with entry. If this returns + "do not run", then return.

            +
          4. + +
          5. +

            Prepare to run script with entry.

            + +

            This affects the entry concept + while the cleanup callback runs.

            +
          6. + +
          7. +

            Let result be the result of performing + CleanupFinalizationRegistry(finalizationRegistry).

            +
          8. + +
          9. +

            Clean up after running script with entry.

            +
          10. + +
          11. +

            If result is an abrupt completion, then report the + exception given by result.[[Value]].

            +
          12. +
          +
        4. +
        +
        HostEnqueuePromiseJob(job, @@ -90194,6 +90259,7 @@ dictionary PromiseRejectionEventInit : EventInit { script execution context } }.

      +
      Module-related host hooks

      The JavaScript specification defines a syntax for modules, as well as some host-agnostic parts @@ -90511,71 +90577,6 @@ import "https://example.com/foo/../module2.mjs"; data-x="concept-script-record">record.

    -
    Integration with the WeakRef and FinalizationRegistry API
    - -

    The WeakRef proposal allows JavaScript to register objects with - FinalizationRegistry objects, in order to schedule a cleanup action if they are found - to be unreachable by the garbage collector.

    - -

    The timing and occurrence of cleanup work is implementation-defined. User agents - may differ in when and whether an object is garbage collected, affecting both whether the return - value of the WeakRef.prototype.deref() method is undefined, and whether - FinalizationRegistry cleanup callbacks occur. There are well-known cases in popular - web browsers where objects are not accessible to JavaScript, but they remain retained by the - garbage collector indefinitely. Authors should not depend on the timing details of garbage - collection implementations.

    - -

    Cleanup actions taken by the WeakRef proposal do not take place interspersed - with synchronous JavaScript execution, but rather happen in queued tasks. This section defines the scheduling of calling - FinalizationRegistry cleanup callbacks.

    - -
    HostEnqueueFinalizationRegistryCleanupJob(finalizationRegistry)
    - -

    The WeakRef proposal contains an implementation-defined HostEnqueueFinalizationRegistryCleanupJob(finalizationRegistry) abstract operation. User agents must use the following - implementation:

    - -
      -
    1. -

      Queue a task on the JavaScript engine task source to perform the - following steps:

      -
        -
      1. -

        Let entry be finalizationRegistry.[[CleanupCallback]].[[Callback]].[[Realm]]'s - environment settings object.

        -
      2. - -
      3. -

        Check if we can run script with entry. If this returns - "do not run", then return.

        -
      4. - -
      5. -

        Prepare to run script with entry.

        - -

        This affects the entry concept - while the cleanup callback runs.

        -
      6. - -
      7. -

        Let result be the result of performing - CleanupFinalizationRegistry(finalizationRegistry).

        -
      8. - -
      9. -

        Clean up after running script with entry.

        -
      10. - -
      11. -

        If result is an abrupt completion, then report the - exception given by result.[[Value]].

        -
      12. -
      -
    2. -
    -

    Event loops

    From f06928daefad5c9b2b02ec2cdde68c10947a0016 Mon Sep 17 00:00:00 2001 From: Shu-yu Guo Date: Fri, 19 Feb 2021 15:46:46 -0800 Subject: [PATCH 19/23] Add notes about ClearKeptObjects --- source | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/source b/source index e75786aca03..e1cdc848a56 100644 --- a/source +++ b/source @@ -90070,8 +90070,10 @@ dictionary PromiseRejectionEventInit : EventInit { collected, affecting both whether the return value of the WeakRef.prototype.deref() method is undefined, and whether FinalizationRegistry cleanup callbacks occur. There are well-known cases in popular web browsers where objects are not accessible to JavaScript, but - they remain retained by the garbage collector indefinitely. Authors should not - depend on the timing details of garbage collection implementations.

    + they remain retained by the garbage collector indefinitely. HTML clears kept-alive + WeakRef objects in the perform a microtask checkpoint algorithm. Authors + should not depend on the timing details of garbage collection + implementations.

    Cleanup actions do not take place interspersed with synchronous JavaScript execution, but rather happen in queued tasks. User agents must use the @@ -91140,7 +91142,12 @@ import "https://example.com/foo/../module2.mjs";

  • Cleanup Indexed Database transactions.

  • -
  • Perform ClearKeptObjects().

  • +
  • +

    Perform ClearKeptObjects().

    + +

    When WeakRef.prototype.deref() returns an object, that object is + kept alive until the next invocation of ClearKeptObjects().

    +
  • Set the event loop's performing a microtask checkpoint to false.

  • From 44b79e1f685c9f9d2f78f1eedc0d0c6681347653 Mon Sep 17 00:00:00 2001 From: Shu-yu Guo Date: Fri, 19 Feb 2021 15:48:26 -0800 Subject: [PATCH 20/23] Refine ClearKeptObjects note to not suggest that it dies due to ClearKeptObjects --- source | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/source b/source index e1cdc848a56..fa2e94e9bc4 100644 --- a/source +++ b/source @@ -91146,7 +91146,8 @@ import "https://example.com/foo/../module2.mjs";

    Perform ClearKeptObjects().

    When WeakRef.prototype.deref() returns an object, that object is - kept alive until the next invocation of ClearKeptObjects().

    + kept alive until the next invocation of ClearKeptObjects(), after which it is again + subject to garbage collection.

  • Set the event loop's performing a microtask checkpoint to From f7041ef3ad24d2e865be6ddd5f9bd641d2015893 Mon Sep 17 00:00:00 2001 From: Shu-yu Guo Date: Mon, 22 Feb 2021 14:27:20 -0800 Subject: [PATCH 21/23] Broaden incumbent tracking in Promises to also include FinalizationRegistries --- source | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/source b/source index fa2e94e9bc4..4a145edde22 100644 --- a/source +++ b/source @@ -90199,9 +90199,10 @@ dictionary PromiseRejectionEventInit : EventInit { 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:

    + object in promises and FinalizationRegistry callbacks by saving the + incumbent settings object and a JavaScript execution context for the + active script. User agents must use the following implementation:

    1. Let incumbent settings be the incumbent settings object.

    2. From cb0f44eab68922f0777a266ef8839317c55f429a Mon Sep 17 00:00:00 2001 From: Shu-yu Guo Date: Fri, 12 Mar 2021 11:31:28 -0800 Subject: [PATCH 22/23] Address domenic review --- source | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/source b/source index 4a145edde22..74a715f5262 100644 --- a/source +++ b/source @@ -90009,7 +90009,12 @@ dictionary PromiseRejectionEventInit : EventInit { 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.

      + scheduled and how JobCallbacks are handled. HTML uses these abstract operations to track the incumbent settings + object in promises and FinalizationRegistry callbacks by saving and + restoring the incumbent settings object and a JavaScript execution + context for the active script in JobCallbacks. This section defines them for + user agent hosts.

      HostCallJobCallback(callback, V, argumentsList)
      @@ -90017,8 +90022,7 @@ dictionary PromiseRejectionEventInit : EventInit {

      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:

        @@ -90072,8 +90076,7 @@ dictionary PromiseRejectionEventInit : EventInit { are well-known cases in popular web browsers where objects are not accessible to JavaScript, but they remain retained by the garbage collector indefinitely. HTML clears kept-alive WeakRef objects in the perform a microtask checkpoint algorithm. Authors - should not depend on the timing details of garbage collection - implementations.

        + would be best off not depending on the timing details of garbage collection implementations.

        Cleanup actions do not take place interspersed with synchronous JavaScript execution, but rather happen in queued tasks. User agents must use the @@ -90197,11 +90200,7 @@ dictionary PromiseRejectionEventInit : EventInit {

        JavaScript contains an implementation-defined 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 and FinalizationRegistry callbacks by saving the - incumbent settings object and a JavaScript execution context for the - active script. User agents must use the following implementation: tasks. User agents must use the following implementation:

          From 557bd3daa0741682a28c469ee5aaad1131eaf3ba Mon Sep 17 00:00:00 2001 From: Anne van Kesteren Date: Thu, 18 Mar 2021 09:02:46 +0100 Subject: [PATCH 23/23] formatting --- source | 34 ++++++++++++---------------------- 1 file changed, 12 insertions(+), 22 deletions(-) diff --git a/source b/source index 74a715f5262..43897d1bab0 100644 --- a/source +++ b/source @@ -90083,24 +90083,20 @@ dictionary PromiseRejectionEventInit : EventInit { following implementation:

            -
          1. -

            Let global be finalizationRegistry.[[Realm]]'s global object.

            -
          2. +
          3. Let global be finalizationRegistry.[[Realm]]'s global + object.

          4. Queue a global task on the JavaScript engine task source given global to perform the following steps:

              -
            1. -

              Let entry be finalizationRegistry.[[CleanupCallback]].[[Callback]].[[Realm]]'s - environment settings object.

              -
            2. +
            3. Let entry be + finalizationRegistry.[[CleanupCallback]].[[Callback]].[[Realm]]'s environment settings object.

            4. -
            5. -

              Check if we can run script with entry. If this returns - "do not run", then return.

              -
            6. +
            7. Check if we can run script with entry. If this returns "do not + run", then return.

            8. Prepare to run script with entry.

              @@ -90109,19 +90105,13 @@ dictionary PromiseRejectionEventInit : EventInit { while the cleanup callback runs.

            9. -
            10. -

              Let result be the result of performing - CleanupFinalizationRegistry(finalizationRegistry).

              -
            11. +
            12. Let result be the result of performing + CleanupFinalizationRegistry(finalizationRegistry).

            13. -
            14. -

              Clean up after running script with entry.

              -
            15. +
            16. Clean up after running script with entry.

            17. -
            18. -

              If result is an abrupt completion, then report the - exception given by result.[[Value]].

              -
            19. +
            20. If result is an abrupt completion, then report the + exception given by result.[[Value]].