Skip to content

Commit

Permalink
Add defineGetter to registry lib/objects
Browse files Browse the repository at this point in the history
  • Loading branch information
jdalton committed Jan 17, 2025
1 parent 30ca7df commit deac9ee
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
5 changes: 5 additions & 0 deletions registry/lib/constants.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ interface Internals {
getter: () => T,
stats?: LazyGetterStats
) => () => T
readonly defineGetter: <T>(
object: object,
propKey: PropertyKey,
getter: () => T
) => object
readonly defineLazyGetter: <T>(
object: object,
propKey: PropertyKey,
Expand Down
13 changes: 7 additions & 6 deletions registry/lib/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ const matcherCache = new Map()
const internalsMixin = {
createConstantsObject,
createLazyGetter,
defineGetter,
defineLazyGetter,
defineLazyGetters,
getGlobMatcher,
Expand Down Expand Up @@ -195,15 +196,15 @@ function createLazyGetter(name, getter, stats) {
return lazyGetter
}

function defineLazyGetter(object, propKey, getter, stats) {
__defineGetter__.call(
object,
propKey,
createLazyGetter(propKey, getter, stats)
)
function defineGetter(object, propKey, getter) {
__defineGetter__.call(object, propKey, getter)
return object
}

function defineLazyGetter(object, propKey, getter, stats) {
return defineGetter(object, propKey, createLazyGetter(propKey, getter, stats))
}

function defineLazyGetters(object, getterDefObj, stats) {
if (getterDefObj !== null && typeof getterDefObj === 'object') {
const keys = Reflect.ownKeys(getterDefObj)
Expand Down
1 change: 1 addition & 0 deletions registry/lib/objects.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ declare function toSortedObjectFromEntries<T>(
}
declare const objectsModule: {
createLazyGetter: Internals['createLazyGetter']
defineGetter: Internals['defineGetter']
defineLazyGetter: Internals['defineLazyGetter']
defineLazyGetters: Internals['defineLazyGetters']
getOwnPropertyValues: typeof getOwnPropertyValues
Expand Down
2 changes: 2 additions & 0 deletions registry/lib/objects.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const {
kInternalsSymbol,
[kInternalsSymbol]: {
createLazyGetter,
defineGetter,
defineLazyGetter,
defineLazyGetters,
objectEntries,
Expand Down Expand Up @@ -126,6 +127,7 @@ function toSortedObjectFromEntries(entries) {

module.exports = {
createLazyGetter,
defineGetter,
defineLazyGetter,
defineLazyGetters,
getOwnPropertyValues,
Expand Down

0 comments on commit deac9ee

Please sign in to comment.