@@ -74,7 +74,7 @@ const Stream = require('stream');
7474const vm = require ( 'vm' ) ;
7575const path = require ( 'path' ) ;
7676const fs = require ( 'fs' ) ;
77- const { Interface, cursorTo , clearScreenDown } = require ( 'readline' ) ;
77+ const { Interface } = require ( 'readline' ) ;
7878const { Console } = require ( 'console' ) ;
7979const CJSModule = require ( 'internal/modules/cjs/loader' ) . Module ;
8080const domain = require ( 'domain' ) ;
@@ -90,13 +90,13 @@ const {
9090 overrideStackTrace,
9191} = require ( 'internal/errors' ) ;
9292const { sendInspectorCommand } = require ( 'internal/util/inspector' ) ;
93- const { appendPreview, clearPreview } = require ( 'internal/readline/utils' ) ;
9493const experimentalREPLAwait = require ( 'internal/options' ) . getOptionValue (
9594 '--experimental-repl-await'
9695) ;
9796const {
9897 isRecoverableError,
99- kStandaloneREPL
98+ kStandaloneREPL,
99+ makePreview
100100} = require ( 'internal/repl/utils' ) ;
101101const {
102102 getOwnNonIndexProperties,
@@ -113,8 +113,6 @@ const {
113113const history = require ( 'internal/repl/history' ) ;
114114const { setImmediate } = require ( 'timers' ) ;
115115const inspector = require ( 'inspector' ) ;
116- const kPreviewResults = Symbol ( 'preview-result-fn' ) ;
117- const util = require ( 'util' ) ;
118116
119117// Lazy-loaded.
120118let processTopLevelAwait ;
@@ -227,6 +225,20 @@ function REPLServer(prompt,
227225 throw new ERR_INVALID_REPL_EVAL_CONFIG ( ) ;
228226 }
229227
228+ const eagerSession = new inspector . Session ( ) ;
229+ eagerSession . connect ( ) ;
230+ eagerSession . once ( 'Runtime.executionContextCreated' ,
231+ ( { params : { context } } ) => {
232+ this . on ( 'buffer' , ( line ) => {
233+ // No need of preview for a multiline statement.
234+ if ( this [ kBufferedCommandSymbol ] !== '' )
235+ return ;
236+ makePreview ( self , eagerSession , context . id , line ) ;
237+ } ) ;
238+ eagerSession . post ( 'Runtime.disable' ) ;
239+ } ) ;
240+ eagerSession . post ( 'Runtime.enable' ) ;
241+
230242 // Add this listener only once and use a WeakSet that contains the REPLs
231243 // domains. Otherwise we'd have to add a single listener to each REPL instance
232244 // and that could trigger the `MaxListenersExceededWarning`.
@@ -269,66 +281,6 @@ function REPLServer(prompt,
269281
270282 const self = this ;
271283
272- self [ kPreviewResults ] = ( eagerSession , eagerEvalContextId ) => {
273- this . on ( 'buffer' , ( line ) => {
274- clearPreview . call ( this ) ;
275-
276- // No need of preview for a multiline statement
277- if ( this [ kBufferedCommandSymbol ] !== '' )
278- return ;
279-
280- eagerSession . post ( 'Runtime.evaluate' , {
281- expression : line . toString ( ) ,
282- generatePreview : true ,
283- throwOnSideEffect : true ,
284- timeout : 500 ,
285- executionContextId : eagerEvalContextId
286- } , ( error , previewResult ) => {
287-
288- if ( error ) {
289- debug ( `Error while generating preview ${ error } ` ) ;
290- return ;
291- }
292-
293- if ( undefined !== previewResult . result . value ) {
294- const value = util . inspect ( previewResult . result . value ) ;
295- appendPreview . call ( this , value , cursorTo , clearScreenDown ) ;
296- return ;
297- }
298-
299-
300- // If no exception and we have objectId
301- // Run the expression via callFunctionOn
302- // And return it from util inspect.
303- if ( ! previewResult . exceptionDetails && previewResult . result . objectId ) {
304- eagerSession . post ( 'Runtime.callFunctionOn' , {
305- functionDeclaration :
306- 'function(arg) { return util.inspect(arg) }' ,
307- arguments : [ previewResult . result ] ,
308- executionContextId : eagerEvalContextId ,
309- returnByValue : true ,
310- } , ( err , result ) => {
311- if ( ! err ) {
312- appendPreview . call ( this , result . result . value ,
313- cursorTo , clearScreenDown ) ;
314- }
315- } ) ;
316- }
317- } ) ;
318- } ) ;
319- } ;
320-
321-
322- // Set up session for eager evaluation
323- const eagerSession = new inspector . Session ( ) ;
324- eagerSession . connect ( ) ;
325- // eslint-disable-next-line
326- eagerSession . once ( 'Runtime.executionContextCreated' , ( { params : { context } } ) => {
327- self [ kPreviewResults ] ( eagerSession , context . id ) ;
328- eagerSession . post ( 'Runtime.disable' ) ;
329- } ) ;
330- eagerSession . post ( 'Runtime.enable' ) ;
331-
332284 // Pause taking in new input, and store the keys in a buffer.
333285 const pausedBuffer = [ ] ;
334286 let paused = false ;
0 commit comments