From adb2c36f0f47aa4a105688e2546fc7be24fe6bb5 Mon Sep 17 00:00:00 2001 From: Geoffrey Booth Date: Sun, 18 Feb 2024 17:19:44 -0800 Subject: [PATCH] typings: lib/internal/vm.js PR-URL: https://github.com/nodejs/node/pull/50112 Reviewed-By: Yagiz Nizipli Reviewed-By: Chengzhong Wu Reviewed-By: Franziska Hinkelmann Reviewed-By: Joyee Cheung Reviewed-By: Rich Trott --- lib/internal/vm.js | 60 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 58 insertions(+), 2 deletions(-) diff --git a/lib/internal/vm.js b/lib/internal/vm.js index 337a2cf0b1ee73..0b9865ea9a0cf6 100644 --- a/lib/internal/vm.js +++ b/lib/internal/vm.js @@ -31,10 +31,23 @@ const { }, } = internalBinding('util'); +/** + * Checks if the given object is a context object. + * @param {object} object - The object to check. + * @returns {boolean} - Returns true if the object is a context object, else false. + */ function isContext(object) { return object[contextify_context_private_symbol] !== undefined; } +/** + * Retrieves the host-defined option ID based on the provided importModuleDynamically and hint. + * @param {import('internal/modules/esm/utils').ImportModuleDynamicallyCallback | undefined} importModuleDynamically - + * The importModuleDynamically function or undefined. + * @param {string} hint - The hint for the option ID. + * @returns {symbol | import('internal/modules/esm/utils').ImportModuleDynamicallyCallback} - The host-defined option + * ID. + */ function getHostDefinedOptionId(importModuleDynamically, hint) { if (importModuleDynamically === vm_dynamic_import_main_context_default || importModuleDynamically === vm_dynamic_import_default_internal) { @@ -66,6 +79,12 @@ function getHostDefinedOptionId(importModuleDynamically, hint) { 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. @@ -83,6 +102,25 @@ function registerImportModuleDynamically(referrer, 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,