From 0c460518e8c0728294cfbb5313d347a62856a2c5 Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Wed, 8 Mar 2023 11:47:26 +0100 Subject: [PATCH] typings: improve `primordials` typings PR-URL: https://github.com/nodejs/node/pull/46970 Reviewed-By: Moshe Atlow Reviewed-By: Yagiz Nizipli --- lib/internal/per_context/primordials.js | 27 ++++++++++++++++++++++--- typings/primordials.d.ts | 3 +++ 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/lib/internal/per_context/primordials.js b/lib/internal/per_context/primordials.js index 496383a76825ce..59c285cd16d165 100644 --- a/lib/internal/per_context/primordials.js +++ b/lib/internal/per_context/primordials.js @@ -307,9 +307,21 @@ const { WeakSet, } = primordials; -// Because these functions are used by `makeSafe`, which is exposed -// on the `primordials` object, it's important to use const references -// to the primordials that they use: + +/** + * Creates a class that can be safely iterated over. + * + * Because these functions are used by `makeSafe`, which is exposed on the + * `primordials` object, it's important to use const references to the + * primordials that they use. + * + * @template {Iterable} T + * @template {*} TReturn + * @template {*} TNext + * @param {(self: T) => IterableIterator} factory + * @param {(...args: [] | [TNext]) => IteratorResult} next + * @returns {Iterator} + */ const createSafeIterator = (factory, next) => { class SafeIterator { constructor(iterable) { @@ -617,6 +629,10 @@ class RegExpLikeForStringSplitting { } ObjectSetPrototypeOf(RegExpLikeForStringSplitting.prototype, null); +/** + * @param {RegExp} pattern + * @returns {RegExp} + */ primordials.hardenRegExp = function hardenRegExp(pattern) { ObjectDefineProperties(pattern, { [SymbolMatch]: { @@ -706,6 +722,11 @@ primordials.hardenRegExp = function hardenRegExp(pattern) { }; +/** + * @param {string} str + * @param {RegExp} regexp + * @returns {number} + */ primordials.SafeStringPrototypeSearch = (str, regexp) => { regexp.lastIndex = 0; const match = RegExpPrototypeExec(regexp, str); diff --git a/typings/primordials.d.ts b/typings/primordials.d.ts index 4dcbac3abc9425..e1aa6419031115 100644 --- a/typings/primordials.d.ts +++ b/typings/primordials.d.ts @@ -597,4 +597,7 @@ declare namespace primordials { export const PromisePrototypeThen: UncurryThis export const PromisePrototypeCatch: UncurryThis export const PromisePrototypeFinally: UncurryThis + export import Proxy = globalThis.Proxy + import _globalThis = globalThis + export { _globalThis as globalThis } }