Skip to content

Commit d5a26f6

Browse files
jasnelladuh95
authored andcommitted
lib: make getCallSites sourceMap option truly optional
When calling the `util.getCallSites(...)` API, if the `options` argument is omitted, then the `options.sourceMap` option is defaulted to false. However, if any empty `options` is passed, it would throw an error is `sourceMap` was not explicitly given. This relaxes that so that `sourceMap` can be left unspecified. For instance, before this commit, `getCallSites({})` would throw an error. Also, add more test coverage of this. PR-URL: #57388 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Jason Zhang <xzha4350@gmail.com>
1 parent 30e5658 commit d5a26f6

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

lib/util.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,9 @@ function getCallSites(frameCount = 10, options) {
388388
// If frameCount is an object, it is the options object
389389
options = frameCount;
390390
validateObject(options, 'options');
391-
validateBoolean(options.sourceMap, 'options.sourceMap');
391+
if (options.sourceMap !== undefined) {
392+
validateBoolean(options.sourceMap, 'options.sourceMap');
393+
}
392394
frameCount = 10;
393395
} else {
394396
// If options is not provided, set it to an empty object
@@ -397,7 +399,9 @@ function getCallSites(frameCount = 10, options) {
397399
} else {
398400
// If options is provided, validate it
399401
validateObject(options, 'options');
400-
validateBoolean(options.sourceMap, 'options.sourceMap');
402+
if (options.sourceMap !== undefined) {
403+
validateBoolean(options.sourceMap, 'options.sourceMap');
404+
}
401405
}
402406

403407
// Using kDefaultMaxCallStackSizeToCapture as reference

test/parallel/test-util-getcallsites.js

+14
Original file line numberDiff line numberDiff line change
@@ -172,3 +172,17 @@ const assert = require('node:assert');
172172
assert.match(output, /test-get-callsite-explicit\.ts/);
173173
assert.strictEqual(status, 0);
174174
}
175+
176+
{
177+
// sourceMap must be a boolean
178+
assert.throws(() => getCallSites({ sourceMap: 1 }), {
179+
code: 'ERR_INVALID_ARG_TYPE'
180+
});
181+
assert.throws(() => getCallSites(1, { sourceMap: 1 }), {
182+
code: 'ERR_INVALID_ARG_TYPE'
183+
});
184+
185+
// Not specifying the sourceMap option should not fail.
186+
getCallSites({});
187+
getCallSites(1, {});
188+
}

0 commit comments

Comments
 (0)