@@ -29,12 +29,23 @@ const {
29
29
getOptionValue,
30
30
} = require ( 'internal/options' ) ;
31
31
32
+ /**
33
+ * Checks if the given object is a context object.
34
+ * @param {object } object - The object to check.
35
+ * @returns {boolean } - Returns true if the object is a context object, else false.
36
+ */
32
37
function isContext ( object ) {
33
38
validateObject ( object , 'object' , kValidateObjectAllowArray ) ;
34
39
35
40
return _isContext ( object ) ;
36
41
}
37
42
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 - The importModuleDynamically function or undefined.
46
+ * @param {string } hint - The hint for the option ID.
47
+ * @returns {symbol | import('internal/modules/esm/utils').ImportModuleDynamicallyCallback } - The host-defined option ID.
48
+ */
38
49
function getHostDefinedOptionId ( importModuleDynamically , hint ) {
39
50
if ( importModuleDynamically === vm_dynamic_import_main_context_default ||
40
51
importModuleDynamically === vm_dynamic_import_default_internal ) {
@@ -66,6 +77,11 @@ function getHostDefinedOptionId(importModuleDynamically, hint) {
66
77
return Symbol ( hint ) ;
67
78
}
68
79
80
+ /**
81
+ * Registers a dynamically imported module for customization.
82
+ * @param {string } referrer - The path of the referrer module.
83
+ * @param {import('internal/modules/esm/utils').ImportModuleDynamicallyCallback } importModuleDynamically - The dynamically imported module function to be registered.
84
+ */
69
85
function registerImportModuleDynamically ( referrer , importModuleDynamically ) {
70
86
// If it's undefined or certain known symbol, there's no customization so
71
87
// no need to register anything.
@@ -83,6 +99,24 @@ function registerImportModuleDynamically(referrer, importModuleDynamically) {
83
99
} ) ;
84
100
}
85
101
102
+ /**
103
+ * Compiles a function from the given code string.
104
+ * @param {string } code - The code string to compile.
105
+ * @param {string } filename - The filename to use for the compiled function.
106
+ * @param {number } lineOffset - The line offset to use for the compiled function.
107
+ * @param {number } columnOffset - The column offset to use for the compiled function.
108
+ * @param {Buffer } cachedData - The cached data to use for the compiled function.
109
+ * @param {boolean } produceCachedData - Whether to produce cached data for the compiled function.
110
+ * @param {ReturnType<import('vm').createContext } parsingContext - The parsing context to use for the compiled function.
111
+ * @param {object[] } contextExtensions - An array of context extensions to use for the compiled function.
112
+ * @param {string[] } params - An optional array of parameter names for the compiled function.
113
+ * @param {object } hostDefinedOptionId - The host defined option id to use for the compiled function.
114
+ * @param {import('internal/modules/esm/utils').ImportModuleDynamicallyCallback } importModuleDynamically -
115
+ * A function to use for dynamically importing modules.
116
+ * @returns {object } An object containing the compiled function and any associated data.
117
+ * @throws {TypeError } If any of the arguments are of the wrong type.
118
+ * @throws {ERR_INVALID_ARG_TYPE } If the parsing context is not a valid context object.
119
+ */
86
120
function internalCompileFunction (
87
121
code , filename , lineOffset , columnOffset ,
88
122
cachedData , produceCachedData , parsingContext , contextExtensions ,
@@ -117,6 +151,19 @@ function internalCompileFunction(
117
151
return result ;
118
152
}
119
153
154
+ /**
155
+ * Creates a contextify script.
156
+ * @param {string } code - The code of the script.
157
+ * @param {string } filename - The filename of the script.
158
+ * @param {number } lineOffset - The line offset of the script.
159
+ * @param {number } columnOffset - The column offset of the script.
160
+ * @param {Buffer } cachedData - The cached data of the script.
161
+ * @param {boolean } produceCachedData - Indicates whether to produce cached data.
162
+ * @param {object } parsingContext - The parsing context of the script.
163
+ * @param {number } hostDefinedOptionId - The host-defined option ID.
164
+ * @param {boolean } importModuleDynamically - Indicates whether to import modules dynamically.
165
+ * @returns {ContextifyScript } The created contextify script.
166
+ */
120
167
function makeContextifyScript ( code ,
121
168
filename ,
122
169
lineOffset ,
@@ -147,8 +194,13 @@ function makeContextifyScript(code,
147
194
return script ;
148
195
}
149
196
150
- // Internal version of vm.Script.prototype.runInThisContext() which skips
151
- // argument validation.
197
+ /**
198
+ * Runs a script in the current context.
199
+ * Internal version of `vm.Script.prototype.runInThisContext()` which skips argument validation.
200
+ * @param {ReturnType<makeContextifyScript> } script - The script to run.
201
+ * @param {boolean } displayErrors - Whether to display errors.
202
+ * @param {boolean } breakOnFirstLine - Whether to break on the first line.
203
+ */
152
204
function runScriptInThisContext ( script , displayErrors , breakOnFirstLine ) {
153
205
return ReflectApply (
154
206
runInContext ,
0 commit comments