diff --git a/lib/repl.js b/lib/repl.js index 309634760aa68b..83d64b0548db15 100644 --- a/lib/repl.js +++ b/lib/repl.js @@ -57,7 +57,6 @@ const Module = require('module'); const domain = require('domain'); const debug = util.debuglog('repl'); const errors = require('internal/errors'); -const Buffer = require('buffer').Buffer; const parentModule = module; const replMap = new WeakMap(); @@ -690,53 +689,15 @@ function intFilter(item) { return /^[A-Za-z_$]/.test(item); } -const defaultProperties = [ - [ Array, Object.getOwnPropertyNames([]).filter(intFilter) ], - [ Buffer, Object.getOwnPropertyNames(Buffer.alloc(0)).filter(intFilter) ], - - [ Uint8Array, - Object.getOwnPropertyNames(new Uint8Array()).filter(intFilter) ], - [ Uint16Array, - Object.getOwnPropertyNames(new Uint16Array()).filter(intFilter) ], - [ Uint32Array, - Object.getOwnPropertyNames(new Uint32Array()).filter(intFilter) ], - [ - Uint8ClampedArray, - Object.getOwnPropertyNames(new Uint8ClampedArray()).filter(intFilter) ], - [ Int8Array, - Object.getOwnPropertyNames(new Int8Array()).filter(intFilter) ], - [ Int16Array, - Object.getOwnPropertyNames(new Int16Array()).filter(intFilter) ], - [ Int32Array, - Object.getOwnPropertyNames(new Int32Array()).filter(intFilter) ], - [ Float32Array, - Object.getOwnPropertyNames(new Float32Array()).filter(intFilter) ], - [ Float64Array, - Object.getOwnPropertyNames(new Float64Array()).filter(intFilter) ] -]; const ARRAY_LENGTH_THRESHOLD = 1e6; function mayBeLargeObject(obj) { - // `Buffer.prototype` passes the `Buffer.isBuffer` and - // `instanceof Uint8Array`. - // - // Refs: https://github.com/nodejs/node/pull/11961 - if (obj === Buffer.prototype) return null; - - for (const type of defaultProperties) { - var typeMatch; - if (type[0] === Array) { - typeMatch = Array.isArray(obj); - } else if (type[0] === Buffer) { - typeMatch = Buffer.isBuffer(obj); - } else { - typeMatch = obj instanceof type[0]; - } - - if (typeMatch) { - return obj.length > ARRAY_LENGTH_THRESHOLD ? type[1] : null; - } + 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; } @@ -746,8 +707,8 @@ function filteredOwnPropertyNames(obj) { if (fakeProperties !== null) { this._writeToOutput('\r\n'); process.emitWarning( - 'Instance is too large so the completion may missing some custom ' + - 'properties.', + 'The current array, Buffer or TypedArray has too many entries. ' + + 'Certain properties may be missing from completion output.', 'REPLWarning', undefined, undefined, diff --git a/test/parallel/test-repl-tab-complete.js b/test/parallel/test-repl-tab-complete.js index 3734f55efc7467..f1bc2d40096f2f 100644 --- a/test/parallel/test-repl-tab-complete.js +++ b/test/parallel/test-repl-tab-complete.js @@ -306,8 +306,11 @@ testMe.complete('.b', common.mustCall((error, data) => { })); // tab completion for large buffer -const warningRegEx = - /\(node:\d+\) REPLWarning: Instance is too large so the completion may missing some custom properties\./; +const warningRegEx = new RegExp( + '\\(node:\\d+\\) REPLWarning: The current array, Buffer or TypedArray has ' + + 'too many entries\\. Certain properties may be missing from completion ' + + 'output\\.'); + [ Array, Buffer, @@ -363,7 +366,7 @@ const warningRegEx = }); // check Buffer.prototype.length not crashing. -// Refs: Refs: https://github.com/nodejs/node/pull/11961 +// Refs: https://github.com/nodejs/node/pull/11961 putIn.run['.clear']; testMe.complete('Buffer.prototype.', common.mustCall());