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,9 @@ 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 ) ;
15631569 let p ;
15641570 if ( ( typeof obj === 'object' && obj !== null ) ||
15651571 typeof obj === 'function' ) {
@@ -1800,6 +1806,7 @@ function includesProxiesOrGetters(expr, exprStr, evalFn, ctx, callback) {
18001806 // is the property identifier/literal)
18011807 if ( expr . object . type === 'Identifier' ) {
18021808 return evalFn ( `try { ${ expr . object . name } } catch {}` , ctx , getREPLResourceName ( ) , ( err , obj ) => {
1809+ reclusiveCatchPromise ( obj ) ;
18031810 if ( err ) {
18041811 return callback ( false ) ;
18051812 }
@@ -1815,6 +1822,7 @@ function includesProxiesOrGetters(expr, exprStr, evalFn, ctx, callback) {
18151822
18161823 return evalFn (
18171824 `try { ${ exprStr } } catch {} ` , ctx , getREPLResourceName ( ) , ( err , obj ) => {
1825+ reclusiveCatchPromise ( obj ) ;
18181826 if ( err ) {
18191827 return callback ( false ) ;
18201828 }
@@ -1877,6 +1885,7 @@ function includesProxiesOrGetters(expr, exprStr, evalFn, ctx, callback) {
18771885 ctx ,
18781886 getREPLResourceName ( ) ,
18791887 ( err , evaledProp ) => {
1888+ reclusiveCatchPromise ( evaledProp ) ;
18801889 if ( err ) {
18811890 return callback ( false ) ;
18821891 }
@@ -1902,7 +1911,9 @@ function includesProxiesOrGetters(expr, exprStr, evalFn, ctx, callback) {
19021911 function safeIsProxyAccess ( obj , prop ) {
19031912 // Accessing `prop` may trigger a getter that throws, so we use try-catch to guard against it
19041913 try {
1905- return isProxy ( obj [ prop ] ) ;
1914+ const value = obj [ prop ] ;
1915+ reclusiveCatchPromise ( value ) ;
1916+ return isProxy ( value ) ;
19061917 } catch {
19071918 return false ;
19081919 }
@@ -1911,6 +1922,33 @@ function includesProxiesOrGetters(expr, exprStr, evalFn, ctx, callback) {
19111922 return callback ( false ) ;
19121923}
19131924
1925+ function reclusiveCatchPromise ( obj , seen = new SafeWeakSet ( ) ) {
1926+ if ( isPromise ( obj ) ) {
1927+ return obj . catch ( ( ) => { } ) ;
1928+ } else if ( ArrayIsArray ( obj ) ) {
1929+ obj . forEach ( ( item ) => {
1930+ reclusiveCatchPromise ( item , seen ) ;
1931+ } ) ;
1932+ } else if ( obj && typeof obj === 'object' ) {
1933+ if ( seen . has ( obj ) ) return ;
1934+ seen . add ( obj ) ;
1935+
1936+ let props ;
1937+ try {
1938+ props = ObjectGetOwnPropertyNames ( obj ) ;
1939+ } catch {
1940+ return ;
1941+ }
1942+ for ( const key of props ) {
1943+ try {
1944+ reclusiveCatchPromise ( obj [ key ] , seen ) ;
1945+ } catch {
1946+ continue ;
1947+ }
1948+ }
1949+ }
1950+ }
1951+
19141952REPLServer . prototype . completeOnEditorMode = ( callback ) => ( err , results ) => {
19151953 if ( err ) return callback ( err ) ;
19161954
0 commit comments