@@ -31,10 +31,23 @@ const {
3131 } ,
3232} = internalBinding ( 'util' ) ;
3333
34+ /**
35+ * Checks if the given object is a context object.
36+ * @param {object } object - The object to check.
37+ * @returns {boolean } - Returns true if the object is a context object, else false.
38+ */
3439function isContext ( object ) {
3540 return object [ contextify_context_private_symbol ] !== undefined ;
3641}
3742
43+ /**
44+ * Retrieves the host-defined option ID based on the provided importModuleDynamically and hint.
45+ * @param {import('internal/modules/esm/utils').ImportModuleDynamicallyCallback | undefined } importModuleDynamically -
46+ * The importModuleDynamically function or undefined.
47+ * @param {string } hint - The hint for the option ID.
48+ * @returns {symbol | import('internal/modules/esm/utils').ImportModuleDynamicallyCallback } - The host-defined option
49+ * ID.
50+ */
3851function getHostDefinedOptionId ( importModuleDynamically , hint ) {
3952 if ( importModuleDynamically === vm_dynamic_import_main_context_default ||
4053 importModuleDynamically === vm_dynamic_import_default_internal ) {
@@ -66,6 +79,12 @@ function getHostDefinedOptionId(importModuleDynamically, hint) {
6679 return Symbol ( hint ) ;
6780}
6881
82+ /**
83+ * Registers a dynamically imported module for customization.
84+ * @param {string } referrer - The path of the referrer module.
85+ * @param {import('internal/modules/esm/utils').ImportModuleDynamicallyCallback } importModuleDynamically - The
86+ * dynamically imported module function to be registered.
87+ */
6988function registerImportModuleDynamically ( referrer , importModuleDynamically ) {
7089 // If it's undefined or certain known symbol, there's no customization so
7190 // no need to register anything.
@@ -83,6 +102,25 @@ function registerImportModuleDynamically(referrer, importModuleDynamically) {
83102 } ) ;
84103}
85104
105+ /**
106+ * Compiles a function from the given code string.
107+ * @param {string } code - The code string to compile.
108+ * @param {string } filename - The filename to use for the compiled function.
109+ * @param {number } lineOffset - The line offset to use for the compiled function.
110+ * @param {number } columnOffset - The column offset to use for the compiled function.
111+ * @param {Buffer } [cachedData=undefined] - The cached data to use for the compiled function.
112+ * @param {boolean } produceCachedData - Whether to produce cached data for the compiled function.
113+ * @param {ReturnType<import('vm').createContext } [parsingContext=undefined] - The parsing context to use for the
114+ * compiled function.
115+ * @param {object[] } [contextExtensions=[]] - An array of context extensions to use for the compiled function.
116+ * @param {string[] } [params] - An optional array of parameter names for the compiled function.
117+ * @param {symbol } hostDefinedOptionId - A symbol referenced by the field `host_defined_option_symbol`.
118+ * @param {import('internal/modules/esm/utils').ImportModuleDynamicallyCallback } [importModuleDynamically] -
119+ * A function to use for dynamically importing modules.
120+ * @returns {object } An object containing the compiled function and any associated data.
121+ * @throws {TypeError } If any of the arguments are of the wrong type.
122+ * @throws {ERR_INVALID_ARG_TYPE } If the parsing context is not a valid context object.
123+ */
86124function internalCompileFunction (
87125 code , filename , lineOffset , columnOffset ,
88126 cachedData , produceCachedData , parsingContext , contextExtensions ,
@@ -117,6 +155,19 @@ function internalCompileFunction(
117155 return result ;
118156}
119157
158+ /**
159+ * Creates a contextify script.
160+ * @param {string } code - The code of the script.
161+ * @param {string } filename - The filename of the script.
162+ * @param {number } lineOffset - The line offset of the script.
163+ * @param {number } columnOffset - The column offset of the script.
164+ * @param {Buffer } cachedData - The cached data of the script.
165+ * @param {boolean } produceCachedData - Indicates whether to produce cached data.
166+ * @param {object } parsingContext - The parsing context of the script.
167+ * @param {number } hostDefinedOptionId - The host-defined option ID.
168+ * @param {boolean } importModuleDynamically - Indicates whether to import modules dynamically.
169+ * @returns {ContextifyScript } The created contextify script.
170+ */
120171function makeContextifyScript ( code ,
121172 filename ,
122173 lineOffset ,
@@ -147,8 +198,13 @@ function makeContextifyScript(code,
147198 return script ;
148199}
149200
150- // Internal version of vm.Script.prototype.runInThisContext() which skips
151- // argument validation.
201+ /**
202+ * Runs a script in the current context.
203+ * Internal version of `vm.Script.prototype.runInThisContext()` which skips argument validation.
204+ * @param {ReturnType<makeContextifyScript> } script - The script to run.
205+ * @param {boolean } displayErrors - Whether to display errors.
206+ * @param {boolean } breakOnFirstLine - Whether to break on the first line.
207+ */
152208function runScriptInThisContext ( script , displayErrors , breakOnFirstLine ) {
153209 return ReflectApply (
154210 runInContext ,
0 commit comments