Skip to content

Commit

Permalink
fixup! apply cr suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
RafaelGSS committed Sep 2, 2024
1 parent 36c2839 commit aa11f56
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion doc/api/util.md
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ added: REPLACEME
-->

* `frames` {number} Number of frames returned in the stacktrace.
**Default:** `10`.
**Default:** `10`. Allowable range is between 1 and 200.
* Returns: {Object\[]} An array of stacktrace objects
* `functionName` {string} Returns the name of the function associated with this stack frame.
* `scriptName` {string} Returns the name of the resource that contains the script for the
Expand Down
1 change: 1 addition & 0 deletions src/node_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ static void GetCallSite(const FunctionCallbackInfo<Value>& args) {
CHECK_EQ(args.Length(), 1);
CHECK(args[0]->IsNumber());
const uint32_t frames = args[0].As<Uint32>()->Value();
DCHECK(frames >= 1 && frames <= 200);

// +1 for disregarding node:util
Local<StackTrace> stack = StackTrace::CurrentStackTrace(isolate, frames + 1);
Expand Down
5 changes: 4 additions & 1 deletion test/parallel/test-util-getCallSite.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const assert = require('node:assert');
);
}

// Guarantee dot-left numbers are ignored
{
const callsite = getCallSite(3.6);
assert.strictEqual(callsite.length, 3);
Expand Down Expand Up @@ -68,6 +69,7 @@ const assert = require('node:assert');
);
}

// Guarantee [eval] will appear on stacktraces when using -e
{
const { status, stderr, stdout } = spawnSync(
process.execPath,
Expand All @@ -84,6 +86,7 @@ const assert = require('node:assert');
assert.strictEqual(stdout.toString(), '[eval]');
}

// Guarantee the stacktrace[0] is the filename
{
const { status, stderr, stdout } = spawnSync(
process.execPath,
Expand All @@ -93,11 +96,11 @@ const assert = require('node:assert');
assert.strictEqual(stdout.toString(), file);
}

// Error.stackTraceLimit should not influence callsite size
{
const originalStackTraceLimit = Error.stackTraceLimit;
Error.stackTraceLimit = 0;
const callsite = getCallSite();
// Error.stackTraceLimit should not influence callsite size
assert.notStrictEqual(callsite.length, 0);
Error.stackTraceLimit = originalStackTraceLimit;
}

0 comments on commit aa11f56

Please sign in to comment.