diff --git a/lib/modules/src/finders/filters.ts b/lib/modules/src/finders/filters.ts index c82fe9a..ee4bcb1 100644 --- a/lib/modules/src/finders/filters.ts +++ b/lib/modules/src/finders/filters.ts @@ -85,7 +85,7 @@ export type ByProps = FilterGenerator< > /** - * Filter modules by their exports having all of the specified properties with truthy values. + * Filter modules by their exports having all of the specified properties. * * @param prop The property to check for. * @param props More properties to check for (optional). @@ -98,7 +98,8 @@ export type ByProps = FilterGenerator< */ export const byProps = createFilterGenerator>( (props, _, exports) => { - if (exports instanceof Object) { + const type = typeof exports + if (type === 'object' || type === 'function') { for (const prop of props) { if (prop in exports) continue return false @@ -127,7 +128,8 @@ export type WithoutProps = FilterGenerator< */ export const withoutProps = createFilterGenerator>( (props, _, exports) => { - if (exports instanceof Object) + const type = typeof exports + if (type === 'object' || type === 'function') for (const prop of props) if (prop in exports) return false return true @@ -152,7 +154,7 @@ export type BySingleProp = FilterGenerator< */ export const bySingleProp = createFilterGenerator>( ([prop], _, exports) => { - if (exports instanceof Object && prop in exports) { + if (typeof exports === 'object' && prop in exports) { let hasMultipleProperties = false for (const _ in exports) { if (hasMultipleProperties) return false diff --git a/lib/modules/src/metro/patches.ts b/lib/modules/src/metro/patches.ts index 42c167e..eeed3d1 100644 --- a/lib/modules/src/metro/patches.ts +++ b/lib/modules/src/metro/patches.ts @@ -116,22 +116,23 @@ function handleFactoryCall( // Blacklist exports that: // - are primitives (https://developer.mozilla.org/en-US/docs/Glossary/Primitive) // - are empty objects - if (exports instanceof Object) - switch (exports.__proto__) { - case Object.prototype: - // This null case is for nativeModuleProxy specifically - // @ts-expect-error: Intentional - // biome-ignore lint/suspicious/noFallthroughSwitchClause: Intentional - case null: - if (!Reflect.ownKeys(exports).length) { - cacheBlacklistedModule(mInitializingId) - break - } + switch (typeof exports) { + case 'function': + mInitialized.add(mInitializingId) + break - default: + // @ts-expect-error: Intentional + // biome-ignore lint/suspicious/noFallthroughSwitchClause: Intentional + case 'object': { + if (Reflect.ownKeys(exports).length) { mInitialized.add(mInitializingId) + break + } } - else cacheBlacklistedModule(mInitializingId) + + default: + cacheBlacklistedModule(mInitializingId) + } } executeInitializeSubscriptions(mInitializingId, exports) diff --git a/lib/utils/src/discord.ts b/lib/utils/src/discord.ts index a79898e..a12a10f 100644 --- a/lib/utils/src/discord.ts +++ b/lib/utils/src/discord.ts @@ -82,8 +82,8 @@ export const byGeneratedIconComponent = createFilterGenerator< Parameters >( (names, id, exports) => { - if (exports instanceof Object) { - if (exports[names[0]] instanceof Function) { + if (typeof exports === 'object') { + if (typeof exports[names[0]] === 'function') { let hasMultipleProps = false for (const _ in exports) { if (hasMultipleProps) return false diff --git a/lib/utils/src/object.ts b/lib/utils/src/object.ts index 464107a..ab28a54 100644 --- a/lib/utils/src/object.ts +++ b/lib/utils/src/object.ts @@ -8,7 +8,7 @@ export { objectFreeze } from './patches/object' * @param val The value to check. */ export function isObject(val: any): val is AnyObject { - return val?.__proto__ === Object.prototype + return typeof val === 'object' && val !== null && !Array.isArray(val) } /** diff --git a/lib/utils/src/proxy.ts b/lib/utils/src/proxy.ts index 36e808a..4be9c49 100644 --- a/lib/utils/src/proxy.ts +++ b/lib/utils/src/proxy.ts @@ -61,7 +61,7 @@ const _handler = { const target = unproxifyFromHint(hint) const val = Reflect.get(target!, p, recv) - if (_metas.get(hint)?.bind && val instanceof Function) + if (_metas.get(hint)?.bind && typeof val === 'function') return new Proxy(val, { // If thisArg happens to be a proxified value, we will use the target object instead apply: (fn, thisArg, args) =>