@@ -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.
3232const path = require ( 'path' ) ;
33- const { inspect } = require ( 'util' ) ;
33+ const { inspect, getCallSite } = require ( 'util' ) ;
3434const { isMainThread } = require ( 'worker_threads' ) ;
3535const { 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-
566554function 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,
0 commit comments