From 6f5ced67a8bbf8e02bc183a19bd76d6ff3727bfd Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Sun, 8 Dec 2019 21:38:25 +0100 Subject: [PATCH] src: accept single argument in getProxyDetails MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This makes sure this function stays backwards compatible in case it's accessed through the binding directly. Refs: https://github.com/nodejs/node/pull/29947#issuecomment-562987888 Backport-PR-URL: https://github.com/nodejs/node/pull/31431 PR-URL: https://github.com/nodejs/node/pull/30858 Refs: https://github.com/nodejs/node/pull/30767 Reviewed-By: Richard Lau Reviewed-By: Rich Trott Reviewed-By: David Carlier Reviewed-By: Yongsheng Zhang Reviewed-By: Michaƫl Zasso Reviewed-By: Ben Noordhuis Reviewed-By: Anna Henningsen --- src/node_util.cc | 7 ++++--- test/parallel/test-util-inspect-proxy.js | 4 ++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/node_util.cc b/src/node_util.cc index b9553eaaa6763d..e0ef7d421ff24a 100644 --- a/src/node_util.cc +++ b/src/node_util.cc @@ -91,11 +91,12 @@ static void GetProxyDetails(const FunctionCallbackInfo& args) { if (!args[0]->IsProxy()) return; - CHECK(args[1]->IsBoolean()); - Local proxy = args[0].As(); - if (args[1]->IsTrue()) { + // TODO(BridgeAR): Remove the length check as soon as we prohibit access to + // the util binding layer. It's accessed in the wild and `esm` would break in + // case the check is removed. + if (args.Length() == 1 || args[1]->IsTrue()) { Local ret[] = { proxy->GetTarget(), proxy->GetHandler() diff --git a/test/parallel/test-util-inspect-proxy.js b/test/parallel/test-util-inspect-proxy.js index 5789a6ffbcf6c5..f87ebecb8e7e7c 100644 --- a/test/parallel/test-util-inspect-proxy.js +++ b/test/parallel/test-util-inspect-proxy.js @@ -50,6 +50,10 @@ let details = processUtil.getProxyDetails(proxyObj, true); assert.strictEqual(target, details[0]); assert.strictEqual(handler, details[1]); +details = processUtil.getProxyDetails(proxyObj); +assert.strictEqual(target, details[0]); +assert.strictEqual(handler, details[1]); + details = processUtil.getProxyDetails(proxyObj, false); assert.strictEqual(target, details);