| 88 | } |
| 89 | |
| 90 | addLogToFunctions(prototype: any) { |
| 91 | if (!DEBUG) return; |
| 92 | for (const key of Object.getOwnPropertyNames(prototype)) { |
| 93 | if (key === 'constructor') continue; |
| 94 | const descriptor = Object.getOwnPropertyDescriptor(prototype, key); |
| 95 | if (descriptor) { |
| 96 | const value = descriptor.value; |
| 97 | if (typeof value === 'function') { |
| 98 | prototype[key] = function (...args: any[]) { |
| 99 | // Before |
| 100 | Debug.log( |
| 101 | `${prototype.constructor.name}.${key} (${Array.from( |
| 102 | args |
| 103 | ) |
| 104 | .map((param) => { |
| 105 | try { |
| 106 | return param.toString(); |
| 107 | } catch (_e) { |
| 108 | return ''; |
| 109 | } |
| 110 | }) |
| 111 | .join(',')})` |
| 112 | ); |
| 113 | indent++; |
| 114 | try { |
| 115 | const result = value.apply(this, args); // use .apply() to call it |
| 116 | // After |
| 117 | return result; |
| 118 | } finally { |
| 119 | indent--; |
| 120 | } |
| 121 | }; |
| 122 | } |
| 123 | } |
| 124 | } |
| 125 | } |
| 126 | } |