ack; } // We should've thrown here immediately when we introduced // --experimental-vm-modules and importModuleDynamically, but since // users are already using this callback to throw a similar error, // we also defer the error to the time when an actual import() is called // to avoid breaking them. To ensure that the isolate compilation // cache can still be hit, use a constant sentinel symbol here. if (!getOptionValue('--experimental-vm-modules')) { return vm_dynamic_import_missing_flag; } return Symbol(hint); } /** * Registers a dynamically imported module for customization. * @param {string} referrer - The path of the referrer module. * @param {import('internal/modules/esm/utils').ImportModuleDynamicallyCallback} importModuleDynamically - The * dynamically imported module function to be registered. */ function registerImportModuleDynamically(referrer, importModuleDynamically) { // If it's undefined or certain known symbol, there's no customization so // no need to register anything. if (importModuleDynamically === undefined || importModuleDynamically === vm_dynamic_import_main_context_default || importModuleDynamically === vm_dynamic_import_default_internal) { return; } const { importModuleDynamicallyWrap } = require('internal/vm/module'); const { registerModule } = require('internal/modules/esm/utils'); registerModule(referrer, { __proto__: null, importModuleDynamically: importModuleDynamicallyWrap(importModuleDynamically), }); } /** * Compiles a function from the given code string. * @param {string} code - The code string to compile. * @param {string} filename - The filename to use for the compiled function. * @param {number} lineOffset - The line offset to use for the compiled function. * @param {number} columnOffset - The column offset to use for the compiled function. * @param {Buffer} [cachedData=undefined] - The cached data to use for the compiled function. * @param {boolean} produceCachedData - Whether to produce cached data for the compiled function. * @param {ReturnType} script - The script to run. * @param {boolean} displayErrors - Whether to display errors. * @param {boolean} breakOnFirstLine - Whether to break on the first line. */ function runScriptInThisContext(script, displayErrors, breakOnFirstLine) { return ReflectApply( runInContext, script, [ null, // sandbox - use current context -1, // timeout displayErrors, // displayErrors false, // breakOnSigint breakOnFirstLine, // breakOnFirstLine ], ); } module.exports = { getHostDefinedOptionId, internalCompileFunction, isContext, makeContextifyScript, registerImportModuleDynamically, runScriptInThisContext, };