mirror of
https://github.com/nodejs/node.git
synced 2026-11-25 23:01:06 -05:00
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: https://github.com/nodejs/node/pull/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>
This commit is contained in:
1 parent
18da8b6f3c
commit
c51710eb0f
2 files changed
+20
-2
No files matched your search
+6
-2
@@ -388,7 +388,9 @@ function getCallSites(frameCount = 10, options) {
|
||||
// If frameCount is an object, it is the options object
|
||||
options = frameCount;
|
||||
validateObject(options, 'options');
|
||||
validateBoolean(options.sourceMap, 'options.sourceMap');
|
||||
if (options.sourceMap !== undefined) {
|
||||
validateBoolean(options.sourceMap, 'options.sourceMap');
|
||||
}
|
||||
frameCount = 10;
|
||||
} else {
|
||||
// If options is not provided, set it to an empty object
|
||||
@@ -397,7 +399,9 @@ function getCallSites(frameCount = 10, options) {
|
||||
} else {
|
||||
// If options is provided, validate it
|
||||
validateObject(options, 'options');
|
||||
validateBoolean(options.sourceMap, 'options.sourceMap');
|
||||
if (options.sourceMap !== undefined) {
|
||||
validateBoolean(options.sourceMap, 'options.sourceMap');
|
||||
}
|
||||
}
|
||||
|
||||
// Using kDefaultMaxCallStackSizeToCapture as reference
|
||||
|
||||
@@ -172,3 +172,17 @@ const assert = require('node:assert');
|
||||
assert.match(output, /test-get-callsite-explicit\.ts/);
|
||||
assert.strictEqual(status, 0);
|
||||
}
|
||||
|
||||
{
|
||||
// sourceMap must be a boolean
|
||||
assert.throws(() => getCallSites({ sourceMap: 1 }), {
|
||||
code: 'ERR_INVALID_ARG_TYPE'
|
||||
});
|
||||
assert.throws(() => getCallSites(1, { sourceMap: 1 }), {
|
||||
code: 'ERR_INVALID_ARG_TYPE'
|
||||
});
|
||||
|
||||
// Not specifying the sourceMap option should not fail.
|
||||
getCallSites({});
|
||||
getCallSites(1, {});
|
||||
}
|
||||
Reference in new issue
Block a user