Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
rename symbol
  • Loading branch information
Flarna committed Dec 13, 2019
commit d1562689fe8240d763190ec2a1453c161b6256f7
6 changes: 3 additions & 3 deletions doc/api/events.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,11 @@ myEmitter.emit('error', new Error('whoops!'));
```

It is possible to monitor `'error'` events without consuming the emitted error
by installing a listener using the symbol `errorMonitorSymbol`.
by installing a listener using the symbol `errorMonitor`.

```js
const myEmitter = new MyEmitter();
myEmitter.on(errorMonitorSymbol, (err) => {
myEmitter.on(errorMonitor, (err) => {
MyMonitoringTool.log(err);
});
myEmitter.emit('error', new Error('whoops!'));
Expand Down Expand Up @@ -360,7 +360,7 @@ the event emitter instance, the event’s name and the number of attached
listeners, respectively.
Its `name` property is set to `'MaxListenersExceededWarning'`.

### EventEmitter.errorMonitorSymbol
### EventEmitter.errorMonitor
<!-- YAML
added: REPLACEME
-->
Expand Down
10 changes: 5 additions & 5 deletions lib/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const {
} = require('internal/util/inspect');

const kCapture = Symbol('kCapture');
const kErrorMonitorSymbol = Symbol('events.error-monitor');
const kErrorMonitor = Symbol('events.errorMonitor');

function EventEmitter(opts) {
EventEmitter.init.call(this, opts);
Expand Down Expand Up @@ -83,8 +83,8 @@ ObjectDefineProperty(EventEmitter, 'captureRejections', {
enumerable: true
});

ObjectDefineProperty(EventEmitter, 'errorMonitorSymbol', {
value: kErrorMonitorSymbol,
ObjectDefineProperty(EventEmitter, 'errorMonitor', {
value: kErrorMonitor,
writable: false,
configurable: true,
enumerable: true
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

by adding an enumerable but nonwritable field, this is a potential breaking change - see googleapis/nodejs-spanner#830 (comment).

In the future, we may want to consider enumerable fields as nonmajor only when they're normal data properties.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we change this to a normal property? I used non writable simply because a write to this is usually a bug. I haven't seen any reasonable usecase to change this value but kept it configurable to allow any sort of hack if really needed.

In principle also a normal property added could be seen a breaking if some user added a property with the same name already before in it's code.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Making it non-enumerable, or making it an accessor instead of a data property, would work as well.

Expand Down Expand Up @@ -264,8 +264,8 @@ EventEmitter.prototype.emit = function emit(type, ...args) {

const events = this._events;
if (events !== undefined) {
if (doError && events[kErrorMonitorSymbol] !== undefined)
this.emit(kErrorMonitorSymbol, ...args);
if (doError && events[kErrorMonitor] !== undefined)
this.emit(kErrorMonitor, ...args);
doError = (doError && events.error === undefined);
} else if (!doError)
return false;
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-event-emitter-error-monitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const EE = new EventEmitter();
const theErr = new Error('MyError');

EE.on(
EventEmitter.errorMonitorSymbol,
EventEmitter.errorMonitor,
common.mustCall((e) => assert.strictEqual(e, theErr), 3)
);

Expand Down