-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Normative: Add Weakrefs and FinalizationRegistry #2089
Conversation
<h1>HostCleanupFinalizationRegistry(_finalizationRegistry_)</h1> | ||
|
||
<p> | ||
HostCleanupFinalizationRegistry is an implementation-defined abstract |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@syg This might be important for the incumbent realm tracking.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For incumbents, see #2086 and whatwg/html#5722
As both an editor and a delegate, given the reality with Promises, I think it'd be fine to fix up the callbacks in this PR to use JobCallback after #2086 is merged, even for Stage 4. There is no need to gate on that.
00ce5e9
to
53fe666
Compare
53fe666
to
78fbc63
Compare
I am not sure what the linter wants from me, any recommendations? |
78fbc63
to
e7bf912
Compare
There should be a space on either side of each square bracket in that heading, I believe. |
e7bf912
to
e6fd679
Compare
Ugh, my apologies for the terrible error messages from ecmarkup. I'll work on that. I think the error you're seeing in the most recent commit is because of the inclusion of blank lines within |
e6fd679
to
7600747
Compare
I think I fixed it, should be good now Edit: narrator: she forgot to commit the patch |
7600747
to
a65af73
Compare
Tests: tc39/test262#2192 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I started to do the suggestions, but it seems like every paragraph is hard-wrapped; it's probably easier to halt my review until those are updated :-)
1. Set _ref_.[[WeakRefTarget]] to ~empty~. | ||
1. For each FinalizationRegistry _fg_ such that _fg_.[[Cells]] contains _cell_, such that _cell_.[[WeakRefTarget]] is _obj_, do | ||
1. Set _cell_.[[WeakRefTarget]] to ~empty~. | ||
1. Optionally, perform ! HostCleanupFinalizationRegistry(_fg_). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The implementation of HostCleanupFinalizationRegistry
is already free to not clean things up so I don't think this needs to be optional.
1. Optionally, perform ! HostCleanupFinalizationRegistry(_fg_). | |
1. Perform ! HostCleanupFinalizationRegistry(_fg_). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I disagree with this suggestion. While it is true that the host hook reserves the right to not do anything, calling out the optionality means hosts don't need to remember to explicitly allow optionality.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why don't we just explicitly call out the optionality in the hook then? Isn't the entire point of host hooks to abstract this kind of thing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's important to call out optionality here to avoid a misunderstanding that it would be mandatory to trigger FinalizationRegistry. The word "optionally" makes the intended interpretation unambiguous, and it does not sacrifice precision/correctness. Remember that specifications are communication devices, not just mathematical artifacts. Because @devsnek's suggestion is an editorial one, we can continue considering it after this PR lands and possibly make the change later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As an editor I also prefer the "Optionally" phrasing.
</p> | ||
|
||
<p> | ||
Because calling HostCleanupFinalizationRegistry is optional, registered objects |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because calling HostCleanupFinalizationRegistry is optional, registered objects | |
Because calling CleanupFinalizationRegistry is optional, registered objects |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also disagree with this suggestion for the same reason as above.
1. Set _ref_.[[WeakRefTarget]] to ~empty~. | ||
1. For each FinalizationRegistry _fg_ such that _fg_.[[Cells]] contains _cell_, such that _cell_.[[WeakRefTarget]] is _obj_, do | ||
1. Set _cell_.[[WeakRefTarget]] to ~empty~. | ||
1. Optionally, perform ! HostCleanupFinalizationRegistry(_fg_). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I disagree with this suggestion. While it is true that the host hook reserves the right to not do anything, calling out the optionality means hosts don't need to remember to explicitly allow optionality.
</p> | ||
|
||
<p> | ||
Because calling HostCleanupFinalizationRegistry is optional, registered objects |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also disagree with this suggestion for the same reason as above.
63bb481
to
913646b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM pending comments
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking very good already, mostly small wording changes now.
913646b
to
fcead87
Compare
Branch has also been rebased |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This recent commit seems to fix the Realm-specificity bug.
Colloquially, we say that an individual object is live if every set of objects containing it is live. | ||
</emu-note> | ||
|
||
<p>At any point during evaluation, a set of objects _S_ is considered <dfn>live</dfn> if either of the following conditions is met: </p> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is "live" sufficiently specific to serve as a linkable definition id? It's not used elsewhere now, but I could see it cropping up in prose. Perhaps something like "liveness" (which is already used) would be better?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's reasonable to define "live" this way within the JavaScript specification. I don't think "liveness" is really any more specific. This proposal successfully links with the term "live" where relevant in normative text ("liveness" is just used in notes) and the rest of ecma262 does not seem to use "live" in a conflicting way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"live" is also the spelling of a common English word (ranked somewhere between 100 and 300 AFAICT) that could easily find a place in the spec, as opposed to "liveness" which will only ever have this meaning.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be fine to iterate on this in an editorial PR after landing this one.
|
||
<emu-clause id="sec-clear-kept-objects" aoid=ClearKeptObjects> | ||
<h1>ClearKeptObjects ( )</h1> | ||
<p>The abstract operation ClearKeptObjects takes no arguments. ECMAScript implementations are expected to call ClearKeptObjects when a synchronous sequence of ECMAScript executions completes. It performs the following steps when called:</p> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given the plausible future addition of Symbols, it would be nice to give these operations initial names that do not directly reference the Object type. "KeptObject" could be replaced with something like "KeptAlive" or "KeptList".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A similar comment was brought up above, and it was agreed that we can change this after the Symbols in WeakMap proposal moved forward. I would rather do this is a group change, as there will be other edits, rather than anticipating an unrelated proposal in this one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renaming operations requires introducing oldids
, which is a bit of an ugly hack that shouldn't be necessary if the initial names do not include "Object". I'm not suggesting that you make the definitions generic right now, just that the names theirselves are not overly specific.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As the champion of the Symbols as WeakMap keys proposal, I would prefer to not generalize this prematurely. oldids are fine.
I think these need to be added to the intrinsics table and to the "constructor properties of the global object" section. |
I think I still need one more editor to approve this, so pinging @bakkot and @michaelficarra for one last look before I rebase and squash |
spec.html
Outdated
<emu-clause id="sec-weakref-invariants"> | ||
<h1>Objectives</h1> | ||
|
||
<p> This specification does not make any guarantees that any object will be garbage collected. Objects which are not live may be released after long periods of time, or never at all. For this reason, this specification uses the term "may" when describing behaviour triggered by garbage collection.</p> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<p> This specification does not make any guarantees that any object will be garbage collected. Objects which are not live may be released after long periods of time, or never at all. For this reason, this specification uses the term "may" when describing behaviour triggered by garbage collection.</p> | |
<p>This specification does not make any guarantees that any object will be garbage collected. Objects which are not live may be released after long periods of time, or never at all. For this reason, this specification uses the term "may" when describing behaviour triggered by garbage collection.</p> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM other than the stray space above.
fe67804
to
71c0897
Compare
(Fixes spec bug from PR tc39#2089)
- Put 2 emu-clause attributes in quotes (We always quote element attributes -- see PR tc39#1868) - Use title-case in clause heading - Tweak some algorithm syntax - Change "a finalization registry object" to "a FinalizationRegistry" (The former term isn't defined.)
- Use title-case in clause heading - Tweak some algorithm syntax - Put 2 emu-clause attributes in quotes (We always quote element attributes -- see PR tc39#1868) - Change "a finalization registry object" to "a FinalizationRegistry" (The former term isn't defined.)
Fixes spec bug from PR tc39#2089.
- Use title-case in clause heading - Tweak some algorithm syntax - Put 2 emu-clause attributes in quotes (We always quote element attributes -- see PR tc39#1868) - Change "a finalization registry object" to "a FinalizationRegistry" (The former term isn't defined.)
Fixes spec bug from PR tc39#2089.
- Use title-case in clause heading - Tweak some algorithm syntax - Put 2 emu-clause attributes in quotes (We always quote element attributes -- see PR tc39#1868) - Change "a finalization registry object" to "a FinalizationRegistry" (The former term isn't defined.)
Specification text for https://github.com/tc39/proposal-weakrefs
This version of the specification is without cleanupSome (see https://github.com/codehag/proposal-cleanup-some), in anticipation of the discussion of the upcoming meeting. Adding this back in would be trivial if we decide against it.
Note: we're adding inline normative optional spec text.