@ -689,8 +689,33 @@ function intFilter(item) {
return /^[A-Za-z_$]/ . test ( item ) ;
}
const ARRAY_LENGTH_THRESHOLD = 1e6 ;
function mayBeLargeObject ( obj ) {
if ( Array . isArray ( obj ) ) {
return obj . length > ARRAY_LENGTH_THRESHOLD ? [ 'length' ] : null ;
} else if ( utilBinding . isTypedArray ( obj ) ) {
return obj . length > ARRAY_LENGTH_THRESHOLD ? [ ] : null ;
}
return null ;
}
function filteredOwnPropertyNames ( obj ) {
if ( ! obj ) return [ ] ;
const fakeProperties = mayBeLargeObject ( obj ) ;
if ( fakeProperties !== null ) {
this . outputStream . write ( '\r\n' ) ;
process . emitWarning (
'The current array, Buffer or TypedArray has too many entries. ' +
'Certain properties may be missing from completion output.' ,
'REPLWarning' ,
undefined ,
undefined ,
true ) ;
return fakeProperties ;
}
return Object . getOwnPropertyNames ( obj ) . filter ( intFilter ) ;
}
@ -844,9 +869,11 @@ function complete(line, callback) {
if ( this . useGlobal || vm . isContext ( this . context ) ) {
var contextProto = this . context ;
while ( contextProto = Object . getPrototypeOf ( contextProto ) ) {
completionGroups . push ( filteredOwnPropertyNames ( contextProto ) ) ;
completionGroups . push (
filteredOwnPropertyNames . call ( this , contextProto ) ) ;
}
completionGroups . push ( filteredOwnPropertyNames ( this . context ) ) ;
completionGroups . push (
filteredOwnPropertyNames . call ( this , this . context ) ) ;
addStandardGlobals ( completionGroups , filter ) ;
completionGroupsLoaded ( ) ;
} else {
@ -866,13 +893,13 @@ function complete(line, callback) {
}
} else {
const evalExpr = ` try { ${ expr } } catch (e) {} ` ;
this . eval ( evalExpr , this . context , 'repl' , function doEval ( e , obj ) {
this . eval ( evalExpr , this . context , 'repl' , ( e , obj ) => {
// if (e) console.log(e);
if ( obj != null ) {
if ( typeof obj === 'object' || typeof obj === 'function' ) {
try {
memberGroups . push ( filteredOwnPropertyNames ( obj ) ) ;
memberGroups . push ( filteredOwnPropertyNames . call ( this , obj ) ) ;
} catch ( ex ) {
// Probably a Proxy object without `getOwnPropertyNames` trap.
// We simply ignore it here, as we don't want to break the
@ -890,7 +917,7 @@ function complete(line, callback) {
p = obj . constructor ? obj . constructor . prototype : null ;
}
while ( p !== null ) {
memberGroups . push ( filteredOwnPropertyNames ( p ) ) ;
memberGroups . push ( filteredOwnPropertyNames . call ( this , p ) ) ;
p = Object . getPrototypeOf ( p ) ;
// Circular refs possible? Let's guard against that.
sentinel -- ;