Skip to content

Commit

Permalink
typings: improve primordials typings
Browse files Browse the repository at this point in the history
PR-URL: #46970
Reviewed-By: Moshe Atlow <[email protected]>
Reviewed-By: Yagiz Nizipli <[email protected]>
  • Loading branch information
aduh95 authored and targos committed Mar 14, 2023
1 parent 5f0f1c4 commit 63a83b4
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
27 changes: 24 additions & 3 deletions lib/internal/per_context/primordials.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>} factory
* @param {(...args: [] | [TNext]) => IteratorResult<T, TReturn>} next
* @returns {Iterator<T, TReturn, TNext>}
*/
const createSafeIterator = (factory, next) => {
class SafeIterator {
constructor(iterable) {
Expand Down Expand Up @@ -617,6 +629,10 @@ class RegExpLikeForStringSplitting {
}
ObjectSetPrototypeOf(RegExpLikeForStringSplitting.prototype, null);

/**
* @param {RegExp} pattern
* @returns {RegExp}
*/
primordials.hardenRegExp = function hardenRegExp(pattern) {
ObjectDefineProperties(pattern, {
[SymbolMatch]: {
Expand Down Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions typings/primordials.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -597,4 +597,7 @@ declare namespace primordials {
export const PromisePrototypeThen: UncurryThis<typeof Promise.prototype.then>
export const PromisePrototypeCatch: UncurryThis<typeof Promise.prototype.catch>
export const PromisePrototypeFinally: UncurryThis<typeof Promise.prototype.finally>
export import Proxy = globalThis.Proxy
import _globalThis = globalThis
export { _globalThis as globalThis }
}

0 comments on commit 63a83b4

Please sign in to comment.