From c1797e06fcfd1af9565d1ea5df3efbdf250a8a80 Mon Sep 17 00:00:00 2001 From: Geoffrey Booth Date: Mon, 9 Oct 2023 20:47:09 -0700 Subject: [PATCH 1/3] typings: lib/internal/vm.js --- lib/internal/vm.js | 56 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 54 insertions(+), 2 deletions(-) diff --git a/lib/internal/vm.js b/lib/internal/vm.js index 337a2cf0b1ee73..13b15349ff7f98 100644 --- a/lib/internal/vm.js +++ b/lib/internal/vm.js @@ -31,10 +31,21 @@ 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 +77,11 @@ 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 +99,24 @@ 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 - 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, From fb07f0c4ec47d0019b162da48170fd5c190edbcd Mon Sep 17 00:00:00 2001 From: Geoffrey Booth Date: Sat, 3 Feb 2024 10:51:38 -0800 Subject: [PATCH 2/3] @legendecas suggestion --- lib/internal/vm.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/internal/vm.js b/lib/internal/vm.js index 13b15349ff7f98..2fba759378e9ed 100644 --- a/lib/internal/vm.js +++ b/lib/internal/vm.js @@ -105,13 +105,13 @@ function registerImportModuleDynamically(referrer, importModuleDynamically) { * @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 - The cached data 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 Date: Sat, 3 Feb 2024 11:05:47 -0800 Subject: [PATCH 3/3] lint --- lib/internal/vm.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/internal/vm.js b/lib/internal/vm.js index 2fba759378e9ed..0b9865ea9a0cf6 100644 --- a/lib/internal/vm.js +++ b/lib/internal/vm.js @@ -42,9 +42,11 @@ function isContext(object) { /** * 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 {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. + * @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 || @@ -80,7 +82,8 @@ function getHostDefinedOptionId(importModuleDynamically, 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. + * @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 @@ -107,7 +110,8 @@ function registerImportModuleDynamically(referrer, importModuleDynamically) { * @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