module: fix cyclical dynamic import

ensures that instantiation result is only used during initial loading

PR-URL: https://github.com/nodejs/node/pull/18965
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Guy Bedford <guybedford@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Reviewed-By: Jan Krems <jan.krems@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
This commit is contained in:
Bradley Farias 2018-02-23 14:21:49 -06:00
parent ae3137049f
commit 023f49c5a9
2 changed files with 7 additions and 3 deletions

View File

@ -50,10 +50,11 @@ class ModuleJob {
}
async instantiate() {
if (this.instantiated) {
return this.instantiated;
if (!this.instantiated) {
return this.instantiated = this._instantiate();
}
return this.instantiated = this._instantiate();
await this.instantiated;
return this.module;
}
// This method instantiates the module associated with this job and its

View File

@ -0,0 +1,3 @@
// Flags: --experimental-modules
import '../common';
import('./test-esm-cyclic-dynamic-import');