Skip to content

lib: make getCallSites sourceMap option truly optional #57388

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
14 changes: 14 additions & 0 deletions test/parallel/test-util-getcallsites.js
Original file line number Diff line number Diff line change
Expand Up @@ -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, {});
}
Loading