Skip to content

Commit

Permalink
process: support symbol events
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
cjihrig authored and rvagg committed Jan 25, 2016
1 parent 66c7454 commit 5a77c09
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -819,7 +819,8 @@
var signalWraps = {};

function isSignal(event) {
return event.slice(0, 3) === 'SIG' &&
return typeof event === 'string' &&
event.slice(0, 3) === 'SIG' &&
startup.lazyConstants().hasOwnProperty(event);
}

Expand Down
20 changes: 20 additions & 0 deletions test/parallel/test-process-emit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
'use strict';
const common = require('../common');
const assert = require('assert');
const sym = Symbol();

process.on('normal', common.mustCall(data => {
assert.strictEqual(data, 'normalData');
}));

process.on(sym, common.mustCall(data => {
assert.strictEqual(data, 'symbolData');
}));

process.on('SIGPIPE', common.mustCall(data => {
assert.strictEqual(data, 'signalData');
}));

process.emit('normal', 'normalData');
process.emit(sym, 'symbolData');
process.emit('SIGPIPE', 'signalData');

0 comments on commit 5a77c09

Please sign in to comment.