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‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -819,7 +819,8 @@
819819
varsignalWraps={};
820820

821821
functionisSignal(event){
822-
returnevent.slice(0,3)==='SIG'&&
822+
returntypeofevent==='string'&&
823+
event.slice(0,3)==='SIG'&&
823824
startup.lazyConstants().hasOwnProperty(event);
824825
}
825826

‎test/parallel/test-process-emit.js‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
'use strict';
2+
constcommon=require('../common');
3+
constassert=require('assert');
4+
constsym=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)