Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

typings: improve primordials typings #46970

Merged
merged 1 commit into from
Mar 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 }
}