MCPcopy Index your code
hub / github.com/nodejs/node / importModuleDynamicallyCallback

Function importModuleDynamicallyCallback

lib/internal/modules/esm/utils.js:263–295  ·  view source on GitHub ↗

* Asynchronously imports a module dynamically using a callback function. The native callback. * @param {symbol} referrerSymbol - Referrer symbol of the registered script, function, module, or contextified object. * @param {string} specifier - The module specifier string. * @param {number} phase -

(referrerSymbol, specifier, phase, attributes,
                                               referrerName)

Source from the content-addressed store, hash-verified

261 * @throws {ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING} - If the callback function is missing.
262 */
263async function importModuleDynamicallyCallback(referrerSymbol, specifier, phase, attributes,
264 referrerName) {
265 // For user-provided vm.constants.USE_MAIN_CONTEXT_DEFAULT_LOADER, emit the warning
266 // and fall back to the default loader.
267 if (referrerSymbol === vm_dynamic_import_main_context_default) {
268 emitExperimentalWarning('vm.USE_MAIN_CONTEXT_DEFAULT_LOADER');
269 return defaultImportModuleDynamicallyForScript(specifier, phase, attributes, referrerName);
270 }
271 // For script compiled internally that should use the default loader to handle dynamic
272 // import, proxy the request to the default loader without the warning.
273 if (referrerSymbol === vm_dynamic_import_default_internal) {
274 return defaultImportModuleDynamicallyForScript(specifier, phase, attributes, referrerName);
275 }
276 // For SourceTextModules compiled internally, proxy the request to the default loader.
277 if (referrerSymbol === source_text_module_default_hdo) {
278 return defaultImportModuleDynamicallyForModule(specifier, phase, attributes, referrerName);
279 }
280 // For embedder entry point ESM, only allow built-in modules.
281 if (referrerSymbol === embedder_module_hdo) {
282 return importModuleDynamicallyForEmbedder(specifier, phase, attributes, referrerName);
283 }
284
285 if (moduleRegistries.has(referrerSymbol)) {
286 const { importModuleDynamically, callbackReferrer } = moduleRegistries.get(referrerSymbol);
287 if (importModuleDynamically !== undefined) {
288 return importModuleDynamically(specifier, callbackReferrer, attributes, phase);
289 }
290 }
291 if (referrerSymbol === vm_dynamic_import_missing_flag) {
292 throw new ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING_FLAG();
293 }
294 throw new ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING();
295}
296
297let _shouldSpawnLoaderHookWorker = true;
298/**

Callers

nothing calls this directly

Calls 7

emitExperimentalWarningFunction · 0.85
hasMethod · 0.65
getMethod · 0.65
importModuleDynamicallyFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…