@@ -69,12 +69,15 @@ const CJSModule = require('internal/modules/cjs/loader');
6969const domain = require ( 'domain' ) ;
7070const debug = require ( 'internal/util/debuglog' ) . debuglog ( 'repl' ) ;
7171const {
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' ) ;
7881const { sendInspectorCommand } = require ( 'internal/util/inspector' ) ;
7982const experimentalREPLAwait = require ( 'internal/options' ) . getOptionValue (
8083 '--experimental-repl-await'
@@ -473,10 +476,29 @@ function REPLServer(prompt,
473476 let errStack = '' ;
474477
475478 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+ } ) ;
478501 decorateErrorStack ( e ) ;
479- Error . prepareStackTrace = pstrace ;
480502
481503 if ( e . domainThrown ) {
482504 delete e . domain ;
@@ -590,30 +612,6 @@ function REPLServer(prompt,
590612 }
591613 }
592614
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-
617615 function _parseREPLKeyword ( keyword , rest ) {
618616 const cmd = this . commands [ keyword ] ;
619617 if ( cmd ) {
0 commit comments