| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent b53919d commit adb2c36
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -31,10 +31,23 @@ const { | |||
| 31 | 31 | }, | |
| 32 | 32 | } = internalBinding('util'); | |
| 33 | 33 | ||
| 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 | + */ | ||
| 34 | 39 | function isContext(object) { | |
| 35 | 40 | return object[contextify_context_private_symbol] !== undefined; | |
| 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 - | ||
| 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 | + */ | ||
| 38 | 51 | function getHostDefinedOptionId(importModuleDynamically, hint) { | |
| 39 | 52 | if (importModuleDynamically === vm_dynamic_import_main_context_default || | |
| 40 | 53 | importModuleDynamically === vm_dynamic_import_default_internal) { | |
@@ -66,6 +79,12 @@ function getHostDefinedOptionId(importModuleDynamically, hint) { | |||
| 66 | 79 | return Symbol(hint); | |
| 67 | 80 | } | |
| 68 | 81 | ||
| 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 | + */ | ||
| 69 | 88 | function registerImportModuleDynamically(referrer, importModuleDynamically) { | |
| 70 | 89 | // If it's undefined or certain known symbol, there's no customization so | |
| 71 | 90 | // no need to register anything. | |
@@ -83,6 +102,25 @@ function registerImportModuleDynamically(referrer, importModuleDynamically) { | |||
| 83 | 102 | }); | |
| 84 | 103 | } | |
| 85 | 104 | ||
| 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 | + */ | ||
| 86 | 124 | function internalCompileFunction( | |
| 87 | 125 | code, filename, lineOffset, columnOffset, | |
| 88 | 126 | cachedData, produceCachedData, parsingContext, contextExtensions, | |
@@ -117,6 +155,19 @@ function internalCompileFunction( | |||
| 117 | 155 | return result; | |
| 118 | 156 | } | |
| 119 | 157 | ||
| 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 | + */ | ||
| 120 | 171 | function makeContextifyScript(code, | |
| 121 | 172 | filename, | |
| 122 | 173 | lineOffset, | |
@@ -147,8 +198,13 @@ function makeContextifyScript(code, | |||
| 147 | 198 | return script; | |
| 148 | 199 | } | |
| 149 | 200 | ||
| 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 | + */ | ||
| 152 | 208 | function runScriptInThisContext(script, displayErrors, breakOnFirstLine) { | |
| 153 | 209 | return ReflectApply( | |
| 154 | 210 | runInContext, | |
| Back | FazBrowse Home | New Git URL |
0 commit comments