diff --git a/src/core/features/siteplugins/services/siteplugins-helper.ts b/src/core/features/siteplugins/services/siteplugins-helper.ts index 2d674dac2..1c715bb6d 100644 --- a/src/core/features/siteplugins/services/siteplugins-helper.ts +++ b/src/core/features/siteplugins/services/siteplugins-helper.ts @@ -84,6 +84,7 @@ import { CoreSitePluginsWorkshopAssessmentStrategyHandler } from '../classes/han import { CoreContentLinksModuleIndexHandler } from '@features/contentlinks/classes/module-index-handler'; import { CoreContentLinksDelegate } from '@features/contentlinks/services/contentlinks-delegate'; import { CoreContentLinksModuleListHandler } from '@features/contentlinks/classes/module-list-handler'; +import { CoreObject } from '@singletons/object'; const HANDLER_DISABLED = 'core_site_plugins_helper_handler_disabled'; @@ -615,9 +616,11 @@ export class CoreSitePluginsHelperProvider { if (result.jsResult) { // Override default handler functions with the result of the method JS. const jsResult = > result.jsResult; - for (const property in handler) { - if (property != 'constructor' && typeof handler[property] == 'function' && - typeof jsResult[property] == 'function') { + const handlerProperties = CoreObject.getAllPropertyNames(handler); + + for (const property of handlerProperties) { + if (property !== 'constructor' && typeof handler[property] === 'function' && + typeof jsResult[property] === 'function') { // eslint-disable-next-line @typescript-eslint/ban-types handler[property] = ( jsResult[property]).bind(handler); } diff --git a/src/core/singletons/object.ts b/src/core/singletons/object.ts index b0dd856c3..9bc8fe760 100644 --- a/src/core/singletons/object.ts +++ b/src/core/singletons/object.ts @@ -36,6 +36,25 @@ export class CoreObject { return JSON.stringify(a) === JSON.stringify(b); } + /** + * Get all the properties names of an object, including the inherited ones except the ones from Object.prototype. + * + * @param object Object to get its properties. + * @return Set of property names. + */ + static getAllPropertyNames(object: unknown): Set { + if (typeof object !== 'object' || object === null || object === Object.prototype) { + // Not an object or we already reached root level. + return new Set([]); + } + + const properties = CoreObject.getAllPropertyNames(Object.getPrototypeOf(object)); + + Object.getOwnPropertyNames(object).forEach(property => properties.add(property)); + + return properties; + } + /** * Check whether the given object is empty. *