Skip to content

Commit 9c8ff61

Browse files
committed
Revert "lib: add WeakRef and FinalizationRegistry to primordials"
This reverts commit 78343bb.
1 parent 98c2067 commit 9c8ff61

File tree

4 files changed

+15
-30
lines changed

4 files changed

+15
-30
lines changed

lib/.eslintrc.yaml

-4
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,6 @@ rules:
5252
- prepareStackTrace
5353
- stackTraceLimit
5454
- name: EvalError
55-
- name: FinalizationRegistry
56-
into: Safe
5755
- name: Float32Array
5856
- name: Float64Array
5957
- name: Function
@@ -92,8 +90,6 @@ rules:
9290
- name: URIError
9391
- name: WeakMap
9492
into: Safe
95-
- name: WeakRef
96-
into: Safe
9793
- name: WeakSet
9894
into: Safe
9995
globals:

lib/internal/event_target.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,8 @@ const {
1414
ObjectGetOwnPropertyDescriptors,
1515
ReflectApply,
1616
SafeArrayIterator,
17-
SafeFinalizationRegistry,
1817
SafeMap,
1918
SafeWeakMap,
20-
SafeWeakRef,
2119
SafeWeakSet,
2220
String,
2321
Symbol,
@@ -203,7 +201,7 @@ let weakListenersState = null;
203201
// get garbage collected now that it's weak.
204202
let objectToWeakListenerMap = null;
205203
function weakListeners() {
206-
weakListenersState ??= new SafeFinalizationRegistry(
204+
weakListenersState ??= new globalThis.FinalizationRegistry(
207205
(listener) => listener.remove()
208206
);
209207
objectToWeakListenerMap ??= new SafeWeakMap();
@@ -234,7 +232,7 @@ class Listener {
234232
this.weak = Boolean(weak); // Don't retain the object
235233

236234
if (this.weak) {
237-
this.callback = new SafeWeakRef(listener);
235+
this.callback = new globalThis.WeakRef(listener);
238236
weakListeners().registry.register(listener, this, this);
239237
// Make the retainer retain the listener in a WeakMap
240238
weakListeners().map.set(weak, listener);

lib/internal/per_context/primordials.js

-20
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,6 @@ function copyPrototype(src, dest, prefix) {
171171
'Date',
172172
'Error',
173173
'EvalError',
174-
'FinalizationRegistry',
175174
'Float32Array',
176175
'Float64Array',
177176
'Function',
@@ -195,7 +194,6 @@ function copyPrototype(src, dest, prefix) {
195194
'Uint8Array',
196195
'Uint8ClampedArray',
197196
'WeakMap',
198-
'WeakRef',
199197
'WeakSet',
200198
].forEach((name) => {
201199
const original = global[name];
@@ -239,15 +237,13 @@ function copyPrototype(src, dest, prefix) {
239237

240238
const {
241239
ArrayPrototypeForEach,
242-
FinalizationRegistry,
243240
FunctionPrototypeCall,
244241
Map,
245242
ObjectFreeze,
246243
ObjectSetPrototypeOf,
247244
Set,
248245
SymbolIterator,
249246
WeakMap,
250-
WeakRef,
251247
WeakSet,
252248
} = primordials;
253249

@@ -346,7 +342,6 @@ primordials.SafeWeakMap = makeSafe(
346342
constructor(i) { super(i); } // eslint-disable-line no-useless-constructor
347343
}
348344
);
349-
350345
primordials.SafeSet = makeSafe(
351346
Set,
352347
class SafeSet extends Set {
@@ -360,20 +355,5 @@ primordials.SafeWeakSet = makeSafe(
360355
}
361356
);
362357

363-
primordials.SafeFinalizationRegistry = makeSafe(
364-
FinalizationRegistry,
365-
class SafeFinalizationRegistry extends FinalizationRegistry {
366-
// eslint-disable-next-line no-useless-constructor
367-
constructor(cleanupCallback) { super(cleanupCallback); }
368-
}
369-
);
370-
primordials.SafeWeakRef = makeSafe(
371-
WeakRef,
372-
class SafeWeakRef extends WeakRef {
373-
// eslint-disable-next-line no-useless-constructor
374-
constructor(target) { super(target); }
375-
}
376-
);
377-
378358
ObjectSetPrototypeOf(primordials, null);
379359
ObjectFreeze(primordials);

lib/internal/util/iterable_weak_map.js

+13-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,25 @@
11
'use strict';
22

33
const {
4+
makeSafe,
45
ObjectFreeze,
5-
SafeFinalizationRegistry,
66
SafeSet,
77
SafeWeakMap,
8-
SafeWeakRef,
98
SymbolIterator,
109
} = primordials;
1110

11+
// TODO(aduh95): Add FinalizationRegistry to primordials
12+
const SafeFinalizationRegistry = makeSafe(
13+
globalThis.FinalizationRegistry,
14+
class SafeFinalizationRegistry extends globalThis.FinalizationRegistry {}
15+
);
16+
17+
// TODO(aduh95): Add WeakRef to primordials
18+
const SafeWeakRef = makeSafe(
19+
globalThis.WeakRef,
20+
class SafeWeakRef extends globalThis.WeakRef {}
21+
);
22+
1223
// This class is modified from the example code in the WeakRefs specification:
1324
// https://github.com/tc39/proposal-weakrefs
1425
// Licensed under ECMA's MIT-style license, see:

0 commit comments

Comments
 (0)