Skip to content

Commit c9ca65c

Browse files
committed
typings: lib/internal/vm.js
1 parent 5acd42e commit c9ca65c

File tree

1 file changed

+54
-2
lines changed

1 file changed

+54
-2
lines changed

lib/internal/vm.js

+54-2
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,23 @@ const {
2929
getOptionValue,
3030
} = require('internal/options');
3131

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+
*/
3237
function isContext(object) {
3338
validateObject(object, 'object', kValidateObjectAllowArray);
3439

3540
return _isContext(object);
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 - 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+
*/
3849
function getHostDefinedOptionId(importModuleDynamically, hint) {
3950
if (importModuleDynamically === vm_dynamic_import_main_context_default ||
4051
importModuleDynamically === vm_dynamic_import_default_internal) {
@@ -66,6 +77,11 @@ function getHostDefinedOptionId(importModuleDynamically, hint) {
6677
return Symbol(hint);
6778
}
6879

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+
*/
6985
function registerImportModuleDynamically(referrer, importModuleDynamically) {
7086
// If it's undefined or certain known symbol, there's no customization so
7187
// no need to register anything.
@@ -83,6 +99,24 @@ function registerImportModuleDynamically(referrer, importModuleDynamically) {
8399
});
84100
}
85101

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+
*/
86120
function internalCompileFunction(
87121
code, filename, lineOffset, columnOffset,
88122
cachedData, produceCachedData, parsingContext, contextExtensions,
@@ -117,6 +151,19 @@ function internalCompileFunction(
117151
return result;
118152
}
119153

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+
*/
120167
function makeContextifyScript(code,
121168
filename,
122169
lineOffset,
@@ -147,8 +194,13 @@ function makeContextifyScript(code,
147194
return script;
148195
}
149196

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+
*/
152204
function runScriptInThisContext(script, displayErrors, breakOnFirstLine) {
153205
return ReflectApply(
154206
runInContext,

0 commit comments

Comments
 (0)