Skip to content

Commit

Permalink
util: avoid inline access to Symbol.iterator
Browse files Browse the repository at this point in the history
PR-URL: #43683
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
  • Loading branch information
cola119 authored Jul 9, 2022
1 parent d4b1c23 commit 550e814
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/internal/util/inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -859,7 +859,7 @@ function formatRaw(ctx, value, recurseTimes, typedArray) {
// Iterators and the rest are split to reduce checks.
// We have to check all values in case the constructor is set to null.
// Otherwise it would not possible to identify all types properly.
if (value[SymbolIterator] || constructor === null) {
if (SymbolIterator in value || constructor === null) {
noIterator = false;
if (ArrayIsArray(value)) {
// Only set the constructor for non ordinary ("Array [...]") arrays.
Expand Down
9 changes: 9 additions & 0 deletions test/parallel/test-util-inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -3240,3 +3240,12 @@ assert.strictEqual(
'-123_456_789.123_456_78'
);
}

// Regression test for https://github.com/nodejs/node/issues/41244
{
assert.strictEqual(util.inspect({
get [Symbol.iterator]() {
throw new Error();
}
}), '{ [Symbol(Symbol.iterator)]: [Getter] }');
}

0 comments on commit 550e814

Please sign in to comment.