(parent)
| 388 | } |
| 389 | |
| 390 | runSync(parent) { |
| 391 | assert(this.shouldRunModule(this.phase)); |
| 392 | assert(this.module instanceof ModuleWrap); |
| 393 | let status = this.module.getStatus(); |
| 394 | |
| 395 | debug('ModuleJob.runSync()', status, this.module); |
| 396 | if (status === kUninstantiated) { |
| 397 | // FIXME(joyeecheung): this cannot fully handle < kInstantiated. Make the linking |
| 398 | // fully synchronous instead. |
| 399 | if (this.module.getModuleRequests().length === 0) { |
| 400 | this.module.link([]); |
| 401 | } |
| 402 | this.module.instantiate(); |
| 403 | status = this.module.getStatus(); |
| 404 | } |
| 405 | if (status === kInstantiated || status === kErrored) { |
| 406 | const filename = urlToFilename(this.url); |
| 407 | const parentFilename = urlToFilename(parent?.filename); |
| 408 | if (this.module.hasAsyncGraph && !getOptionValue('--experimental-print-required-tla')) { |
| 409 | throw new ERR_REQUIRE_ASYNC_MODULE(filename, parentFilename); |
| 410 | } |
| 411 | if (status === kInstantiated) { |
| 412 | setHasStartedUserESMExecution(); |
| 413 | const namespace = this.module.evaluateSync(filename, parentFilename); |
| 414 | return { __proto__: null, module: this.module, namespace }; |
| 415 | } |
| 416 | throw this.module.getError(); |
| 417 | } else if (status === kEvaluating || status === kEvaluated) { |
| 418 | if (this.module.hasAsyncGraph) { |
| 419 | const filename = urlToFilename(this.url); |
| 420 | const parentFilename = urlToFilename(parent?.filename); |
| 421 | throw new ERR_REQUIRE_ASYNC_MODULE(filename, parentFilename); |
| 422 | } |
| 423 | // kEvaluating can show up when this is being used to deal with CJS <-> CJS cycles. |
| 424 | // Allow it for now, since we only need to ban ESM <-> CJS cycles which would be |
| 425 | // detected earlier during the linking phase, though the CJS handling in the ESM |
| 426 | // loader won't be able to emit warnings on pending circular exports like what |
| 427 | // the CJS loader does. |
| 428 | // TODO(joyeecheung): remove the re-invented require() in the ESM loader and |
| 429 | // always handle CJS using the CJS loader to eliminate the quirks. |
| 430 | return { __proto__: null, module: this.module, namespace: this.module.getNamespace() }; |
| 431 | } |
| 432 | assert(status === kUninstantiated, `Unexpected module status ${status}.`); |
| 433 | throw new ERR_REQUIRE_ESM_RACE_CONDITION(); |
| 434 | } |
| 435 | |
| 436 | async run(isEntryPoint = false) { |
| 437 | debug('ModuleJob.run()', this.module); |
no test coverage detected