| 206 | // If something went wrong, onLoad() may run without the response callback |
| 207 | // having been invoked. |
| 208 | const onLoad = () => { |
| 209 | // We wrap it in an extra Promise, to ensure the microtask |
| 210 | // is scheduled after the loaded endpoint has executed any potential microtask itself, |
| 211 | // which is not guaranteed in Internet Explorer and EdgeHTML. See issue #39496 |
| 212 | this.resolvedPromise.then(() => { |
| 213 | // Cleanup the page. |
| 214 | cleanup(); |
| 215 | |
| 216 | // Check whether the response callback has run. |
| 217 | if (!finished) { |
| 218 | // It hasn't, something went wrong with the request. Return an error via |
| 219 | // the Observable error path. All JSONP errors have status 0. |
| 220 | observer.error( |
| 221 | new HttpErrorResponse({ |
| 222 | url, |
| 223 | status: 0, |
| 224 | statusText: 'JSONP Error', |
| 225 | error: new Error(JSONP_ERR_NO_CALLBACK), |
| 226 | }), |
| 227 | ); |
| 228 | return; |
| 229 | } |
| 230 | |
| 231 | // Success. body either contains the response body or null if none was |
| 232 | // returned. |
| 233 | observer.next( |
| 234 | new HttpResponse({ |
| 235 | body, |
| 236 | status: HTTP_STATUS_CODE_OK, |
| 237 | statusText: 'OK', |
| 238 | url, |
| 239 | }), |
| 240 | ); |
| 241 | |
| 242 | // Complete the stream, the response is over. |
| 243 | observer.complete(); |
| 244 | }); |
| 245 | }; |
| 246 | |
| 247 | // onError() is the error callback, which runs if the script returned generates |
| 248 | // a Javascript error. It emits the error via the Observable error channel as |