@@ -688,8 +688,33 @@ function intFilter(item) {
688688 return / ^ [ A - Z a - z _ $ ] / . test ( item ) ;
689689}
690690
691+ const ARRAY_LENGTH_THRESHOLD = 1e6 ;
692+
693+ function mayBeLargeObject ( obj ) {
694+ if ( Array . isArray ( obj ) ) {
695+ return obj . length > ARRAY_LENGTH_THRESHOLD ? [ 'length' ] : null ;
696+ } else if ( utilBinding . isTypedArray ( obj ) ) {
697+ return obj . length > ARRAY_LENGTH_THRESHOLD ? [ ] : null ;
698+ }
699+
700+ return null ;
701+ }
702+
691703function filteredOwnPropertyNames ( obj ) {
692704 if ( ! obj ) return [ ] ;
705+ const fakeProperties = mayBeLargeObject ( obj ) ;
706+ if ( fakeProperties !== null ) {
707+ this . outputStream . write ( '\r\n' ) ;
708+ process . emitWarning (
709+ 'The current array, Buffer or TypedArray has too many entries. ' +
710+ 'Certain properties may be missing from completion output.' ,
711+ 'REPLWarning' ,
712+ undefined ,
713+ undefined ,
714+ true ) ;
715+
716+ return fakeProperties ;
717+ }
693718 return Object . getOwnPropertyNames ( obj ) . filter ( intFilter ) ;
694719}
695720
@@ -843,9 +868,11 @@ function complete(line, callback) {
843868 if ( this . useGlobal || vm . isContext ( this . context ) ) {
844869 var contextProto = this . context ;
845870 while ( contextProto = Object . getPrototypeOf ( contextProto ) ) {
846- completionGroups . push ( filteredOwnPropertyNames ( contextProto ) ) ;
871+ completionGroups . push (
872+ filteredOwnPropertyNames . call ( this , contextProto ) ) ;
847873 }
848- completionGroups . push ( filteredOwnPropertyNames ( this . context ) ) ;
874+ completionGroups . push (
875+ filteredOwnPropertyNames . call ( this , this . context ) ) ;
849876 addStandardGlobals ( completionGroups , filter ) ;
850877 completionGroupsLoaded ( ) ;
851878 } else {
@@ -865,13 +892,13 @@ function complete(line, callback) {
865892 }
866893 } else {
867894 const evalExpr = `try { ${ expr } } catch (e) {}` ;
868- this . eval ( evalExpr , this . context , 'repl' , function doEval ( e , obj ) {
895+ this . eval ( evalExpr , this . context , 'repl' , ( e , obj ) => {
869896 // if (e) console.log(e);
870897
871898 if ( obj != null ) {
872899 if ( typeof obj === 'object' || typeof obj === 'function' ) {
873900 try {
874- memberGroups . push ( filteredOwnPropertyNames ( obj ) ) ;
901+ memberGroups . push ( filteredOwnPropertyNames . call ( this , obj ) ) ;
875902 } catch ( ex ) {
876903 // Probably a Proxy object without `getOwnPropertyNames` trap.
877904 // We simply ignore it here, as we don't want to break the
@@ -889,7 +916,7 @@ function complete(line, callback) {
889916 p = obj . constructor ? obj . constructor . prototype : null ;
890917 }
891918 while ( p !== null ) {
892- memberGroups . push ( filteredOwnPropertyNames ( p ) ) ;
919+ memberGroups . push ( filteredOwnPropertyNames . call ( this , p ) ) ;
893920 p = Object . getPrototypeOf ( p ) ;
894921 // Circular refs possible? Let's guard against that.
895922 sentinel -- ;
0 commit comments