@@ -689,8 +689,33 @@ function intFilter(item) {
689
689
return / ^ [ A - Z a - z _ $ ] / . test ( item ) ;
690
690
}
691
691
692
+ const ARRAY_LENGTH_THRESHOLD = 1e6 ;
693
+
694
+ function mayBeLargeObject ( obj ) {
695
+ if ( Array . isArray ( obj ) ) {
696
+ return obj . length > ARRAY_LENGTH_THRESHOLD ? [ 'length' ] : null ;
697
+ } else if ( utilBinding . isTypedArray ( obj ) ) {
698
+ return obj . length > ARRAY_LENGTH_THRESHOLD ? [ ] : null ;
699
+ }
700
+
701
+ return null ;
702
+ }
703
+
692
704
function filteredOwnPropertyNames ( obj ) {
693
705
if ( ! obj ) return [ ] ;
706
+ const fakeProperties = mayBeLargeObject ( obj ) ;
707
+ if ( fakeProperties !== null ) {
708
+ this . outputStream . write ( '\r\n' ) ;
709
+ process . emitWarning (
710
+ 'The current array, Buffer or TypedArray has too many entries. ' +
711
+ 'Certain properties may be missing from completion output.' ,
712
+ 'REPLWarning' ,
713
+ undefined ,
714
+ undefined ,
715
+ true ) ;
716
+
717
+ return fakeProperties ;
718
+ }
694
719
return Object . getOwnPropertyNames ( obj ) . filter ( intFilter ) ;
695
720
}
696
721
@@ -844,9 +869,11 @@ function complete(line, callback) {
844
869
if ( this . useGlobal || vm . isContext ( this . context ) ) {
845
870
var contextProto = this . context ;
846
871
while ( contextProto = Object . getPrototypeOf ( contextProto ) ) {
847
- completionGroups . push ( filteredOwnPropertyNames ( contextProto ) ) ;
872
+ completionGroups . push (
873
+ filteredOwnPropertyNames . call ( this , contextProto ) ) ;
848
874
}
849
- completionGroups . push ( filteredOwnPropertyNames ( this . context ) ) ;
875
+ completionGroups . push (
876
+ filteredOwnPropertyNames . call ( this , this . context ) ) ;
850
877
addStandardGlobals ( completionGroups , filter ) ;
851
878
completionGroupsLoaded ( ) ;
852
879
} else {
@@ -866,13 +893,13 @@ function complete(line, callback) {
866
893
}
867
894
} else {
868
895
const evalExpr = `try { ${ expr } } catch (e) {}` ;
869
- this . eval ( evalExpr , this . context , 'repl' , function doEval ( e , obj ) {
896
+ this . eval ( evalExpr , this . context , 'repl' , ( e , obj ) => {
870
897
// if (e) console.log(e);
871
898
872
899
if ( obj != null ) {
873
900
if ( typeof obj === 'object' || typeof obj === 'function' ) {
874
901
try {
875
- memberGroups . push ( filteredOwnPropertyNames ( obj ) ) ;
902
+ memberGroups . push ( filteredOwnPropertyNames . call ( this , obj ) ) ;
876
903
} catch ( ex ) {
877
904
// Probably a Proxy object without `getOwnPropertyNames` trap.
878
905
// We simply ignore it here, as we don't want to break the
@@ -890,7 +917,7 @@ function complete(line, callback) {
890
917
p = obj . constructor ? obj . constructor . prototype : null ;
891
918
}
892
919
while ( p !== null ) {
893
- memberGroups . push ( filteredOwnPropertyNames ( p ) ) ;
920
+ memberGroups . push ( filteredOwnPropertyNames . call ( this , p ) ) ;
894
921
p = Object . getPrototypeOf ( p ) ;
895
922
// Circular refs possible? Let's guard against that.
896
923
sentinel -- ;
0 commit comments