Skip to content

Commit 746c3c2

Browse files
authored
util: assert getCallSites does not invoke Error.prepareStackTrace
PR-URL: #60922 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Ilyas Shabi <[email protected]>
1 parent 5879e9b commit 746c3c2

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

doc/api/util.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,9 @@ changes:
564564
Returns an array of call site objects containing the stack of
565565
the caller function.
566566

567+
Unlike accessing an `error.stack`, the result returned from this API is not
568+
interfered with `Error.prepareStackTrace`.
569+
567570
```mjs
568571
import { getCallSites } from 'node:util';
569572

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
const assert = require('node:assert');
5+
const { getCallSites } = require('node:util');
6+
7+
// Asserts that util.getCallSites() does not invoke
8+
// Error.prepareStackTrace.
9+
10+
Error.prepareStackTrace = common.mustNotCall();
11+
12+
const sites = getCallSites(1);
13+
assert.strictEqual(sites.length, 1);
14+
assert.strictEqual(sites[0].scriptName, __filename);

0 commit comments

Comments
 (0)