GeezerVison is showing github.com — worker: display MessagePort status in util.inspect() · nodejs/node@1daa82a
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: lib/internal/worker.js +21Lines changed: 21 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -125,6 +125,27 @@ MessagePort.prototype.close = function(cb) { |
125 | 125 | const drainMessagePort = MessagePort.prototype.drain; |
126 | 126 | delete MessagePort.prototype.drain; |
127 | 127 |
|
| 128 | +Object.defineProperty(MessagePort.prototype, util.inspect.custom, { |
| 129 | + enumerable: false, |
| 130 | + writable: false, |
| 131 | + value: function inspect() { // eslint-disable-line func-name-matching |
| 132 | + let ref; |
| 133 | + try { |
| 134 | + // This may throw when `this` does not refer to a native object, |
| 135 | + // e.g. when accessing the prototype directly. |
| 136 | + ref = this.hasRef(); |
| 137 | + } catch { return this; } |
| 138 | + return Object.assign(Object.create(MessagePort.prototype), |
| 139 | + ref === undefined ? { |
| 140 | + active: false, |
| 141 | + } : { |
| 142 | + active: true, |
| 143 | + refed: ref |
| 144 | + }, |
| 145 | + this); |
| 146 | + } |
| 147 | +}); |
| 148 | + |
128 | 149 | function setupPortReferencing(port, eventEmitter, eventName) { |
129 | 150 | // Keep track of whether there are any workerMessage listeners: |
130 | 151 | // If there are some, ref() the channel so it keeps the event loop alive. |
|