(loader, load, seen)
| 247 | // returns a promise if and only if a top-level await subgraph |
| 248 | // throws on sync errors |
| 249 | function postOrderExec (loader, load, seen) { |
| 250 | if (seen[load.id]) |
| 251 | return; |
| 252 | seen[load.id] = true; |
| 253 | |
| 254 | if (!load.e) { |
| 255 | if (load.er) |
| 256 | throw load.er; |
| 257 | if (load.E) |
| 258 | return load.E; |
| 259 | return; |
| 260 | } |
| 261 | |
| 262 | // From here we're about to execute the load. |
| 263 | // Because the execution may be async, we pop the `load.e` first. |
| 264 | // So `load.e === null` always means the load has been executed or is executing. |
| 265 | // To inspect the state: |
| 266 | // - If `load.er` is truthy, the execution has threw or has been rejected; |
| 267 | // - otherwise, either the `load.E` is a promise, means it's under async execution, or |
| 268 | // - the `load.E` is null, means the load has completed the execution or has been async resolved. |
| 269 | var exec = load.e; |
| 270 | load.e = null; |
| 271 | |
| 272 | // deps execute first, unless circular |
| 273 | var depLoadPromises; |
| 274 | load.d.forEach(function (depLoad) { |
| 275 | try { |
| 276 | var depLoadPromise = postOrderExec(loader, depLoad, seen); |
| 277 | if (depLoadPromise) |
| 278 | (depLoadPromises = depLoadPromises || []).push(depLoadPromise); |
| 279 | } |
| 280 | catch (err) { |
| 281 | load.er = err; |
| 282 | if (!process.env.SYSTEM_PRODUCTION) triggerOnload(loader, load, err, false); |
| 283 | throw err; |
| 284 | } |
| 285 | }); |
| 286 | if (depLoadPromises) |
| 287 | return Promise.all(depLoadPromises).then(doExec); |
| 288 | |
| 289 | return doExec(); |
| 290 | |
| 291 | function doExec () { |
| 292 | try { |
| 293 | var execPromise = exec.call(nullContext); |
| 294 | if (execPromise) { |
| 295 | execPromise = execPromise.then(function () { |
| 296 | load.C = load.n; |
| 297 | load.E = null; // indicates completion |
| 298 | if (!process.env.SYSTEM_PRODUCTION) triggerOnload(loader, load, null, true); |
| 299 | }, function (err) { |
| 300 | load.er = err; |
| 301 | load.E = null; |
| 302 | if (!process.env.SYSTEM_PRODUCTION) triggerOnload(loader, load, err, true); |
| 303 | throw err; |
| 304 | }); |
| 305 | return load.E = execPromise; |
| 306 | } |
no test coverage detected
searching dependent graphs…