(tapIndex, { onError, onResult, onDone, rethrowIfPossible })
| 184 | } |
| 185 | |
| 186 | callTap(tapIndex, { onError, onResult, onDone, rethrowIfPossible }) { |
| 187 | let code = ""; |
| 188 | let hasTapCached = false; |
| 189 | for (let i = 0; i < this.options.interceptors.length; i++) { |
| 190 | const interceptor = this.options.interceptors[i]; |
| 191 | if (interceptor.tap) { |
| 192 | if (!hasTapCached) { |
| 193 | code += `var _tap${tapIndex} = ${this.getTap(tapIndex)};\n`; |
| 194 | hasTapCached = true; |
| 195 | } |
| 196 | code += `${this.getInterceptor(i)}.tap(${ |
| 197 | interceptor.context ? "_context, " : "" |
| 198 | }_tap${tapIndex});\n`; |
| 199 | } |
| 200 | } |
| 201 | code += `var _fn${tapIndex} = ${this.getTapFn(tapIndex)};\n`; |
| 202 | const tap = this.options.taps[tapIndex]; |
| 203 | switch (tap.type) { |
| 204 | case "sync": |
| 205 | if (!rethrowIfPossible) { |
| 206 | code += `var _hasError${tapIndex} = false;\n`; |
| 207 | code += "try {\n"; |
| 208 | } |
| 209 | if (onResult) { |
| 210 | code += `var _result${tapIndex} = _fn${tapIndex}(${this.args({ |
| 211 | before: tap.context ? "_context" : undefined |
| 212 | })});\n`; |
| 213 | } else { |
| 214 | code += `_fn${tapIndex}(${this.args({ |
| 215 | before: tap.context ? "_context" : undefined |
| 216 | })});\n`; |
| 217 | } |
| 218 | if (!rethrowIfPossible) { |
| 219 | code += "} catch(_err) {\n"; |
| 220 | code += `_hasError${tapIndex} = true;\n`; |
| 221 | code += onError("_err"); |
| 222 | code += "}\n"; |
| 223 | code += `if(!_hasError${tapIndex}) {\n`; |
| 224 | } |
| 225 | if (onResult) { |
| 226 | code += onResult(`_result${tapIndex}`); |
| 227 | } |
| 228 | if (onDone) { |
| 229 | code += onDone(); |
| 230 | } |
| 231 | if (!rethrowIfPossible) { |
| 232 | code += "}\n"; |
| 233 | } |
| 234 | break; |
| 235 | case "async": { |
| 236 | let cbCode = ""; |
| 237 | cbCode += onResult |
| 238 | ? `(function(_err${tapIndex}, _result${tapIndex}) {\n` |
| 239 | : `(function(_err${tapIndex}) {\n`; |
| 240 | cbCode += `if(_err${tapIndex}) {\n`; |
| 241 | cbCode += onError(`_err${tapIndex}`); |
| 242 | cbCode += "} else {\n"; |
| 243 | if (onResult) { |
no test coverage detected