@@ -21,7 +21,7 @@ let debug = require('internal/util/debuglog').debuglog('esm', (fn) => {
|
21 | 21 | debug = fn; |
22 | 22 | }); |
23 | 23 | |
24 | | -const { ModuleWrap, kEvaluated } = internalBinding('module_wrap'); |
| 24 | +const { ModuleWrap, kInstantiated } = internalBinding('module_wrap'); |
25 | 25 | |
26 | 26 | const { decorateErrorStack, kEmptyObject } = require('internal/util'); |
27 | 27 | const { |
@@ -346,10 +346,26 @@ class ModuleJobSync extends ModuleJobBase {
|
346 | 346 | } |
347 | 347 | |
348 | 348 | async run() { |
| 349 | +// This path is hit by a require'd module that is imported again. |
349 | 350 | const status = this.module.getStatus(); |
350 | | -assert(status === kEvaluated, |
351 | | -`A require()-d module that is imported again must be evaluated. Status = ${status}`); |
352 | | -return { __proto__: null, module: this.module }; |
| 351 | +if (status > kInstantiated) { |
| 352 | +if (this.evaluationPromise) { |
| 353 | +await this.evaluationPromise; |
| 354 | +} |
| 355 | +return { __proto__: null, module: this.module }; |
| 356 | +} else if (status === kInstantiated) { |
| 357 | +// The evaluation may have been canceled because instantiateSync() detected TLA first. |
| 358 | +// But when it is imported again, it's fine to re-evaluate it asynchronously. |
| 359 | +const timeout = -1; |
| 360 | +const breakOnSigint = false; |
| 361 | +this.evaluationPromise = this.module.evaluate(timeout, breakOnSigint); |
| 362 | +await this.evaluationPromise; |
| 363 | +this.evaluationPromise = undefined; |
| 364 | +return { __proto__: null, module: this.module }; |
| 365 | +} |
| 366 | + |
| 367 | +assert.fail('Unexpected status of a module that is imported again after being required. ' + |
| 368 | +`Status = ${status}`); |
353 | 369 | } |
354 | 370 | |
355 | 371 | runSync() { |
|