|
8 | 8 | getConstructorOf,
|
9 | 9 | customInspectSymbol,
|
10 | 10 | } = require('internal/util');
|
| 11 | +const { SafePromise } = require('internal/safe_globals'); |
11 | 12 |
|
12 | 13 | const {
|
13 | 14 | ModuleWrap,
|
@@ -131,27 +132,26 @@ class Module {
|
131 | 132 | const wrap = wrapMap.get(this);
|
132 | 133 | if (wrap.getStatus() !== kUninstantiated)
|
133 | 134 | throw new errors.Error('ERR_VM_MODULE_STATUS', 'must be uninstantiated');
|
| 135 | + |
134 | 136 | linkingStatusMap.set(this, 'linking');
|
135 |
| - const promises = []; |
136 |
| - wrap.link((specifier) => { |
137 |
| - const p = (async () => { |
138 |
| - const m = await linker(specifier, this); |
139 |
| - if (!m || !wrapMap.has(m)) |
140 |
| - throw new errors.Error('ERR_VM_MODULE_NOT_MODULE'); |
141 |
| - if (m.context !== this.context) |
142 |
| - throw new errors.Error('ERR_VM_MODULE_DIFFERENT_CONTEXT'); |
143 |
| - const childLinkingStatus = linkingStatusMap.get(m); |
144 |
| - if (childLinkingStatus === 'errored') |
145 |
| - throw new errors.Error('ERR_VM_MODULE_LINKING_ERRORED'); |
146 |
| - if (childLinkingStatus === 'unlinked') |
147 |
| - await m.link(linker); |
148 |
| - return wrapMap.get(m); |
149 |
| - })(); |
150 |
| - promises.push(p); |
151 |
| - return p; |
| 137 | + |
| 138 | + const promises = wrap.link(async (specifier) => { |
| 139 | + const m = await linker(specifier, this); |
| 140 | + if (!m || !wrapMap.has(m)) |
| 141 | + throw new errors.Error('ERR_VM_MODULE_NOT_MODULE'); |
| 142 | + if (m.context !== this.context) |
| 143 | + throw new errors.Error('ERR_VM_MODULE_DIFFERENT_CONTEXT'); |
| 144 | + const childLinkingStatus = linkingStatusMap.get(m); |
| 145 | + if (childLinkingStatus === 'errored') |
| 146 | + throw new errors.Error('ERR_VM_MODULE_LINKING_ERRORED'); |
| 147 | + if (childLinkingStatus === 'unlinked') |
| 148 | + await m.link(linker); |
| 149 | + return wrapMap.get(m); |
152 | 150 | });
|
| 151 | + |
153 | 152 | try {
|
154 |
| - await Promise.all(promises); |
| 153 | + if (promises !== undefined) |
| 154 | + await SafePromise.all(promises); |
155 | 155 | linkingStatusMap.set(this, 'linked');
|
156 | 156 | } catch (err) {
|
157 | 157 | linkingStatusMap.set(this, 'errored');
|
|
0 commit comments