From 60a697dd5cf630e1f93c45672fdf06340d97110f 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 948e2f354ac..6a5d7b15cd2 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 8092c658966..c7cb51b221c 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] }'); +}