@@ -30,7 +30,7 @@ const net = require('net');
30
30
// Do not require 'os' until needed so that test-os-checked-function can
31
31
// monkey patch it. If 'os' is required here, that test will fail.
32
32
const path = require ( 'path' ) ;
33
- const { inspect } = require ( 'util' ) ;
33
+ const { inspect, getCallSite } = require ( 'util' ) ;
34
34
const { isMainThread } = require ( 'worker_threads' ) ;
35
35
const { isModuleNamespaceObject } = require ( 'util/types' ) ;
36
36
@@ -551,25 +551,13 @@ function canCreateSymLink() {
551
551
return true ;
552
552
}
553
553
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
-
566
554
function mustNotCall ( msg ) {
567
- const callSite = getCallSite ( mustNotCall ) ;
555
+ const callSite = getCallSite ( ) [ 1 ] ;
568
556
return function mustNotCall ( ...args ) {
569
557
const argsInfo = args . length > 0 ?
570
558
`\ncalled with arguments: ${ args . map ( ( arg ) => inspect ( arg ) ) . join ( ', ' ) } ` : '' ;
571
559
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 } ` +
573
561
argsInfo ) ;
574
562
} ;
575
563
}
@@ -968,7 +956,6 @@ const common = {
968
956
expectWarning,
969
957
getArrayBufferViews,
970
958
getBufferSources,
971
- getCallSite,
972
959
getPrintedStackTrace,
973
960
getTTYfd,
974
961
hasIntl,
0 commit comments