diff --git a/src/generics/lib.generics.ts b/src/generics/lib.generics.ts index 2f0ea7b..389affb 100644 --- a/src/generics/lib.generics.ts +++ b/src/generics/lib.generics.ts @@ -3058,9 +3058,10 @@ namespace __Iterator } } -// gc only: the collector clears the link. Under any other model the compiler rejects the -// GC_* call below. -class WeakRef { +// WeakRef is the compiler's own (own spec 84), under gc, own and none. WeakMap and WeakSet stay +// gc only: their entries keep this collector link, whose GC_* call the compiler rejects under any +// other model. The collector clears the link. +class GcWeakLink { // The target's address complemented, as gc.h's GC_HIDE_POINTER does: a plain pointer here is // one the collector finds when it scans this object, and it then keeps the target alive, so // the link was never cleared. The collector sets this to 0 when the target goes. @@ -3085,14 +3086,14 @@ class WeakRef { class WeakMapEntry { public values: V[]; - constructor(public ref: WeakRef, value: V) { + constructor(public ref: GcWeakLink, value: V) { this.values = [value]; } } -// gc only, as WeakRef is. Keys are objects, compared by identity. The table is keyed by the key's -// address complemented (see WeakRef), so it does not hold the key: the collector clears the entry's -// WeakRef when the key goes, and the entry is then as if deleted. The collector does not move objects, +// gc only, as its link is. Keys are objects, compared by identity. The table is keyed by the key's +// address complemented (see GcWeakLink), so it does not hold the key: the collector clears the entry's +// link when the key goes, and the entry is then as if deleted. The collector does not move objects, // so an address stays the key's for as long as it lives; one reused by a later object finds a dead // entry and replaces it. The values are held strongly: a value that refers to its own key keeps that // key alive, as the collector has no ephemerons. @@ -3126,7 +3127,7 @@ class WeakMap { this.sweep(); } - this.table.set(this.hide(key), new WeakMapEntry(new WeakRef(key), value)); + this.table.set(this.hide(key), new WeakMapEntry(new GcWeakLink(key), value)); return this; } diff --git a/tests/weakref_basic.ts b/tests/weakref_basic.ts index 946c1ca..a5a7897 100644 --- a/tests/weakref_basic.ts +++ b/tests/weakref_basic.ts @@ -1,5 +1,5 @@ -// gc only: WeakRef is built on the collector's weak links, and this calls GC_gcollect() itself. -// Under any other model the compiler rejects both. +// gc only: this calls GC_gcollect() itself, which the compiler rejects under any other model. +// Under gc a WeakRef is a link the collector clears; its own-model test is in the compiler's suite. class Foo { constructor(public value: int) { }