From 550e8149036358713be8d5c8a91f7ad8f01d7f6d Mon Sep 17 00:00:00 2001 From: Kohei Ueno Date: Sat, 9 Jul 2022 20:59:50 +0900 Subject: [PATCH] util: avoid inline access to Symbol.iterator PR-URL: https://github.com/nodejs/node/pull/43683 Reviewed-By: Ben Noordhuis Reviewed-By: Antoine du Hamel Reviewed-By: Ruben Bridgewater Reviewed-By: Darshan Sen --- lib/internal/util/inspect.js | 2 +- test/parallel/test-util-inspect.js | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/internal/util/inspect.js b/lib/internal/util/inspect.js index 25c4874e227dad..ddd08e4f917618 100644 --- a/lib/internal/util/inspect.js +++ b/lib/internal/util/inspect.js @@ -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. diff --git a/test/parallel/test-util-inspect.js b/test/parallel/test-util-inspect.js index 8092c658966493..c7cb51b221c5f7 100644 --- a/test/parallel/test-util-inspect.js +++ b/test/parallel/test-util-inspect.js @@ -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] }'); +}