From 846fc79dff31f3058b0c0260769877cfd6f8e895 Mon Sep 17 00:00:00 2001 From: ExE Boss <3889017+ExE-Boss@users.noreply.github.com> Date: Sun, 7 Feb 2021 16:00:00 +0100 Subject: [PATCH] =?UTF-8?q?fixup!=20lib:=20add=C2=A0`WeakRef`=20and=C2=A0`?= =?UTF-8?q?FinalizationRegistry`=20to=C2=A0`primordials`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/internal/per_context/primordials.js | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/lib/internal/per_context/primordials.js b/lib/internal/per_context/primordials.js index 81ea3c3c0fd916..27a759ac7e6f22 100644 --- a/lib/internal/per_context/primordials.js +++ b/lib/internal/per_context/primordials.js @@ -158,7 +158,6 @@ function copyPrototype(src, dest, prefix) { 'Date', 'Error', 'EvalError', - 'FinalizationRegistry', 'Float32Array', 'Float64Array', 'Function', @@ -182,7 +181,6 @@ function copyPrototype(src, dest, prefix) { 'Uint8Array', 'Uint8ClampedArray', 'WeakMap', - 'WeakRef', 'WeakSet', ].forEach((name) => { const original = global[name]; @@ -191,6 +189,19 @@ function copyPrototype(src, dest, prefix) { copyPrototype(original.prototype, primordials, `${name}Prototype`); }); +// Copy potentially `undefined` primordials: +[ + 'FinalizationRegistry', + 'WeakRef', +].forEach((name) => { + const original = global[name]; + if (original) { + primordials[name] = original; + copyPropsRenamed(original, primordials, name); + copyPrototype(original.prototype, primordials, `${name}Prototype`); + } +}); + // Create copies of intrinsic objects that require a valid `this` to call // static methods. // Refs: https://www.ecma-international.org/ecma-262/#sec-promise.all @@ -344,14 +355,14 @@ primordials.SafeWeakSet = makeSafe( } ); -primordials.SafeFinalizationRegistry = makeSafe( +if (FinalizationRegistry) primordials.SafeFinalizationRegistry = makeSafe( FinalizationRegistry, class SafeFinalizationRegistry extends FinalizationRegistry { // eslint-disable-next-line no-useless-constructor constructor(cleanupCallback) { super(cleanupCallback); } } ); -primordials.SafeWeakRef = makeSafe( +if (WeakRef) primordials.SafeWeakRef = makeSafe( WeakRef, class SafeWeakRef extends WeakRef { // eslint-disable-next-line no-useless-constructor