Skip to content
Permalink
Browse files

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 <vieuxtech@gmail.com>
Reviewed-By: Michaël Zasso <mic.besace@gmail.com>
Reviewed-By: Wyatt Preul <wpreul@gmail.com>
  • Loading branch information...
cjihrig authored and MylesBorins committed Jan 21, 2016
1 parent 0887208 commit 7a2e8f435637be1053e80198345d06ddd75cc303
Showing with 22 additions and 1 deletion.
  1. +2 −1 src/node.js
  2. +20 −0 test/parallel/test-process-emit.js
@@ -782,7 +782,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);
}

@@ -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 7a2e8f4

Please sign in to comment.
You can’t perform that action at this time.