Skip to content

Commit c6efcd0

Browse files
jasnellRafaelGSS
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 183711c commit c6efcd0

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
@@ -532,7 +532,9 @@ function getCallSites(frameCount = 10, options) {
532532
// If frameCount is an object, it is the options object
533533
options = frameCount;
534534
validateObject(options, 'options');
535-
validateBoolean(options.sourceMap, 'options.sourceMap');
535+
if (options.sourceMap !== undefined) {
536+
validateBoolean(options.sourceMap, 'options.sourceMap');
537+
}
536538
frameCount = 10;
537539
} else {
538540
// If options is not provided, set it to an empty object
@@ -541,7 +543,9 @@ function getCallSites(frameCount = 10, options) {
541543
} else {
542544
// If options is provided, validate it
543545
validateObject(options, 'options');
544-
validateBoolean(options.sourceMap, 'options.sourceMap');
546+
if (options.sourceMap !== undefined) {
547+
validateBoolean(options.sourceMap, 'options.sourceMap');
548+
}
545549
}
546550

547551
// 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)