Skip to content

Commit

Permalink
fixup! lib: add WeakRef and FinalizationRegistry to primordials
Browse files Browse the repository at this point in the history
  • Loading branch information
ExE-Boss committed Feb 7, 2021
1 parent 9a951fa commit 846fc79
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions lib/internal/per_context/primordials.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@ function copyPrototype(src, dest, prefix) {
'Date',
'Error',
'EvalError',
'FinalizationRegistry',
'Float32Array',
'Float64Array',
'Function',
Expand All @@ -182,7 +181,6 @@ function copyPrototype(src, dest, prefix) {
'Uint8Array',
'Uint8ClampedArray',
'WeakMap',
'WeakRef',
'WeakSet',
].forEach((name) => {
const original = global[name];
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 846fc79

Please sign in to comment.