Skip to content

Commit a65e441

Browse files
avivkellerjasnell
authored andcommitted
test: remove getCallSite from common
PR-URL: nodejs#54947 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 77ca5ca commit a65e441

File tree

3 files changed

+3
-25
lines changed

3 files changed

+3
-25
lines changed

test/common/README.md

-7
Original file line numberDiff line numberDiff line change
@@ -187,13 +187,6 @@ Returns an instance of all possible `ArrayBufferView`s of the provided Buffer.
187187
Returns an instance of all possible `BufferSource`s of the provided Buffer,
188188
consisting of all `ArrayBufferView` and an `ArrayBuffer`.
189189

190-
### `getCallSite(func)`
191-
192-
* `func` [\<Function>][<Function>]
193-
* return [\<string>][<string>]
194-
195-
Returns the file name and line number for the provided Function.
196-
197190
### `getTTYfd()`
198191

199192
Attempts to get a valid TTY file descriptor. Returns `-1` if it fails.

test/common/index.js

+3-16
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ const net = require('net');
3030
// Do not require 'os' until needed so that test-os-checked-function can
3131
// monkey patch it. If 'os' is required here, that test will fail.
3232
const path = require('path');
33-
const { inspect } = require('util');
33+
const { inspect, getCallSite } = require('util');
3434
const { isMainThread } = require('worker_threads');
3535
const { isModuleNamespaceObject } = require('util/types');
3636

@@ -551,25 +551,13 @@ function canCreateSymLink() {
551551
return true;
552552
}
553553

554-
function getCallSite(top) {
555-
const originalStackFormatter = Error.prepareStackTrace;
556-
Error.prepareStackTrace = (err, stack) =>
557-
`${stack[0].getFileName()}:${stack[0].getLineNumber()}`;
558-
const err = new Error();
559-
Error.captureStackTrace(err, top);
560-
// With the V8 Error API, the stack is not formatted until it is accessed
561-
err.stack; // eslint-disable-line no-unused-expressions
562-
Error.prepareStackTrace = originalStackFormatter;
563-
return err.stack;
564-
}
565-
566554
function mustNotCall(msg) {
567-
const callSite = getCallSite(mustNotCall);
555+
const callSite = getCallSite()[1];
568556
return function mustNotCall(...args) {
569557
const argsInfo = args.length > 0 ?
570558
`\ncalled with arguments: ${args.map((arg) => inspect(arg)).join(', ')}` : '';
571559
assert.fail(
572-
`${msg || 'function should not have been called'} at ${callSite}` +
560+
`${msg || 'function should not have been called'} at ${callSite.scriptName}:${callSite.lineNumber}` +
573561
argsInfo);
574562
};
575563
}
@@ -968,7 +956,6 @@ const common = {
968956
expectWarning,
969957
getArrayBufferViews,
970958
getBufferSources,
971-
getCallSite,
972959
getPrintedStackTrace,
973960
getTTYfd,
974961
hasIntl,

test/common/index.mjs

-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ const {
1515
expectWarning,
1616
getArrayBufferViews,
1717
getBufferSources,
18-
getCallSite,
1918
getTTYfd,
2019
hasCrypto,
2120
hasIntl,
@@ -69,7 +68,6 @@ export {
6968
expectWarning,
7069
getArrayBufferViews,
7170
getBufferSources,
72-
getCallSite,
7371
getPort,
7472
getTTYfd,
7573
hasCrypto,

0 commit comments

Comments
 (0)