| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 9498e97 commit 78343bb
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -48,6 +48,8 @@ rules: | |||
| 48 | 48 | - prepareStackTrace | |
| 49 | 49 | - stackTraceLimit | |
| 50 | 50 | - name: EvalError | |
| 51 | + - name: FinalizationRegistry | ||
| 52 | + into: Safe | ||
| 51 | 53 | - name: Float32Array | |
| 52 | 54 | - name: Float64Array | |
| 53 | 55 | - name: Function | |
@@ -86,6 +88,8 @@ rules: | |||
| 86 | 88 | - name: URIError | |
| 87 | 89 | - name: WeakMap | |
| 88 | 90 | into: Safe | |
| 91 | + - name: WeakRef | ||
| 92 | + into: Safe | ||
| 89 | 93 | - name: WeakSet | |
| 90 | 94 | into: Safe | |
| 91 | 95 | globals: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -14,8 +14,10 @@ const { | |||
| 14 | 14 | ObjectGetOwnPropertyDescriptors, | |
| 15 | 15 | ReflectApply, | |
| 16 | 16 | SafeArrayIterator, | |
| 17 | + SafeFinalizationRegistry, | ||
| 17 | 18 | SafeMap, | |
| 18 | 19 | SafeWeakMap, | |
| 20 | + SafeWeakRef, | ||
| 19 | 21 | SafeWeakSet, | |
| 20 | 22 | String, | |
| 21 | 23 | Symbol, | |
@@ -201,7 +203,7 @@ let weakListenersState = null; | |||
| 201 | 203 | // get garbage collected now that it's weak. | |
| 202 | 204 | let objectToWeakListenerMap = null; | |
| 203 | 205 | function weakListeners() { | |
| 204 | - weakListenersState ??= new globalThis.FinalizationRegistry( | ||
| 206 | + weakListenersState ??= new SafeFinalizationRegistry( | ||
| 205 | 207 | (listener) => listener.remove() | |
| 206 | 208 | ); | |
| 207 | 209 | objectToWeakListenerMap ??= new SafeWeakMap(); | |
@@ -232,7 +234,7 @@ class Listener { | |||
| 232 | 234 | this.weak = Boolean(weak); // Don't retain the object | |
| 233 | 235 | ||
| 234 | 236 | if (this.weak) { | |
| 235 | - this.callback = new globalThis.WeakRef(listener); | ||
| 237 | + this.callback = new SafeWeakRef(listener); | ||
| 236 | 238 | weakListeners().registry.register(listener, this, this); | |
| 237 | 239 | // Make the retainer retain the listener in a WeakMap | |
| 238 | 240 | weakListeners().map.set(weak, listener); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -163,6 +163,7 @@ function copyPrototype(src, dest, prefix) { | |||
| 163 | 163 | 'Date', | |
| 164 | 164 | 'Error', | |
| 165 | 165 | 'EvalError', | |
| 166 | + 'FinalizationRegistry', | ||
| 166 | 167 | 'Float32Array', | |
| 167 | 168 | 'Float64Array', | |
| 168 | 169 | 'Function', | |
@@ -186,6 +187,7 @@ function copyPrototype(src, dest, prefix) { | |||
| 186 | 187 | 'Uint8Array', | |
| 187 | 188 | 'Uint8ClampedArray', | |
| 188 | 189 | 'WeakMap', | |
| 190 | + 'WeakRef', | ||
| 189 | 191 | 'WeakSet', | |
| 190 | 192 | ].forEach((name) => { | |
| 191 | 193 | const original = global[name]; | |
@@ -229,13 +231,15 @@ function copyPrototype(src, dest, prefix) { | |||
| 229 | 231 | ||
| 230 | 232 | const { | |
| 231 | 233 | ArrayPrototypeForEach, | |
| 234 | + FinalizationRegistry, | ||
| 232 | 235 | FunctionPrototypeCall, | |
| 233 | 236 | Map, | |
| 234 | 237 | ObjectFreeze, | |
| 235 | 238 | ObjectSetPrototypeOf, | |
| 236 | 239 | Set, | |
| 237 | 240 | SymbolIterator, | |
| 238 | 241 | WeakMap, | |
| 242 | + WeakRef, | ||
| 239 | 243 | WeakSet, | |
| 240 | 244 | } = primordials; | |
| 241 | 245 | ||
@@ -334,6 +338,7 @@ primordials.SafeWeakMap = makeSafe( | |||
| 334 | 338 | constructor(i) { super(i); } // eslint-disable-line no-useless-constructor | |
| 335 | 339 | } | |
| 336 | 340 | ); | |
| 341 | + | ||
| 337 | 342 | primordials.SafeSet = makeSafe( | |
| 338 | 343 | Set, | |
| 339 | 344 | class SafeSet extends Set { | |
@@ -347,5 +352,20 @@ primordials.SafeWeakSet = makeSafe( | |||
| 347 | 352 | } | |
| 348 | 353 | ); | |
| 349 | 354 | ||
| 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 | + | ||
| 350 | 370 | ObjectSetPrototypeOf(primordials, null); | |
| 351 | 371 | ObjectFreeze(primordials); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,25 +1,14 @@ | |||
| 1 | 1 | 'use strict'; | |
| 2 | 2 | ||
| 3 | 3 | const { | |
| 4 | - makeSafe, | ||
| 5 | 4 | ObjectFreeze, | |
| 5 | + SafeFinalizationRegistry, | ||
| 6 | 6 | SafeSet, | |
| 7 | 7 | SafeWeakMap, | |
| 8 | + SafeWeakRef, | ||
| 8 | 9 | SymbolIterator, | |
| 9 | 10 | } = primordials; | |
| 10 | 11 | ||
| 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 | - | ||
| 23 | 12 | // This class is modified from the example code in the WeakRefs specification: | |
| 24 | 13 | // https://github.com/tc39/proposal-weakrefs | |
| 25 | 14 | // Licensed under ECMA's MIT-style license, see: | |
| Back | FazBrowse Home | New Git URL |
0 commit comments