MCPcopy Index your code
hub / github.com/nodejs/node / [kLink]

Method [kLink]

lib/internal/vm/module.js:335–377  ·  view source on GitHub ↗
(linker)

Source from the content-addressed store, hash-verified

333 }
334
335 async [kLink](linker) {
336 this.#statusOverride = 'linking';
337
338 // Iterates the module requests and links with the linker.
339 // Modules should be aligned with the moduleRequests array in order.
340 const modulePromises = Array(this.#moduleRequests.length);
341 // Iterates with index to avoid calling into userspace with `Symbol.iterator`.
342 for (let idx = 0; idx < this.#moduleRequests.length; idx++) {
343 const { specifier, attributes } = this.#moduleRequests[idx];
344
345 const linkerResult = linker(specifier, this, {
346 attributes,
347 assert: attributes,
348 });
349 const modulePromise = PromisePrototypeThen(
350 PromiseResolve(linkerResult), async (module) => {
351 if (!isModule(module)) {
352 throw new ERR_VM_MODULE_NOT_MODULE();
353 }
354 if (module.context !== this.context) {
355 throw new ERR_VM_MODULE_DIFFERENT_CONTEXT();
356 }
357 if (module.status === 'errored') {
358 throw new ERR_VM_MODULE_LINK_FAILURE(`request for '${specifier}' resolved to an errored module`, module.error);
359 }
360 if (module.status === 'unlinked') {
361 await module[kLink](linker);
362 }
363 return module[kWrap];
364 });
365 modulePromises[idx] = modulePromise;
366 }
367
368 try {
369 const modules = await SafePromiseAllReturnArrayLike(modulePromises);
370 this[kWrap].link(modules);
371 } catch (e) {
372 this.#error = e;
373 throw e;
374 } finally {
375 this.#statusOverride = undefined;
376 }
377 }
378
379 linkRequests(modules) {
380 validateThisInternalField(this, kWrap, 'SourceTextModule');

Callers

nothing calls this directly

Calls 3

ArrayFunction · 0.85
isModuleFunction · 0.85
linkMethod · 0.45

Tested by

no test coverage detected