MOBILE-3953 siteplugins: Fix override handler properties
This commit is contained in:
		
							parent
							
								
									11d219ddce
								
							
						
					
					
						commit
						db67faaa50
					
				| @ -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 = <Record<string, unknown>> 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] = (<Function> jsResult[property]).bind(handler); | ||||
|                     } | ||||
|  | ||||
| @ -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<string> { | ||||
|         if (typeof object !== 'object' || object === null || object === Object.prototype) { | ||||
|             // Not an object or we already reached root level.
 | ||||
|             return new Set<string>([]); | ||||
|         } | ||||
| 
 | ||||
|         const properties = CoreObject.getAllPropertyNames(Object.getPrototypeOf(object)); | ||||
| 
 | ||||
|         Object.getOwnPropertyNames(object).forEach(property => properties.add(property)); | ||||
| 
 | ||||
|         return properties; | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Check whether the given object is empty. | ||||
|      * | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user