@@ -124,6 +124,12 @@ const {
124124} = internalBinding ( 'contextify' ) ;
125125
126126const history = require ( 'internal/repl/history' ) ;
127+ let nextREPLResourceNumber = 1 ;
128+ // This prevents v8 code cache from getting confused and using a different
129+ // cache from a resource of the same name
130+ function getREPLResourceName ( ) {
131+ return `REPL${ nextREPLResourceNumber ++ } ` ;
132+ }
127133
128134// Lazy-loaded.
129135let processTopLevelAwait ;
@@ -541,10 +547,10 @@ function REPLServer(prompt,
541547 if ( e . name === 'SyntaxError' ) {
542548 // Remove stack trace.
543549 e . stack = e . stack
544- . replace ( / ^ r e p l : \d + \r ? \n / , '' )
550+ . replace ( / ^ R E P L \d + : \d + \r ? \n / , '' )
545551 . replace ( / ^ \s + a t \s .* \n ? / gm, '' ) ;
546552 } else if ( self . replMode === exports . REPL_MODE_STRICT ) {
547- e . stack = e . stack . replace ( / ( \s + a t \s + r e p l : ) ( \d + ) / ,
553+ e . stack = e . stack . replace ( / ( \s + a t \s + R E P L \d + : ) ( \d + ) / ,
548554 ( _ , pre , line ) => pre + ( line - 1 ) ) ;
549555 }
550556 }
@@ -759,7 +765,7 @@ function REPLServer(prompt,
759765 const evalCmd = self [ kBufferedCommandSymbol ] + cmd + '\n' ;
760766
761767 debug ( 'eval %j' , evalCmd ) ;
762- self . eval ( evalCmd , self . context , 'repl' , finish ) ;
768+ self . eval ( evalCmd , self . context , getREPLResourceName ( ) , finish ) ;
763769
764770 function finish ( e , ret ) {
765771 debug ( 'finish' , e , ret ) ;
@@ -1275,7 +1281,7 @@ function complete(line, callback) {
12751281 }
12761282
12771283 const evalExpr = `try { ${ expr } } catch {}` ;
1278- this . eval ( evalExpr , this . context , 'repl' , ( e , obj ) => {
1284+ this . eval ( evalExpr , this . context , getREPLResourceName ( ) , ( e , obj ) => {
12791285 if ( obj != null ) {
12801286 if ( typeof obj === 'object' || typeof obj === 'function' ) {
12811287 try {
0 commit comments