lib: add util.getCallSite() API

PR-URL: https://github.com/nodejs/node/pull/54380
Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Claudio Wunder <cwunder@gnome.org>
Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
Rafael Gonzaga 2024-09-04 16:47:25 -03:00 committed by GitHub
parent 6c6a9338cb
commit 80a989f931
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 298 additions and 0 deletions

View file

@ -315,6 +315,17 @@ function parseEnv(content) {
return binding.parseEnv(content);
}
/**
* Returns the callSite
* @param {number} frames
* @returns {object}
*/
function getCallSite(frames = 10) {
// Using kDefaultMaxCallStackSizeToCapture as reference
validateNumber(frames, 'frames', 1, 200);
return binding.getCallSite(frames);
};
// Keep the `exports =` so that various functions can still be monkeypatched
module.exports = {
_errnoException,
@ -329,6 +340,7 @@ module.exports = {
format,
styleText,
formatWithOptions,
getCallSite,
getSystemErrorMap,
getSystemErrorName,
inherits,