镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content
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, {});
}