From 76e5ca6fe0f0c0253ea91326b1feec89cd8f8c78 Mon Sep 17 00:00:00 2001 From: LiviaMedeiros Date: Tue, 17 Nov 2026 04:05:29 +0800 Subject: [PATCH] lib: add ERM classes to primordials Totes three classes: - `DisposableStack` - `AsyncDisposableStack` - `SuppressedError` Signed-off-by: LiviaMedeiros PR-URL: https://github.com/nodejs/node/pull/67533 Reviewed-By: Antoine du Hamel Reviewed-By: James M Snell --- lib/eslint.config_partial.mjs | 10 ------- lib/internal/freeze_intrinsics.js | 35 +++++++++++++++++-------- lib/internal/per_context/primordials.js | 3 +++ typings/primordials.d.ts | 18 +++++++++++++ 4 files changed, 45 insertions(+), 21 deletions(-) diff --git a/lib/eslint.config_partial.mjs b/lib/eslint.config_partial.mjs index cc1ad67d917..1bb6bad8d7d 100644 --- a/lib/eslint.config_partial.mjs +++ b/lib/eslint.config_partial.mjs @@ -412,16 +412,6 @@ export default [ name: 'SubtleCrypto', message: "Use `const { SubtleCrypto } = require('internal/crypto/webcrypto');` instead of the global.", }, - // DisposableStack and AsyncDisposableStack are not available in primordials because they can be - // disabled with --no-js-explicit-resource-management CLI flag. - { - name: 'DisposableStack', - message: 'Use `const { DisposableStack } = globalThis;` instead of the global.', - }, - { - name: 'AsyncDisposableStack', - message: 'Use `const { AsyncDisposableStack } = globalThis;` instead of the global.', - }, ], 'no-restricted-modules': [ 'error', diff --git a/lib/internal/freeze_intrinsics.js b/lib/internal/freeze_intrinsics.js index 5dd425cb093..3f1e397ec19 100644 --- a/lib/internal/freeze_intrinsics.js +++ b/lib/internal/freeze_intrinsics.js @@ -31,6 +31,8 @@ const { ArrayPrototype, ArrayPrototypeForEach, ArrayPrototypePush, + AsyncDisposableStack, + AsyncDisposableStackPrototype, AsyncFunctionPrototype, AsyncGeneratorFunctionPrototype, AsyncGeneratorFunctionPrototypePrototype, @@ -48,6 +50,8 @@ const { DataViewPrototype, Date, DatePrototype, + DisposableStack, + DisposableStackPrototype, Error, ErrorPrototype, EvalError, @@ -106,6 +110,8 @@ const { String, StringIteratorPrototype, StringPrototype, + SuppressedError, + SuppressedErrorPrototype, Symbol, SymbolPrototype, SyntaxError, @@ -171,6 +177,7 @@ module.exports = function() { EvalErrorPrototype, RangeErrorPrototype, ReferenceErrorPrototype, + SuppressedErrorPrototype, SyntaxErrorPrototype, TypeErrorPrototype, URIErrorPrototype, @@ -225,12 +232,14 @@ module.exports = function() { IteratorPrototype, // 27.1.3 WrapForValidIteratorPrototype, // 27.1.3.2.2.1 AsyncIteratorPrototype, // 27.1.4 - PromisePrototype, // 27.2 - GeneratorFunctionPrototype, // 27.3 - AsyncGeneratorFunctionPrototype, // 27.4 - // 27.5 GeneratorPrototype + DisposableStackPrototype, // 27.3.2.1 + AsyncDisposableStackPrototype, // 27.4.2.1 + PromisePrototype, // 27.5.4.4 + GeneratorFunctionPrototype, // 27.6.2.1 + AsyncGeneratorFunctionPrototype, // 27.7.3.3 + // 27.8 GeneratorPrototype GeneratorFunctionPrototypePrototype, - // 27.6 AsyncGeneratorPrototype + // 27.9 AsyncGeneratorPrototype AsyncGeneratorFunctionPrototypePrototype, AsyncFunctionPrototype, // 27.7 @@ -270,6 +279,7 @@ module.exports = function() { EvalError, RangeError, ReferenceError, + SuppressedError, SyntaxError, TypeError, URIError, @@ -329,14 +339,17 @@ module.exports = function() { Iterator, // 27.1.3 WrapForValidIteratorPrototype, // 27.1.3.2.2.1 ArrayIteratorPrototype, // 27.1.4 - Promise, // 27.2 - // 27.3 GeneratorFunction - // 27.5 Generator + // 27.2 SymbolDispose + DisposableStack, // 27.3 + AsyncDisposableStack, // 27.4 + Promise, // 27.5 + // 27.6 GeneratorFunction + // 27.8 Generator GeneratorFunctionPrototype, - // 27.4 AsyncGeneratorFunction - // 27.6 AsyncGenerator + // 27.7 AsyncGeneratorFunction + // 27.9 AsyncGenerator AsyncGeneratorFunctionPrototype, - // 27.7 AsyncFunction + // 27.10 AsyncFunction AsyncFunctionPrototype, // 28 Reflection diff --git a/lib/internal/per_context/primordials.js b/lib/internal/per_context/primordials.js index 2e610f4ab50..582c91126b3 100644 --- a/lib/internal/per_context/primordials.js +++ b/lib/internal/per_context/primordials.js @@ -187,12 +187,14 @@ function copyPrototype(src, dest, prefix) { 'AggregateError', 'Array', 'ArrayBuffer', + 'AsyncDisposableStack', 'BigInt', 'BigInt64Array', 'BigUint64Array', 'Boolean', 'DataView', 'Date', + 'DisposableStack', 'Error', 'EvalError', 'FinalizationRegistry', @@ -212,6 +214,7 @@ function copyPrototype(src, dest, prefix) { 'RegExp', 'Set', 'String', + 'SuppressedError', 'Symbol', 'SyntaxError', 'TypeError', diff --git a/typings/primordials.d.ts b/typings/primordials.d.ts index 7a424c72950..63a75bbee04 100644 --- a/typings/primordials.d.ts +++ b/typings/primordials.d.ts @@ -168,6 +168,14 @@ declare namespace primordials { export const ArrayBufferPrototypeSlice: UncurryThis export const ArrayBufferPrototypeTransfer: UncurryThis export const ArrayBufferPrototypeGetByteLength: UncurryGetter; + export import AsyncDisposableStack = globalThis.AsyncDisposableStack, + export const AsyncDisposableStackPrototype: typeof AsyncDisposableStack.prototype + export const AsyncDisposableStackAdopt: UncurryThis + export const AsyncDisposableStackDefer: UncurryThis + export const AsyncDisposableStackDispose: UncurryThis + export const AsyncDisposableStackMove: UncurryThis + export const AsyncDisposableStackUse: UncurryThis + export const AsyncDisposableStackSymbolAsyncDispose: UncurryMethod; export import BigInt = globalThis.BigInt; export const BigIntPrototype: typeof BigInt.prototype export const BigIntAsUintN: typeof BigInt.asUintN @@ -259,6 +267,14 @@ declare namespace primordials { export const DatePrototypeToLocaleDateString: UncurryThis export const DatePrototypeToLocaleTimeString: UncurryThis export const DatePrototypeSymbolToPrimitive: UncurryMethod; + export import DisposableStack = globalThis.DisposableStack, + export const DisposableStackPrototype: typeof DisposableStack.prototype + export const DisposableStackAdopt: UncurryThis + export const DisposableStackDefer: UncurryThis + export const DisposableStackDispose: UncurryThis + export const DisposableStackMove: UncurryThis + export const DisposableStackUse: UncurryThis + export const DisposableStackSymbolDispose: UncurryMethod; export import Error = globalThis.Error; export const ErrorPrototype: typeof Error.prototype // @ts-ignore @@ -444,6 +460,8 @@ declare namespace primordials { export const StringPrototypeToWellFormed: UncurryThis export const StringPrototypeValueOf: UncurryThis export const StringPrototypeReplaceAll: UncurryThis + export import SuppressedError = globalThis.SuppressedError; + export const SuppressedErrorPrototype: typeof SuppressedError.prototype export import Symbol = globalThis.Symbol; export const SymbolPrototype: typeof Symbol.prototype export const SymbolFor: typeof Symbol.for