Skip to content

Commit

Permalink
update after reviewing again
Browse files Browse the repository at this point in the history
  • Loading branch information
XadillaX committed Jun 21, 2017
1 parent 11db662 commit 573e252
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 49 deletions.
53 changes: 7 additions & 46 deletions lib/repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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;
}

Expand All @@ -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,
Expand Down
9 changes: 6 additions & 3 deletions test/parallel/test-repl-tab-complete.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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());

Expand Down

0 comments on commit 573e252

Please sign in to comment.