4343'use strict' ;
4444
4545const {
46+ ArrayIsArray,
4647 ArrayPrototypeAt,
4748 ArrayPrototypeFilter,
4849 ArrayPrototypeFindLastIndex,
@@ -98,6 +99,7 @@ const {
9899
99100const {
100101 isProxy,
102+ isPromise,
101103} = require ( 'internal/util/types' ) ;
102104
103105const { BuiltinModule } = require ( 'internal/bootstrap/realm' ) ;
@@ -351,6 +353,7 @@ function REPLServer(prompt,
351353 this . allowBlockingCompletions = ! ! options . allowBlockingCompletions ;
352354 this . useColors = ! ! options . useColors ;
353355 this . _domain = options . domain || domain . create ( ) ;
356+ this . _completeDomain = domain . create ( ) ;
354357 this . useGlobal = ! ! useGlobal ;
355358 this . ignoreUndefined = ! ! ignoreUndefined ;
356359 this . replMode = replMode || module . exports . REPL_MODE_SLOPPY ;
@@ -668,6 +671,8 @@ function REPLServer(prompt,
668671 }
669672
670673 self . eval = self . _domain . bind ( eval_ ) ;
674+ self . completeEval = self . _completeDomain . bind ( eval_ ) ;
675+ self . _completeDomain . on ( 'error' , ( err ) => { } ) ;
671676
672677 self . _domain . on ( 'error' , function debugDomainError ( e ) {
673678 debug ( 'domain error' ) ;
@@ -1541,7 +1546,7 @@ function complete(line, callback) {
15411546 return includesProxiesOrGetters (
15421547 completeTargetAst . body [ 0 ] . expression ,
15431548 parsableCompleteTarget ,
1544- this . eval ,
1549+ this . completeEval ,
15451550 this . context ,
15461551 ( includes ) => {
15471552 if ( includes ) {
@@ -1558,8 +1563,10 @@ function complete(line, callback) {
15581563
15591564 const memberGroups = [ ] ;
15601565 const evalExpr = `try { ${ expr } } catch {}` ;
1561- this . eval ( evalExpr , this . context , getREPLResourceName ( ) , ( e , obj ) => {
1566+ this . completeEval ( evalExpr , this . context , getREPLResourceName ( ) , ( e , obj ) => {
15621567 try {
1568+ reclusiveCatchPromise ( obj ) ;
1569+
15631570 let p ;
15641571 if ( ( typeof obj === 'object' && obj !== null ) ||
15651572 typeof obj === 'function' ) {
@@ -1800,6 +1807,7 @@ function includesProxiesOrGetters(expr, exprStr, evalFn, ctx, callback) {
18001807 // is the property identifier/literal)
18011808 if ( expr . object . type === 'Identifier' ) {
18021809 return evalFn ( `try { ${ expr . object . name } } catch {}` , ctx , getREPLResourceName ( ) , ( err , obj ) => {
1810+ reclusiveCatchPromise ( obj ) ;
18031811 if ( err ) {
18041812 return callback ( false ) ;
18051813 }
@@ -1815,6 +1823,7 @@ function includesProxiesOrGetters(expr, exprStr, evalFn, ctx, callback) {
18151823
18161824 return evalFn (
18171825 `try { ${ exprStr } } catch {} ` , ctx , getREPLResourceName ( ) , ( err , obj ) => {
1826+ reclusiveCatchPromise ( obj ) ;
18181827 if ( err ) {
18191828 return callback ( false ) ;
18201829 }
@@ -1877,6 +1886,7 @@ function includesProxiesOrGetters(expr, exprStr, evalFn, ctx, callback) {
18771886 ctx ,
18781887 getREPLResourceName ( ) ,
18791888 ( err , evaledProp ) => {
1889+ reclusiveCatchPromise ( evaledProp ) ;
18801890 if ( err ) {
18811891 return callback ( false ) ;
18821892 }
@@ -1902,7 +1912,9 @@ function includesProxiesOrGetters(expr, exprStr, evalFn, ctx, callback) {
19021912 function safeIsProxyAccess ( obj , prop ) {
19031913 // Accessing `prop` may trigger a getter that throws, so we use try-catch to guard against it
19041914 try {
1905- return isProxy ( obj [ prop ] ) ;
1915+ const value = obj [ prop ] ;
1916+ reclusiveCatchPromise ( value ) ;
1917+ return isProxy ( value ) ;
19061918 } catch {
19071919 return false ;
19081920 }
@@ -1911,6 +1923,29 @@ function includesProxiesOrGetters(expr, exprStr, evalFn, ctx, callback) {
19111923 return callback ( false ) ;
19121924}
19131925
1926+ function reclusiveCatchPromise ( obj , seen = new SafeWeakSet ( ) ) {
1927+ if ( isPromise ( obj ) ) {
1928+ return obj . catch ( ( ) => { } ) ;
1929+ } else if ( ArrayIsArray ( obj ) ) {
1930+ obj . forEach ( ( item ) => {
1931+ reclusiveCatchPromise ( item , seen ) ;
1932+ } ) ;
1933+ } else if ( obj && typeof obj === 'object' ) {
1934+ if ( seen . has ( obj ) ) return ;
1935+ seen . add ( obj ) ;
1936+
1937+ let props ;
1938+ try {
1939+ props = ObjectGetOwnPropertyNames ( obj ) ;
1940+ } catch {
1941+ return ;
1942+ }
1943+ props . forEach ( ( key ) => {
1944+ reclusiveCatchPromise ( obj [ key ] , seen ) ;
1945+ } ) ;
1946+ }
1947+ }
1948+
19141949REPLServer . prototype . completeOnEditorMode = ( callback ) => ( err , results ) => {
19151950 if ( err ) return callback ( err ) ;
19161951
0 commit comments