Skip to content

Commit fa2f2e2

Browse files
committed
Revert "lib: add WeakRef and FinalizationRegistry to primordials"
This reverts commit 78343bb.
1 parent 984b965 commit fa2f2e2

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
@@ -48,8 +48,6 @@ rules:
4848
- prepareStackTrace
4949
- stackTraceLimit
5050
- name: EvalError
51-
- name: FinalizationRegistry
52-
into: Safe
5351
- name: Float32Array
5452
- name: Float64Array
5553
- name: Function
@@ -88,8 +86,6 @@ rules:
8886
- name: URIError
8987
- name: WeakMap
9088
into: Safe
91-
- name: WeakRef
92-
into: Safe
9389
- name: WeakSet
9490
into: Safe
9591
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
@@ -163,7 +163,6 @@ function copyPrototype(src, dest, prefix) {
163163
'Date',
164164
'Error',
165165
'EvalError',
166-
'FinalizationRegistry',
167166
'Float32Array',
168167
'Float64Array',
169168
'Function',
@@ -187,7 +186,6 @@ function copyPrototype(src, dest, prefix) {
187186
'Uint8Array',
188187
'Uint8ClampedArray',
189188
'WeakMap',
190-
'WeakRef',
191189
'WeakSet',
192190
].forEach((name) => {
193191
const original = global[name];
@@ -231,15 +229,13 @@ function copyPrototype(src, dest, prefix) {
231229

232230
const {
233231
ArrayPrototypeForEach,
234-
FinalizationRegistry,
235232
FunctionPrototypeCall,
236233
Map,
237234
ObjectFreeze,
238235
ObjectSetPrototypeOf,
239236
Set,
240237
SymbolIterator,
241238
WeakMap,
242-
WeakRef,
243239
WeakSet,
244240
} = primordials;
245241

@@ -338,7 +334,6 @@ primordials.SafeWeakMap = makeSafe(
338334
constructor(i) { super(i); } // eslint-disable-line no-useless-constructor
339335
}
340336
);
341-
342337
primordials.SafeSet = makeSafe(
343338
Set,
344339
class SafeSet extends Set {
@@ -352,20 +347,5 @@ primordials.SafeWeakSet = makeSafe(
352347
}
353348
);
354349

355-
primordials.SafeFinalizationRegistry = makeSafe(
356-
FinalizationRegistry,
357-
class SafeFinalizationRegistry extends FinalizationRegistry {
358-
// eslint-disable-next-line no-useless-constructor
359-
constructor(cleanupCallback) { super(cleanupCallback); }
360-
}
361-
);
362-
primordials.SafeWeakRef = makeSafe(
363-
WeakRef,
364-
class SafeWeakRef extends WeakRef {
365-
// eslint-disable-next-line no-useless-constructor
366-
constructor(target) { super(target); }
367-
}
368-
);
369-
370350
ObjectSetPrototypeOf(primordials, null);
371351
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)