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

Function getHostDefinedOptionId

lib/internal/vm.js:60–89  ·  view source on GitHub ↗

* Retrieves the host-defined option ID based on the provided importModuleDynamically and hint. * @param {VmImportModuleDynamicallyCallback | undefined} importModuleDynamically - * The importModuleDynamically function or undefined. * @param {string} hint - The hint for the option ID. * @returns

(importModuleDynamically, hint)

Source from the content-addressed store, hash-verified

58 * ID.
59 */
60function getHostDefinedOptionId(importModuleDynamically, hint) {
61 if (importModuleDynamically === vm_dynamic_import_main_context_default ||
62 importModuleDynamically === vm_dynamic_import_default_internal) {
63 return importModuleDynamically;
64 }
65
66 if (importModuleDynamically !== undefined) {
67 // Check that it's either undefined or a function before we pass
68 // it into the native constructor.
69 validateFunction(importModuleDynamically,
70 'options.importModuleDynamically');
71 }
72 if (importModuleDynamically === undefined) {
73 // We need a default host defined options that are the same for all
74 // scripts not needing custom module callbacks so that the isolate
75 // compilation cache can be hit.
76 return vm_dynamic_import_no_callback;
77 }
78 // We should've thrown here immediately when we introduced
79 // --experimental-vm-modules and importModuleDynamically, but since
80 // users are already using this callback to throw a similar error,
81 // we also defer the error to the time when an actual import() is called
82 // to avoid breaking them. To ensure that the isolate compilation
83 // cache can still be hit, use a constant sentinel symbol here.
84 if (!getOptionValue('--experimental-vm-modules')) {
85 return vm_dynamic_import_missing_flag;
86 }
87
88 return Symbol(hint);
89}
90
91/**
92 * Registers a dynamically imported module for customization.

Callers 3

constructorMethod · 0.85
createContextFunction · 0.85
compileFunctionFunction · 0.85

Calls 2

getOptionValueFunction · 0.85
SymbolFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…