Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 10 additions & 18 deletions lib/internal/process.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,24 +178,23 @@ function setupKillAndExit() {


function setupSignalHandlers() {
// Load events module in order to access prototype elements on process like
// process.addListener.
const signalWraps = {};
const signalWraps = Object.create(null);
let Signal;

function isSignal(event) {
return typeof event === 'string' && constants[event] !== undefined;
}

// Detect presence of a listener for the special signal types
process.on('newListener', function(type, listener) {
if (isSignal(type) &&
!signalWraps.hasOwnProperty(type)) {
const Signal = process.binding('signal_wrap').Signal;
process.on('newListener', function(type) {
if (isSignal(type) && signalWraps[type] === undefined) {
if (Signal === undefined)
Signal = process.binding('signal_wrap').Signal;
const wrap = new Signal();

wrap.unref();

wrap.onsignal = function() { process.emit(type, type); };
wrap.onsignal = process.emit.bind(process, type, type);

const signum = constants[type];
const err = wrap.start(signum);
Expand All @@ -208,8 +207,8 @@ function setupSignalHandlers() {
}
});

process.on('removeListener', function(type, listener) {
if (signalWraps.hasOwnProperty(type) && this.listenerCount(type) === 0) {
process.on('removeListener', function(type) {
if (signalWraps[type] !== undefined && this.listenerCount(type) === 0) {
signalWraps[type].close();
delete signalWraps[type];
}
Expand All @@ -227,14 +226,7 @@ function setupChannel() {
// Make sure it's not accidentally inherited by child processes.
delete process.env.NODE_CHANNEL_FD;

const cp = require('child_process');

// Load tcp_wrap to avoid situation where we might immediately receive
// a message.
// FIXME is this really necessary?
process.binding('tcp_wrap');

cp._forkChild(fd);
require('child_process')._forkChild(fd);
assert(process.send);
}
}
Expand Down