@@ -69,12 +69,15 @@ const CJSModule = require('internal/modules/cjs/loader');
69
69
const domain = require ( 'domain' ) ;
70
70
const debug = require ( 'internal/util/debuglog' ) . debuglog ( 'repl' ) ;
71
71
const {
72
- ERR_CANNOT_WATCH_SIGINT ,
73
- ERR_INVALID_ARG_TYPE ,
74
- ERR_INVALID_REPL_EVAL_CONFIG ,
75
- ERR_INVALID_REPL_INPUT ,
76
- ERR_SCRIPT_EXECUTION_INTERRUPTED
77
- } = require ( 'internal/errors' ) . codes ;
72
+ codes : {
73
+ ERR_CANNOT_WATCH_SIGINT ,
74
+ ERR_INVALID_ARG_TYPE ,
75
+ ERR_INVALID_REPL_EVAL_CONFIG ,
76
+ ERR_INVALID_REPL_INPUT ,
77
+ ERR_SCRIPT_EXECUTION_INTERRUPTED ,
78
+ } ,
79
+ overrideStackTrace,
80
+ } = require ( 'internal/errors' ) ;
78
81
const { sendInspectorCommand } = require ( 'internal/util/inspector' ) ;
79
82
const experimentalREPLAwait = require ( 'internal/options' ) . getOptionValue (
80
83
'--experimental-repl-await'
@@ -473,10 +476,29 @@ function REPLServer(prompt,
473
476
let errStack = '' ;
474
477
475
478
if ( typeof e === 'object' && e !== null ) {
476
- const pstrace = Error . prepareStackTrace ;
477
- Error . prepareStackTrace = prepareStackTrace ( pstrace ) ;
479
+ overrideStackTrace . set ( e , ( error , stackFrames ) => {
480
+ let frames ;
481
+ if ( typeof stackFrames === 'object' ) {
482
+ // Search from the bottom of the call stack to
483
+ // find the first frame with a null function name
484
+ const idx = stackFrames
485
+ . reverse ( )
486
+ . findIndex ( ( frame ) => frame . getFunctionName ( ) === null ) ;
487
+ // If found, get rid of it and everything below it
488
+ frames = stackFrames . splice ( idx + 1 ) ;
489
+ } else {
490
+ frames = stackFrames ;
491
+ }
492
+ // FIXME(devsnek): this is inconsistent with the checks
493
+ // that the real prepareStackTrace dispatch uses in
494
+ // lib/internal/errors.js.
495
+ if ( typeof Error . prepareStackTrace === 'function' ) {
496
+ return Error . prepareStackTrace ( error , frames ) ;
497
+ }
498
+ frames . push ( error ) ;
499
+ return frames . reverse ( ) . join ( '\n at ' ) ;
500
+ } ) ;
478
501
decorateErrorStack ( e ) ;
479
- Error . prepareStackTrace = pstrace ;
480
502
481
503
if ( e . domainThrown ) {
482
504
delete e . domain ;
@@ -590,30 +612,6 @@ function REPLServer(prompt,
590
612
}
591
613
}
592
614
593
- function filterInternalStackFrames ( structuredStack ) {
594
- // Search from the bottom of the call stack to
595
- // find the first frame with a null function name
596
- if ( typeof structuredStack !== 'object' )
597
- return structuredStack ;
598
- const idx = structuredStack . reverse ( ) . findIndex (
599
- ( frame ) => frame . getFunctionName ( ) === null ) ;
600
-
601
- // If found, get rid of it and everything below it
602
- structuredStack = structuredStack . splice ( idx + 1 ) ;
603
- return structuredStack ;
604
- }
605
-
606
- function prepareStackTrace ( fn ) {
607
- return ( error , stackFrames ) => {
608
- const frames = filterInternalStackFrames ( stackFrames ) ;
609
- if ( fn ) {
610
- return fn ( error , frames ) ;
611
- }
612
- frames . push ( error ) ;
613
- return frames . reverse ( ) . join ( '\n at ' ) ;
614
- } ;
615
- }
616
-
617
615
function _parseREPLKeyword ( keyword , rest ) {
618
616
const cmd = this . commands [ keyword ] ;
619
617
if ( cmd ) {
0 commit comments