Skip to content

Commit cd9fe86

Browse files
committed
fixup! lib: implement WeakReference on top of JS WeakRef
1 parent d62bec6 commit cd9fe86

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

lib/internal/util.js

+14-13
Original file line numberDiff line numberDiff line change
@@ -799,33 +799,34 @@ function guessHandleType(fd) {
799799
}
800800

801801
class WeakReference {
802+
#weak = null;
803+
#strong = null;
804+
#refCount = 0;
802805
constructor(object) {
803-
this.weak = new SafeWeakRef(object);
804-
this.strong = null;
805-
this.refCount = 0;
806+
this.#weak = new SafeWeakRef(object);
806807
}
807808

808809
incRef() {
809-
this.refCount++;
810-
if (this.refCount === 1) {
811-
const derefed = this.weak.deref();
810+
this.#refCount++;
811+
if (this.#refCount === 1) {
812+
const derefed = this.#weak.deref();
812813
if (derefed !== undefined) {
813-
this.strong = derefed;
814+
this.#strong = derefed;
814815
}
815816
}
816-
return this.refCount;
817+
return this.#refCount;
817818
}
818819

819820
decRef() {
820-
this.refCount--;
821-
if (this.refCount === 0) {
822-
this.strong = null;
821+
this.#refCount--;
822+
if (this.#refCount === 0) {
823+
this.#strong = null;
823824
}
824-
return this.refCount;
825+
return this.#refCount;
825826
}
826827

827828
get() {
828-
return this.weak.deref();
829+
return this.#weak.deref();
829830
}
830831
}
831832

0 commit comments

Comments
 (0)