diff --git a/lib/.eslintrc.yaml b/lib/.eslintrc.yaml index 3911b421be1356..2cc2660157191f 100644 --- a/lib/.eslintrc.yaml +++ b/lib/.eslintrc.yaml @@ -25,10 +25,6 @@ rules: message: "Please use `require('internal/errors').hideStackFrames()` instead." - selector: "AssignmentExpression:matches([left.name='prepareStackTrace'], [left.property.name='prepareStackTrace'])" message: "Use 'overrideStackTrace' from 'lib/internal/errors.js' instead of 'Error.prepareStackTrace'." - no-restricted-globals: - - error - - name: globalThis - message: "Use `const { globalThis } = primordials;` instead of the global." # Custom rules in tools/eslint-rules node-core/lowercase-name-for-primitive: error node-core/non-ascii-character: error @@ -52,8 +48,6 @@ rules: - prepareStackTrace - stackTraceLimit - name: EvalError - - name: FinalizationRegistry - into: Safe - name: Float32Array - name: Float64Array - name: Function @@ -92,8 +86,6 @@ rules: - name: URIError - name: WeakMap into: Safe - - name: WeakRef - into: Safe - name: WeakSet into: Safe globals: diff --git a/lib/internal/event_target.js b/lib/internal/event_target.js index 026746825b7767..02166bcc783fe2 100644 --- a/lib/internal/event_target.js +++ b/lib/internal/event_target.js @@ -14,10 +14,8 @@ const { ObjectGetOwnPropertyDescriptors, ReflectApply, SafeArrayIterator, - SafeFinalizationRegistry, SafeMap, SafeWeakMap, - SafeWeakRef, SafeWeakSet, String, Symbol, @@ -203,7 +201,7 @@ let weakListenersState = null; // get garbage collected now that it's weak. let objectToWeakListenerMap = null; function weakListeners() { - weakListenersState ??= new SafeFinalizationRegistry( + weakListenersState ??= new globalThis.FinalizationRegistry( (listener) => listener.remove() ); objectToWeakListenerMap ??= new SafeWeakMap(); @@ -234,7 +232,7 @@ class Listener { this.weak = Boolean(weak); // Don't retain the object if (this.weak) { - this.callback = new SafeWeakRef(listener); + this.callback = new globalThis.WeakRef(listener); weakListeners().registry.register(listener, this, this); // Make the retainer retain the listener in a WeakMap weakListeners().map.set(weak, listener); diff --git a/lib/internal/modules/esm/loader.js b/lib/internal/modules/esm/loader.js index 8b2c89ba130aa7..14e66dcb9fdf62 100644 --- a/lib/internal/modules/esm/loader.js +++ b/lib/internal/modules/esm/loader.js @@ -9,7 +9,6 @@ const { RegExpPrototypeExec, SafeWeakMap, StringPrototypeStartsWith, - globalThis, } = primordials; const { diff --git a/lib/internal/per_context/primordials.js b/lib/internal/per_context/primordials.js index a1e9f3ae305e32..f6f960eabdf316 100644 --- a/lib/internal/per_context/primordials.js +++ b/lib/internal/per_context/primordials.js @@ -131,14 +131,6 @@ function copyPrototype(src, dest, prefix) { } } -// Create copies of configurable value properties of the global object -[ - 'globalThis', -].forEach((name) => { - // eslint-disable-next-line no-restricted-globals - primordials[name] = globalThis[name]; -}); - // Create copies of URI handling functions [ decodeURI, @@ -171,7 +163,6 @@ function copyPrototype(src, dest, prefix) { 'Date', 'Error', 'EvalError', - 'FinalizationRegistry', 'Float32Array', 'Float64Array', 'Function', @@ -195,7 +186,6 @@ function copyPrototype(src, dest, prefix) { 'Uint8Array', 'Uint8ClampedArray', 'WeakMap', - 'WeakRef', 'WeakSet', ].forEach((name) => { const original = global[name]; @@ -239,7 +229,6 @@ function copyPrototype(src, dest, prefix) { const { ArrayPrototypeForEach, - FinalizationRegistry, FunctionPrototypeCall, Map, ObjectFreeze, @@ -247,7 +236,6 @@ const { Set, SymbolIterator, WeakMap, - WeakRef, WeakSet, } = primordials; @@ -346,7 +334,6 @@ primordials.SafeWeakMap = makeSafe( constructor(i) { super(i); } // eslint-disable-line no-useless-constructor } ); - primordials.SafeSet = makeSafe( Set, class SafeSet extends Set { @@ -360,20 +347,5 @@ primordials.SafeWeakSet = makeSafe( } ); -primordials.SafeFinalizationRegistry = makeSafe( - FinalizationRegistry, - class SafeFinalizationRegistry extends FinalizationRegistry { - // eslint-disable-next-line no-useless-constructor - constructor(cleanupCallback) { super(cleanupCallback); } - } -); -primordials.SafeWeakRef = makeSafe( - WeakRef, - class SafeWeakRef extends WeakRef { - // eslint-disable-next-line no-useless-constructor - constructor(target) { super(target); } - } -); - ObjectSetPrototypeOf(primordials, null); ObjectFreeze(primordials); diff --git a/lib/internal/process/execution.js b/lib/internal/process/execution.js index e370770643ca6f..314b8b0a03c161 100644 --- a/lib/internal/process/execution.js +++ b/lib/internal/process/execution.js @@ -1,9 +1,5 @@ 'use strict'; -const { - globalThis, -} = primordials; - const path = require('path'); const { diff --git a/lib/internal/test/binding.js b/lib/internal/test/binding.js index d00ef89a16111b..063b9b5c900aad 100644 --- a/lib/internal/test/binding.js +++ b/lib/internal/test/binding.js @@ -1,9 +1,5 @@ 'use strict'; -const { - globalThis, -} = primordials; - process.emitWarning( 'These APIs are for internal testing only. Do not use them.', 'internal/test/binding'); diff --git a/lib/internal/util/iterable_weak_map.js b/lib/internal/util/iterable_weak_map.js index 0842622d2451b3..c9715a7e313b20 100644 --- a/lib/internal/util/iterable_weak_map.js +++ b/lib/internal/util/iterable_weak_map.js @@ -1,14 +1,25 @@ 'use strict'; const { + makeSafe, ObjectFreeze, - SafeFinalizationRegistry, SafeSet, SafeWeakMap, - SafeWeakRef, SymbolIterator, } = primordials; +// TODO(aduh95): Add FinalizationRegistry to primordials +const SafeFinalizationRegistry = makeSafe( + globalThis.FinalizationRegistry, + class SafeFinalizationRegistry extends globalThis.FinalizationRegistry {} +); + +// TODO(aduh95): Add WeakRef to primordials +const SafeWeakRef = makeSafe( + globalThis.WeakRef, + class SafeWeakRef extends globalThis.WeakRef {} +); + // This class is modified from the example code in the WeakRefs specification: // https://github.com/tc39/proposal-weakrefs // Licensed under ECMA's MIT-style license, see: diff --git a/lib/internal/v8_prof_polyfill.js b/lib/internal/v8_prof_polyfill.js index 2b6b90c58d1147..c4140bab54168c 100644 --- a/lib/internal/v8_prof_polyfill.js +++ b/lib/internal/v8_prof_polyfill.js @@ -72,7 +72,6 @@ function read(fileName) { } const quit = process.exit; // Polyfill "readline()". -// eslint-disable-next-line no-restricted-globals const logFile = globalThis.arguments[globalThis.arguments.length - 1]; try { fs.accessSync(logFile); @@ -162,7 +161,6 @@ function macCppfiltNm(out) { }); } -// eslint-disable-next-line no-restricted-globals Object.assign(globalThis, { os, print,