summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/internal/util/inspect.js7
-rw-r--r--test/parallel/test-util-inspect-proxy.js3
2 files changed, 10 insertions, 0 deletions
diff --git a/lib/internal/util/inspect.js b/lib/internal/util/inspect.js
index 4e6f967c6a..a4a9a05ece 100644
--- a/lib/internal/util/inspect.js
+++ b/lib/internal/util/inspect.js
@@ -1648,6 +1648,13 @@ function reduceToSingleString(
}
function hasBuiltInToString(value) {
+ // Prevent triggering proxy traps.
+ const getFullProxy = false;
+ const proxyTarget = getProxyDetails(value, getFullProxy);
+ if (proxyTarget !== undefined) {
+ value = proxyTarget;
+ }
+
// Count objects that have no `toString` function as built-in.
if (typeof value.toString !== 'function') {
return true;
diff --git a/test/parallel/test-util-inspect-proxy.js b/test/parallel/test-util-inspect-proxy.js
index c684026b19..505503d579 100644
--- a/test/parallel/test-util-inspect-proxy.js
+++ b/test/parallel/test-util-inspect-proxy.js
@@ -41,6 +41,9 @@ proxyObj = new Proxy(target, handler);
// Inspecting the proxy should not actually walk it's properties
util.inspect(proxyObj, opts);
+// Make sure inspecting object does not trigger any proxy traps.
+util.format('%s', proxyObj);
+
// getProxyDetails is an internal method, not intended for public use.
// This is here to test that the internals are working correctly.
let details = processUtil.getProxyDetails(proxyObj, true);