From 5a77c095a65cb1ef255241c7bb2da5c5ccecc1ca Mon Sep 17 00:00:00 2001 From: cjihrig Date: Thu, 21 Jan 2016 13:07:25 -0500 Subject: [PATCH] process: support symbol events MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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: https://github.com/nodejs/node/pull/4798 Reviewed-By: Sam Roberts Reviewed-By: Michaƫl Zasso Reviewed-By: Wyatt Preul --- src/node.js | 3 ++- test/parallel/test-process-emit.js | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 test/parallel/test-process-emit.js diff --git a/src/node.js b/src/node.js index 67f6cdb5ce..fb39c0e2e7 100644 --- a/src/node.js +++ b/src/node.js @@ -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); } diff --git a/test/parallel/test-process-emit.js b/test/parallel/test-process-emit.js new file mode 100644 index 0000000000..0e6d28b22a --- /dev/null +++ b/test/parallel/test-process-emit.js @@ -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');