* Wraps a method with a debugger or logger statement. * * @param {object} object * @param {string} methodName * @param {boolean} isLog * @private
(object, methodName, isLog)
| 176 | */ |
| 177 | |
| 178 | function wrapMethod(object, methodName, isLog) { |
| 179 | assert( |
| 180 | typeof object === 'object' && |
| 181 | object && typeof object[methodName] === 'function', |
| 182 | 'Illegal object or failed to find method.' |
| 183 | ); |
| 184 | |
| 185 | var method = object[methodName]; |
| 186 | |
| 187 | wrappedMethods.push({ |
| 188 | object: object, |
| 189 | method: method |
| 190 | }); |
| 191 | |
| 192 | var slice = [].slice; |
| 193 | var replacement; |
| 194 | |
| 195 | if (isLog) { |
| 196 | replacement = function() { |
| 197 | console.log(arguments); |
| 198 | return method.apply(this, slice.call(arguments)); |
| 199 | }; |
| 200 | } else { |
| 201 | replacement = function() { |
| 202 | debugger; |
| 203 | return method.apply(this, slice.call(arguments)); |
| 204 | }; |
| 205 | } |
| 206 | |
| 207 | object[methodName] = replacement; |
| 208 | } |
| 209 | |
| 210 | /** |
| 211 | * Wraps a method with a debugger statement. |