worker: display MessagePort status in util.inspect()
PR-URL: https://github.com/nodejs/node/pull/22658 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Denys Otrishko <shishugi@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
This commit is contained in:
parent
e007166009
commit
caf8e7a49d
@ -125,6 +125,27 @@ MessagePort.prototype.close = function(cb) {
|
||||
const drainMessagePort = MessagePort.prototype.drain;
|
||||
delete MessagePort.prototype.drain;
|
||||
|
||||
Object.defineProperty(MessagePort.prototype, util.inspect.custom, {
|
||||
enumerable: false,
|
||||
writable: false,
|
||||
value: function inspect() { // eslint-disable-line func-name-matching
|
||||
let ref;
|
||||
try {
|
||||
// This may throw when `this` does not refer to a native object,
|
||||
// e.g. when accessing the prototype directly.
|
||||
ref = this.hasRef();
|
||||
} catch { return this; }
|
||||
return Object.assign(Object.create(MessagePort.prototype),
|
||||
ref === undefined ? {
|
||||
active: false,
|
||||
} : {
|
||||
active: true,
|
||||
refed: ref
|
||||
},
|
||||
this);
|
||||
}
|
||||
});
|
||||
|
||||
function setupPortReferencing(port, eventEmitter, eventName) {
|
||||
// Keep track of whether there are any workerMessage listeners:
|
||||
// If there are some, ref() the channel so it keeps the event loop alive.
|
||||
|
Loading…
x
Reference in New Issue
Block a user