mirror of
https://github.com/nodejs/node.git
synced 2026-11-24 21:50:36 -05:00
console: fix console.dir crash on a revoked proxy
Fixes: https://github.com/nodejs/node/issues/43095 Signed-off-by: Daeyeon Jeong daeyeon.dev@gmail.com PR-URL: https://github.com/nodejs/node/pull/43100 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
This commit is contained in:
1 parent
2b8b224077
commit
285ef30877
3 files changed
+39
No files matched your search
@@ -759,6 +759,9 @@ function formatValue(ctx, value, recurseTimes, typedArray) {
|
||||
// any proxy handlers.
|
||||
const proxy = getProxyDetails(value, !!ctx.showProxy);
|
||||
if (proxy !== undefined) {
|
||||
if (proxy === null || proxy[0] === null) {
|
||||
return ctx.stylize('<Revoked Proxy>', 'special');
|
||||
}
|
||||
if (ctx.showProxy) {
|
||||
return formatProxy(ctx, proxy, recurseTimes);
|
||||
}
|
||||
@@ -1967,6 +1970,9 @@ function hasBuiltInToString(value) {
|
||||
const getFullProxy = false;
|
||||
const proxyTarget = getProxyDetails(value, getFullProxy);
|
||||
if (proxyTarget !== undefined) {
|
||||
if (proxyTarget === null) {
|
||||
return true;
|
||||
}
|
||||
value = proxyTarget;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
'use strict';
|
||||
|
||||
require('../common');
|
||||
const { inspect } = require('node:util');
|
||||
|
||||
const r = Proxy.revocable({}, {});
|
||||
r.revoke();
|
||||
|
||||
console.dir(r);
|
||||
console.dir(r.proxy);
|
||||
console.log(r.proxy);
|
||||
console.log(inspect(r.proxy, { showProxy: true }));
|
||||
@@ -57,6 +57,27 @@ assert.strictEqual(handler, details[1]);
|
||||
details = processUtil.getProxyDetails(proxyObj, false);
|
||||
assert.strictEqual(target, details);
|
||||
|
||||
details = processUtil.getProxyDetails({}, true);
|
||||
assert.strictEqual(details, undefined);
|
||||
|
||||
const r = Proxy.revocable({}, {});
|
||||
r.revoke();
|
||||
|
||||
details = processUtil.getProxyDetails(r.proxy, true);
|
||||
assert.strictEqual(details[0], null);
|
||||
assert.strictEqual(details[1], null);
|
||||
|
||||
details = processUtil.getProxyDetails(r.proxy, false);
|
||||
assert.strictEqual(details, null);
|
||||
|
||||
assert.strictEqual(util.inspect(r.proxy), '<Revoked Proxy>');
|
||||
assert.strictEqual(
|
||||
util.inspect(r, { showProxy: true }),
|
||||
'{ proxy: <Revoked Proxy>, revoke: [Function (anonymous)] }',
|
||||
);
|
||||
|
||||
assert.strictEqual(util.format('%s', r.proxy), '<Revoked Proxy>');
|
||||
|
||||
assert.strictEqual(
|
||||
util.inspect(proxyObj, opts),
|
||||
'Proxy [\n' +
|
||||
|
||||
Reference in new issue
Block a user