Skip to content

Commit 5a77c09

Browse files
cjihrigrvagg
authored andcommitted
process: support symbol events
Event emitters support symbols as event names. The process object assumes that the event name is a string, and examines the first three characters to check for signals. This causes an exception if the event name is a symbol. This commit ensures that the event name is a string before trying to slice() it. PR-URL: #4798 Reviewed-By: Sam Roberts <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Wyatt Preul <[email protected]>
1 parent 66c7454 commit 5a77c09

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

src/node.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -819,7 +819,8 @@
819819
var signalWraps = {};
820820

821821
function isSignal(event) {
822-
return event.slice(0, 3) === 'SIG' &&
822+
return typeof event === 'string' &&
823+
event.slice(0, 3) === 'SIG' &&
823824
startup.lazyConstants().hasOwnProperty(event);
824825
}
825826

test/parallel/test-process-emit.js

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
'use strict';
2+
const common = require('../common');
3+
const assert = require('assert');
4+
const sym = Symbol();
5+
6+
process.on('normal', common.mustCall(data => {
7+
assert.strictEqual(data, 'normalData');
8+
}));
9+
10+
process.on(sym, common.mustCall(data => {
11+
assert.strictEqual(data, 'symbolData');
12+
}));
13+
14+
process.on('SIGPIPE', common.mustCall(data => {
15+
assert.strictEqual(data, 'signalData');
16+
}));
17+
18+
process.emit('normal', 'normalData');
19+
process.emit(sym, 'symbolData');
20+
process.emit('SIGPIPE', 'signalData');

0 commit comments

Comments
 (0)