-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
repl: tab auto complete big arrays #22408
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
Due to a new API it's possible to skip the indices. That allows to use auto completion with big (typed) arrays. Fixes: #21446
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,6 +11,7 @@ const { | |
| isSet | ||
| } = internalBinding('types'); | ||
| const { getOwnNonIndexProperties } = process.binding('util'); | ||
| const { kPropertyFilter: { ONLY_ENUMERABLE } } = require('internal/util'); | ||
|
|
||
| const ReflectApply = Reflect.apply; | ||
|
|
||
|
|
@@ -118,8 +119,9 @@ function strictDeepEqual(val1, val2, memos) { | |
| if (val1.length !== val2.length) { | ||
| return false; | ||
| } | ||
| const keys1 = getOwnNonIndexProperties(val1); | ||
| if (keys1.length !== getOwnNonIndexProperties(val2).length) { | ||
| const keys1 = getOwnNonIndexProperties(val1, ONLY_ENUMERABLE); | ||
| const keys2 = getOwnNonIndexProperties(val2, ONLY_ENUMERABLE); | ||
| if (keys1.length !== keys2.length) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unrelated optimization idea: would it make sense to return only the length from V8 rather than the properties themselves in the case of keys2?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I already spoke with @nodejs/v8 to implement a API that does exactly that. Until that exists, I would rather keep it as is.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The reason for needing
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I already spoke to @littledan and I am writing the proposal at the moment. It's almost done. |
||
| return false; | ||
| } | ||
| return keyCheck(val1, val2, kStrict, memos, kIsArray, keys1); | ||
|
|
@@ -150,8 +152,9 @@ function strictDeepEqual(val1, val2, memos) { | |
| // Buffer.compare returns true, so val1.length === val2.length. If they both | ||
| // only contain numeric keys, we don't need to exam further than checking | ||
| // the symbols. | ||
| const keys1 = getOwnNonIndexProperties(val1); | ||
| if (keys1.length !== getOwnNonIndexProperties(val2).length) { | ||
| const keys1 = getOwnNonIndexProperties(val1, ONLY_ENUMERABLE); | ||
| const keys2 = getOwnNonIndexProperties(val2, ONLY_ENUMERABLE); | ||
| if (keys1.length !== keys2.length) { | ||
| return false; | ||
| } | ||
| return keyCheck(val1, val2, kStrict, memos, kNoIterator, keys1); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,17 +21,20 @@ static void GetOwnNonIndexProperties( | |
| Environment* env = Environment::GetCurrent(args); | ||
| Local<Context> context = env->context(); | ||
|
|
||
| if (!args[0]->IsObject()) | ||
| if (!args[0]->IsObject() || !args[1]->IsUint32()) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wouldn't it make sense for this to be a (Not critical for this PR) |
||
| return; | ||
|
|
||
| v8::Local<v8::Object> object = args[0].As<v8::Object>(); | ||
| Local<Object> object = args[0].As<Object>(); | ||
|
|
||
| Local<Array> properties; | ||
|
|
||
| // Return only non-enumerable properties by default. | ||
| v8::Local<v8::Array> properties; | ||
| v8::PropertyFilter filter = | ||
| static_cast<v8::PropertyFilter>( | ||
| args[1]->Uint32Value(env->context()).FromJust()); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since you already know at this point that |
||
|
|
||
| if (!object->GetPropertyNames( | ||
| context, v8::KeyCollectionMode::kOwnOnly, | ||
| v8::ONLY_ENUMERABLE, | ||
| filter, | ||
| v8::IndexFilter::kSkipIndices) | ||
| .ToLocal(&properties)) { | ||
| return; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -393,12 +393,6 @@ testMe.complete('obj.', common.mustCall((error, data) => { | |
| assert(data[0].includes('obj.key')); | ||
| })); | ||
|
|
||
| // tab completion for large buffer | ||
| 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, | ||
|
|
@@ -428,11 +422,7 @@ const warningRegEx = new RegExp( | |
| putIn.run([`var ele = new ${type.name}(1e6 + 1); ele.biu = 1;`]); | ||
| } | ||
|
|
||
| common.hijackStderr(common.mustCall((err) => { | ||
| process.nextTick(() => { | ||
| assert.ok(warningRegEx.test(err)); | ||
| }); | ||
| })); | ||
| common.hijackStderr(common.mustNotCall()); | ||
| testMe.complete('ele.', common.mustCall((err, data) => { | ||
| common.restoreStderr(); | ||
| assert.ifError(err); | ||
|
|
@@ -443,13 +433,12 @@ const warningRegEx = new RegExp( | |
| Buffer.alloc(0) : | ||
| new type(0)); | ||
|
|
||
| assert.strictEqual(data[0].includes('ele.biu'), true); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be great to have tests that specify the behaviour for long arrays better.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test is specifically for long arrays. Since this value shows up, we can be certain that it works. I would not know what to improve. Do you have a suggestion? |
||
|
|
||
| data[0].forEach((key) => { | ||
| if (!key) return; | ||
| if (!key || key === 'ele.biu') return; | ||
| assert.notStrictEqual(ele[key.substr(4)], undefined); | ||
| }); | ||
|
|
||
| // no `biu` | ||
| assert.strictEqual(data.includes('ele.biu'), false); | ||
| })); | ||
| }); | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it make sense to copy the whole enum as it is in V8 ( https://github.com/v8/v8/blob/master/src/property-details.h#L36-L45 ) for consistency and keeping a reference to the V8 source here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So far, we usually go all the way here and provide the real V8 constants as exports from the binding, e.g.
node/src/pipe_wrap.cc
Lines 105 to 114 in 9bcb744
I’d encourage you to keep up with that pattern to prevent unexpected breakage from changes to the V8 definition, which is the source-of-truth for these values, even if it seems like a bit of extra work at this point (or leave to TODO comment for me, I’m happy to do the work myself if you prefer)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot for the comments. I definitely appreciate it as I try to teach myself more and more about C++ and the V8 side. So please always mention these things.