Skip to content

Commit 78b79c0

Browse files
aduh95danielleadams
authored andcommitted
typings: improve primordials typings
PR-URL: #46970 Reviewed-By: Moshe Atlow <moshe@atlow.co.il> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
1 parent 43b94b0 commit 78b79c0

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

lib/internal/per_context/primordials.js

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -307,9 +307,21 @@ const {
307307
WeakSet,
308308
} = primordials;
309309

310-
// Because these functions are used by `makeSafe`, which is exposed
311-
// on the `primordials` object, it's important to use const references
312-
// to the primordials that they use:
310+
311+
/**
312+
* Creates a class that can be safely iterated over.
313+
*
314+
* Because these functions are used by `makeSafe`, which is exposed on the
315+
* `primordials` object, it's important to use const references to the
316+
* primordials that they use.
317+
*
318+
* @template {Iterable} T
319+
* @template {*} TReturn
320+
* @template {*} TNext
321+
* @param {(self: T) => IterableIterator<T>} factory
322+
* @param {(...args: [] | [TNext]) => IteratorResult<T, TReturn>} next
323+
* @returns {Iterator<T, TReturn, TNext>}
324+
*/
313325
const createSafeIterator = (factory, next) => {
314326
class SafeIterator {
315327
constructor(iterable) {
@@ -617,6 +629,10 @@ class RegExpLikeForStringSplitting {
617629
}
618630
ObjectSetPrototypeOf(RegExpLikeForStringSplitting.prototype, null);
619631

632+
/**
633+
* @param {RegExp} pattern
634+
* @returns {RegExp}
635+
*/
620636
primordials.hardenRegExp = function hardenRegExp(pattern) {
621637
ObjectDefineProperties(pattern, {
622638
[SymbolMatch]: {
@@ -706,6 +722,11 @@ primordials.hardenRegExp = function hardenRegExp(pattern) {
706722
};
707723

708724

725+
/**
726+
* @param {string} str
727+
* @param {RegExp} regexp
728+
* @returns {number}
729+
*/
709730
primordials.SafeStringPrototypeSearch = (str, regexp) => {
710731
regexp.lastIndex = 0;
711732
const match = RegExpPrototypeExec(regexp, str);

typings/primordials.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -597,4 +597,7 @@ declare namespace primordials {
597597
export const PromisePrototypeThen: UncurryThis<typeof Promise.prototype.then>
598598
export const PromisePrototypeCatch: UncurryThis<typeof Promise.prototype.catch>
599599
export const PromisePrototypeFinally: UncurryThis<typeof Promise.prototype.finally>
600+
export import Proxy = globalThis.Proxy
601+
import _globalThis = globalThis
602+
export { _globalThis as globalThis }
600603
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy