From f6aecebcc3f5d0d06e717775b73e2b18af9bf0b6 Mon Sep 17 00:00:00 2001 From: James M Snell Date: Mon, 12 Oct 2026 11:36:32 +0000 Subject: [PATCH] lib: avoid using __proto__: null in AbortController/AbortSignal Using `__proto__: null` on objects will properties immediately puts them into the slower DictionaryProperties mode. Using a `__proto__: { __proto: null }, ...` pattern, however, keeps the objects in FastProperties mode. Technically this is an observable change since calling `Object.getPrototoTypeOf(...)` some of these will no longer return `null`. So a decision needs to be made about whether these types of changes are `semver-major` or not. Signed-off-by: James M Snell --- lib/internal/abort_controller.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/internal/abort_controller.js b/lib/internal/abort_controller.js index 9f524d5cb5e2..ce95476aea00 100644 --- a/lib/internal/abort_controller.js +++ b/lib/internal/abort_controller.js @@ -33,6 +33,7 @@ const { const { kMaxEventTargetListeners } = require('events'); const { customInspectSymbol, + kEmptyObject, kEnumerableProperty, } = require('internal/util'); const { inspect } = require('internal/util/inspect'); @@ -376,7 +377,7 @@ class AbortSignal extends EventTarget { static any(signals) { const signalsArray = converters['sequence']( signals, - { __proto__: null, context: 'signals' }, + { __proto__: kEmptyObject, context: 'signals' }, ); const resultSignal = new AbortSignal(kDontThrowSymbol, false, undefined, false, true); @@ -478,7 +479,7 @@ class AbortSignal extends EventTarget { if (aborted) { const reason = this.reason; return { - data: { aborted, reason }, + data: { __proto__: kEmptyObject, aborted, reason }, deserializeInfo: 'internal/abort_controller:ClonedAbortSignal', }; } @@ -489,10 +490,10 @@ class AbortSignal extends EventTarget { this.addEventListener('abort', () => { port1.postMessage(this.reason); port1.close(); - }, { once: true }); + }, { __proto__: kEmptyObject, once: true }); return { - data: { port: port2 }, + data: { __proto__: kEmptyObject, port: port2 }, deserializeInfo: 'internal/abort_controller:ClonedAbortSignal', }; } @@ -685,12 +686,12 @@ function transferableAbortController() { * @returns {Promise} */ async function aborted(signal, resource) { - converters.AbortSignal(signal, { __proto__: null, context: 'signal' }); + converters.AbortSignal(signal, { __proto__: kEmptyObject, context: 'signal' }); validateObject(resource, 'resource', kValidateObjectAllowObjects); if (signal.aborted) return PromiseResolve(); const abortPromise = PromiseWithResolvers(); - const opts = { __proto__: null, [kWeakHandler]: resource, once: true, [kResistStopPropagation]: true }; + const opts = { __proto__: kEmptyObject, [kWeakHandler]: resource, once: true, [kResistStopPropagation]: true }; signal.addEventListener('abort', abortPromise.resolve, opts); return abortPromise.promise; }