GeezerVison is showing github.com — repl: tab auto complete big arrays · nodejs/node@0b340ab
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: lib/internal/util.js -1Lines changed: 0 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -364,7 +364,6 @@ function isInsideNodeModules() { | 364 | 364 | return false; | 365 | 365 | } | 366 | 366 |
| 367 | | - | 368 | 367 | module.exports = { | 369 | 368 | assertCrypto, | 370 | 369 | cachedResult, | |
Collapse file Copy file name to clipboardExpand all lines: lib/internal/util/comparisons.js +12-5Lines changed: 12 additions & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -4,7 +4,12 @@ const { compare } = process.binding('buffer'); | 4 | 4 | const { isArrayBufferView } = require('internal/util/types'); | 5 | 5 | const { internalBinding } = require('internal/bootstrap/loaders'); | 6 | 6 | const { isDate, isMap, isRegExp, isSet } = internalBinding('types'); | 7 | | -const { getOwnNonIndexProperties } = process.binding('util'); | | 7 | +const { | | 8 | + getOwnNonIndexProperties, | | 9 | + propertyFilter: { | | 10 | + ONLY_ENUMERABLE | | 11 | + } | | 12 | +} = process.binding('util'); | 8 | 13 |
| 9 | 14 | const ReflectApply = Reflect.apply; | 10 | 15 |
| @@ -107,8 +112,9 @@ function strictDeepEqual(val1, val2, memos) { | 107 | 112 | if (val1.length !== val2.length) { | 108 | 113 | return false; | 109 | 114 | } | 110 | | - const keys1 = getOwnNonIndexProperties(val1); | 111 | | - if (keys1.length !== getOwnNonIndexProperties(val2).length) { | | 115 | + const keys1 = getOwnNonIndexProperties(val1, ONLY_ENUMERABLE); | | 116 | + const keys2 = getOwnNonIndexProperties(val2, ONLY_ENUMERABLE); | | 117 | + if (keys1.length !== keys2.length) { | 112 | 118 | return false; | 113 | 119 | } | 114 | 120 | return keyCheck(val1, val2, kStrict, memos, kIsArray, keys1); | @@ -139,8 +145,9 @@ function strictDeepEqual(val1, val2, memos) { | 139 | 145 | // Buffer.compare returns true, so val1.length === val2.length. If they both | 140 | 146 | // only contain numeric keys, we don't need to exam further than checking | 141 | 147 | // the symbols. | 142 | | - const keys1 = getOwnNonIndexProperties(val1); | 143 | | - if (keys1.length !== getOwnNonIndexProperties(val2).length) { | | 148 | + const keys1 = getOwnNonIndexProperties(val1, ONLY_ENUMERABLE); | | 149 | + const keys2 = getOwnNonIndexProperties(val2, ONLY_ENUMERABLE); | | 150 | + if (keys1.length !== keys2.length) { | 144 | 151 | return false; | 145 | 152 | } | 146 | 153 | return keyCheck(val1, val2, kStrict, memos, kNoIterator, keys1); | |
Collapse file Copy file name to clipboardExpand all lines: lib/repl.js +9-27Lines changed: 9 additions & 27 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -52,7 +52,6 @@ const { | 52 | 52 | isIdentifierChar | 53 | 53 | } = require('internal/deps/acorn/dist/acorn'); | 54 | 54 | const internalUtil = require('internal/util'); | 55 | | -const { isTypedArray } = require('internal/util/types'); | 56 | 55 | const util = require('util'); | 57 | 56 | const utilBinding = process.binding('util'); | 58 | 57 | const { inherits } = util; | @@ -74,6 +73,13 @@ const { | 74 | 73 | const { sendInspectorCommand } = require('internal/util/inspector'); | 75 | 74 | const { experimentalREPLAwait } = process.binding('config'); | 76 | 75 | const { isRecoverableError } = require('internal/repl/recoverable'); | | 76 | +const { | | 77 | + getOwnNonIndexProperties, | | 78 | + propertyFilter: { | | 79 | + ALL_PROPERTIES, | | 80 | + SKIP_SYMBOLS | | 81 | + } | | 82 | +} = process.binding('util'); | 77 | 83 |
| 78 | 84 | // Lazy-loaded. | 79 | 85 | let processTopLevelAwait; | @@ -927,34 +933,10 @@ function isIdentifier(str) { | 927 | 933 | return true; | 928 | 934 | } | 929 | 935 |
| 930 | | -const ARRAY_LENGTH_THRESHOLD = 1e6; | 931 | | - | 932 | | -function mayBeLargeObject(obj) { | 933 | | - if (Array.isArray(obj)) { | 934 | | - return obj.length > ARRAY_LENGTH_THRESHOLD ? ['length'] : null; | 935 | | - } else if (isTypedArray(obj)) { | 936 | | - return obj.length > ARRAY_LENGTH_THRESHOLD ? [] : null; | 937 | | - } | 938 | | - | 939 | | - return null; | 940 | | -} | 941 | | - | 942 | 936 | function filteredOwnPropertyNames(obj) { | 943 | 937 | if (!obj) return []; | 944 | | - const fakeProperties = mayBeLargeObject(obj); | 945 | | - if (fakeProperties !== null) { | 946 | | - this.outputStream.write('\r\n'); | 947 | | - process.emitWarning( | 948 | | - 'The current array, Buffer or TypedArray has too many entries. ' + | 949 | | - 'Certain properties may be missing from completion output.', | 950 | | - 'REPLWarning', | 951 | | - undefined, | 952 | | - undefined, | 953 | | - true); | 954 | | - | 955 | | - return fakeProperties; | 956 | | - } | 957 | | - return Object.getOwnPropertyNames(obj).filter(isIdentifier); | | 938 | + const filter = ALL_PROPERTIES | SKIP_SYMBOLS; | | 939 | + return getOwnNonIndexProperties(obj, filter).filter(isIdentifier); | 958 | 940 | } | 959 | 941 |
| 960 | 942 | function getGlobalLexicalScopeNames(contextId) { | |
Collapse file Copy file name to clipboardExpand all lines: src/node_util.cc +26-6Lines changed: 26 additions & 6 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 4 | 4 | namespace node { | 5 | 5 | namespace util { | 6 | 6 |
| | 7 | +using v8::ALL_PROPERTIES; | 7 | 8 | using v8::Array; | 8 | 9 | using v8::Context; | 9 | 10 | using v8::FunctionCallbackInfo; | 10 | 11 | using v8::Integer; | 11 | 12 | using v8::Local; | 12 | 13 | using v8::Object; | | 14 | +using v8::ONLY_CONFIGURABLE; | | 15 | +using v8::ONLY_ENUMERABLE; | | 16 | +using v8::ONLY_WRITABLE; | 13 | 17 | using v8::Private; | 14 | 18 | using v8::Promise; | 15 | 19 | using v8::Proxy; | | 20 | +using v8::SKIP_STRINGS; | | 21 | +using v8::SKIP_SYMBOLS; | 16 | 22 | using v8::String; | | 23 | +using v8::Uint32; | 17 | 24 | using v8::Value; | 18 | 25 |
| 19 | 26 | static void GetOwnNonIndexProperties( | 20 | 27 | const FunctionCallbackInfo<Value>& args) { | 21 | 28 | Environment* env = Environment::GetCurrent(args); | 22 | 29 | Local<Context> context = env->context(); | 23 | 30 |
| 24 | | - if (!args[0]->IsObject()) | 25 | | - return; | | 31 | + CHECK(args[0]->IsObject()); | | 32 | + CHECK(args[1]->IsUint32()); | | 33 | + | | 34 | + Local<Object> object = args[0].As<Object>(); | 26 | 35 |
| 27 | | - v8::Local<v8::Object> object = args[0].As<v8::Object>(); | | 36 | + Local<Array> properties; | 28 | 37 |
| 29 | | - // Return only non-enumerable properties by default. | 30 | | - v8::Local<v8::Array> properties; | | 38 | + v8::PropertyFilter filter = | | 39 | + static_cast<v8::PropertyFilter>(args[1].As<Uint32>()->Value()); | 31 | 40 |
| 32 | 41 | if (!object->GetPropertyNames( | 33 | 42 | context, v8::KeyCollectionMode::kOwnOnly, | 34 | | - v8::ONLY_ENUMERABLE, | | 43 | + filter, | 35 | 44 | v8::IndexFilter::kSkipIndices) | 36 | 45 | .ToLocal(&properties)) { | 37 | 46 | return; | @@ -209,6 +218,17 @@ void Initialize(Local<Object> target, | 209 | 218 | WatchdogHasPendingSigint); | 210 | 219 |
| 211 | 220 | env->SetMethod(target, "safeGetenv", SafeGetenv); | | 221 | + | | 222 | + Local<Object> constants = Object::New(env->isolate()); | | 223 | + NODE_DEFINE_CONSTANT(constants, ALL_PROPERTIES); | | 224 | + NODE_DEFINE_CONSTANT(constants, ONLY_WRITABLE); | | 225 | + NODE_DEFINE_CONSTANT(constants, ONLY_ENUMERABLE); | | 226 | + NODE_DEFINE_CONSTANT(constants, ONLY_CONFIGURABLE); | | 227 | + NODE_DEFINE_CONSTANT(constants, SKIP_STRINGS); | | 228 | + NODE_DEFINE_CONSTANT(constants, SKIP_SYMBOLS); | | 229 | + target->Set(context, | | 230 | + FIXED_ONE_BYTE_STRING(env->isolate(), "propertyFilter"), | | 231 | + constants).FromJust(); | 212 | 232 | } | 213 | 233 |
| 214 | 234 | } // namespace util | |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-repl-tab-complete.js +4-15Lines changed: 4 additions & 15 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -393,12 +393,6 @@ testMe.complete('obj.', common.mustCall((error, data) => { | 393 | 393 | assert(data[0].includes('obj.key')); | 394 | 394 | })); | 395 | 395 |
| 396 | | -// tab completion for large buffer | 397 | | -const warningRegEx = new RegExp( | 398 | | - '\\(node:\\d+\\) REPLWarning: The current array, Buffer or TypedArray has ' + | 399 | | - 'too many entries\\. Certain properties may be missing from completion ' + | 400 | | - 'output\\.'); | 401 | | - | 402 | 396 | [ | 403 | 397 | Array, | 404 | 398 | Buffer, | @@ -428,11 +422,7 @@ const warningRegEx = new RegExp( | 428 | 422 | putIn.run([`var ele = new ${type.name}(1e6 + 1); ele.biu = 1;`]); | 429 | 423 | } | 430 | 424 |
| 431 | | - common.hijackStderr(common.mustCall((err) => { | 432 | | - process.nextTick(() => { | 433 | | - assert.ok(warningRegEx.test(err)); | 434 | | - }); | 435 | | - })); | | 425 | + common.hijackStderr(common.mustNotCall()); | 436 | 426 | testMe.complete('ele.', common.mustCall((err, data) => { | 437 | 427 | common.restoreStderr(); | 438 | 428 | assert.ifError(err); | @@ -443,13 +433,12 @@ const warningRegEx = new RegExp( | 443 | 433 | Buffer.alloc(0) : | 444 | 434 | new type(0)); | 445 | 435 |
| | 436 | + assert.strictEqual(data[0].includes('ele.biu'), true); | | 437 | + | 446 | 438 | data[0].forEach((key) => { | 447 | | - if (!key) return; | | 439 | + if (!key || key === 'ele.biu') return; | 448 | 440 | assert.notStrictEqual(ele[key.substr(4)], undefined); | 449 | 441 | }); | 450 | | - | 451 | | - // no `biu` | 452 | | - assert.strictEqual(data.includes('ele.biu'), false); | 453 | 442 | })); | 454 | 443 | }); | 455 | 444 |
| |
|