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 <vieuxtech@gmail.com>
Reviewed-By: Michaël Zasso <mic.besace@gmail.com>
Reviewed-By: Wyatt Preul <wpreul@gmail.com>
  • Loading branch information
cjihrig committed Jan 21, 2016
1 parent e436272 commit 66cb4bc
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 @@ -821,7 +821,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 66cb4bc

Please sign in to comment.