Skip to content

Commit 053368c

Browse files
cola119targos
authored andcommitted
util: avoid inline access to Symbol.iterator
PR-URL: #43683 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Darshan Sen <[email protected]>
1 parent 025248b commit 053368c

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

lib/internal/util/inspect.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -859,7 +859,7 @@ function formatRaw(ctx, value, recurseTimes, typedArray) {
859859
// Iterators and the rest are split to reduce checks.
860860
// We have to check all values in case the constructor is set to null.
861861
// Otherwise it would not possible to identify all types properly.
862-
if (value[SymbolIterator] || constructor === null) {
862+
if (SymbolIterator in value || constructor === null) {
863863
noIterator = false;
864864
if (ArrayIsArray(value)) {
865865
// Only set the constructor for non ordinary ("Array [...]") arrays.

test/parallel/test-util-inspect.js

+9
Original file line numberDiff line numberDiff line change
@@ -3240,3 +3240,12 @@ assert.strictEqual(
32403240
'-123_456_789.123_456_78'
32413241
);
32423242
}
3243+
3244+
// Regression test for https://github.com/nodejs/node/issues/41244
3245+
{
3246+
assert.strictEqual(util.inspect({
3247+
get [Symbol.iterator]() {
3248+
throw new Error();
3249+
}
3250+
}), '{ [Symbol(Symbol.iterator)]: [Getter] }');
3251+
}

0 commit comments

Comments
 (0)