@@ -688,8 +688,33 @@ function intFilter(item) {
688
688
return / ^ [ A - Z a - z _ $ ] / . test ( item ) ;
689
689
}
690
690
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
+
691
703
function filteredOwnPropertyNames ( obj ) {
692
704
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
+ }
693
718
return Object . getOwnPropertyNames ( obj ) . filter ( intFilter ) ;
694
719
}
695
720
@@ -843,9 +868,11 @@ function complete(line, callback) {
843
868
if ( this . useGlobal || vm . isContext ( this . context ) ) {
844
869
var contextProto = this . context ;
845
870
while ( contextProto = Object . getPrototypeOf ( contextProto ) ) {
846
- completionGroups . push ( filteredOwnPropertyNames ( contextProto ) ) ;
871
+ completionGroups . push (
872
+ filteredOwnPropertyNames . call ( this , contextProto ) ) ;
847
873
}
848
- completionGroups . push ( filteredOwnPropertyNames ( this . context ) ) ;
874
+ completionGroups . push (
875
+ filteredOwnPropertyNames . call ( this , this . context ) ) ;
849
876
addStandardGlobals ( completionGroups , filter ) ;
850
877
completionGroupsLoaded ( ) ;
851
878
} else {
@@ -865,13 +892,13 @@ function complete(line, callback) {
865
892
}
866
893
} else {
867
894
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 ) => {
869
896
// if (e) console.log(e);
870
897
871
898
if ( obj != null ) {
872
899
if ( typeof obj === 'object' || typeof obj === 'function' ) {
873
900
try {
874
- memberGroups . push ( filteredOwnPropertyNames ( obj ) ) ;
901
+ memberGroups . push ( filteredOwnPropertyNames . call ( this , obj ) ) ;
875
902
} catch ( ex ) {
876
903
// Probably a Proxy object without `getOwnPropertyNames` trap.
877
904
// We simply ignore it here, as we don't want to break the
@@ -889,7 +916,7 @@ function complete(line, callback) {
889
916
p = obj . constructor ? obj . constructor . prototype : null ;
890
917
}
891
918
while ( p !== null ) {
892
- memberGroups . push ( filteredOwnPropertyNames ( p ) ) ;
919
+ memberGroups . push ( filteredOwnPropertyNames . call ( this , p ) ) ;
893
920
p = Object . getPrototypeOf ( p ) ;
894
921
// Circular refs possible? Let's guard against that.
895
922
sentinel -- ;
0 commit comments