-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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
util: correctly inspect Map/Set Iterators #3119
Conversation
@@ -486,6 +494,16 @@ function formatMap(ctx, value, recurseTimes, visibleKeys, keys) { | |||
return output; | |||
} | |||
|
|||
function formatIterator(ctx, value, recurseTimes, visibleKeys, keys) { | |||
var output = []; | |||
for (let o of value) { |
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.
This will consume iterator entirely and make it useless
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.
For Maps and Sets?
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.
If you print an iterator, python just prints the type of iterator. May be we should do the same. Otherwise we'll exhaust the iterator as vkurchatkin pointed out.
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.
Ah yea, I see what you mean.
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 I guess that means that we will have to use Debug.MakeMirror and fetch the values?
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.
Yes.
ed5c500
to
04b8de3
Compare
static void IsMapOrSetIterator(const FunctionCallbackInfo<Value>& args) { | ||
CHECK_EQ(1, args.Length()); | ||
args.GetReturnValue().Set(args[0]->IsSetIterator() | ||
|| args[0]->IsMapIterator()); |
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.
Style nit. Or operator should be in the previous line.
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.
@thefourtheye Do we have an eslint rule for that, btw?
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.
make lint
passes with both. Be happy to change if that is the preferred way though
04b8de3
to
7da3f9a
Compare
static void IsMapOrSetIterator(const FunctionCallbackInfo<Value>& args) { | ||
CHECK_EQ(1, args.Length()); | ||
args.GetReturnValue().Set(args[0]->IsSetIterator() || | ||
args[0]->IsMapIterator()); |
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.
Doesn't it fit on one line? It works out to exactly 80 characters, doesn't it?
7da3f9a
to
8204269
Compare
Updated to use |
@@ -486,6 +502,18 @@ function formatMap(ctx, value, recurseTimes, visibleKeys, keys) { | |||
return output; | |||
} | |||
|
|||
function formatCollectionIterator(ctx, value, recurseTimes, visibleKeys, keys) { | |||
Debug = Debug || require('vm').runInDebugContext('Debug'); |
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.
Can you rebase and use ensureDebugIsInitialized()
here?
Updated to utilize |
@@ -3,6 +3,7 @@ | |||
const uv = process.binding('uv'); | |||
const Buffer = require('buffer').Buffer; | |||
const internalUtil = require('internal/util'); | |||
const Util = process.binding('util'); |
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.
Can you name this binding
? That's more in line with other source files.
Mostly LGTM. I think the |
66169e3
to
c7d7eab
Compare
Alright, broke out the |
LGTM |
In the event an Array is created in a Debug context, the constructor will be Array, but !== Array. This adds a check constructor.name === 'Array' to handle edge cases like that. PR-URL: nodejs#3119 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Previously, a MapIterator or SetIterator would not be inspected properly. This change makes it possible to inspect them by creating a Debug Mirror and previewing the iterators to not consume the actual iterator that we are trying to inspect. This change also adds a node_util binding that uses v8's Value::IsSetIterator and Value::IsMapIterator to verify that the values passed in are actual iterators. Fixes: nodejs#3107 PR-URL: nodejs#3119 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
In the event an Array is created in a Debug context, the constructor will be Array, but !== Array. This adds a check constructor.name === 'Array' to handle edge cases like that. PR-URL: #3119 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Previously, a MapIterator or SetIterator would not be inspected properly. This change makes it possible to inspect them by creating a Debug Mirror and previewing the iterators to not consume the actual iterator that we are trying to inspect. This change also adds a node_util binding that uses v8's Value::IsSetIterator and Value::IsMapIterator to verify that the values passed in are actual iterators. Fixes: #3107 PR-URL: #3119 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Currently, inspecting
new Map().keys()
or other iterators will return an empty object.I am opening more for discussion of how we want (if at all) to address not being able to inspect map and set iterators. I first had first attempting using
Debug.MakeMirror
but the performance of doing it this way was about 10x better.Related: #3107