mirror of
https://github.com/nodejs/node.git
synced 2026-11-27 17:52:27 -05:00
util: correctly inspect Map/Set Iterators
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: https://github.com/nodejs/node/issues/3107 PR-URL: https://github.com/nodejs/node/pull/3119 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
This commit is contained in:
1 parent
b5c51fdba0
commit
8dfdee3733
4 files changed
+89
-5
No files matched your search
@@ -287,6 +287,26 @@ global.Promise = function() { this.bar = 42; };
|
||||
assert.equal(util.inspect(new Promise()), '{ bar: 42 }');
|
||||
global.Promise = oldPromise;
|
||||
|
||||
// Map/Set Iterators
|
||||
var m = new Map([['foo', 'bar']]);
|
||||
assert.strictEqual(util.inspect(m.keys()), 'MapIterator { \'foo\' }');
|
||||
assert.strictEqual(util.inspect(m.values()), 'MapIterator { \'bar\' }');
|
||||
assert.strictEqual(util.inspect(m.entries()),
|
||||
'MapIterator { [ \'foo\', \'bar\' ] }');
|
||||
// make sure the iterator doesn't get consumed
|
||||
var keys = m.keys();
|
||||
assert.strictEqual(util.inspect(keys), 'MapIterator { \'foo\' }');
|
||||
assert.strictEqual(util.inspect(keys), 'MapIterator { \'foo\' }');
|
||||
|
||||
var s = new Set([1, 3]);
|
||||
assert.strictEqual(util.inspect(s.keys()), 'SetIterator { 1, 3 }');
|
||||
assert.strictEqual(util.inspect(s.values()), 'SetIterator { 1, 3 }');
|
||||
assert.strictEqual(util.inspect(s.entries()),
|
||||
'SetIterator { [ 1, 1 ], [ 3, 3 ] }');
|
||||
// make sure the iterator doesn't get consumed
|
||||
keys = s.keys();
|
||||
assert.strictEqual(util.inspect(keys), 'SetIterator { 1, 3 }');
|
||||
assert.strictEqual(util.inspect(keys), 'SetIterator { 1, 3 }');
|
||||
|
||||
// Test alignment of items in container
|
||||
// Assumes that the first numeric character is the start of an item.
|
||||
|
||||
Reference in new issue
Block a user