@ -7,48 +7,18 @@ const dgram = require('dgram');
const assert = require ( 'assert' ) ;
const util = require ( 'util' ) ;
const debug = util . debuglog ( 'child_process' ) ;
const constants = require ( 'constants' ) ;
const Process = process . binding ( 'process_wrap' ) . Process ;
const WriteWrap = process . binding ( 'stream_wrap' ) . WriteWrap ;
const uv = process . binding ( 'uv' ) ;
var spawn_sync ; // Lazy-loaded process.binding('spawn_sync')
var constants ; // Lazy-loaded process.binding('constants')
const spawn_sync = process . binding ( 'spawn_sync' ) ;
const Pipe = process . binding ( 'pipe_wrap' ) . Pipe ;
const TTY = process . binding ( 'tty_wrap' ) . TTY ;
const TCP = process . binding ( 'tcp_wrap' ) . TCP ;
const UDP = process . binding ( 'udp_wrap' ) . UDP ;
const errnoException = util . _ errnoException ;
var handleWraps = { } ;
function handleWrapGetter ( name , callback ) {
var cons ;
Object . defineProperty ( handleWraps , name , {
get : function ( ) {
if ( cons !== undefined ) return cons ;
return cons = callback ( ) ;
}
} ) ;
}
handleWrapGetter ( 'Pipe' , function ( ) {
return process . binding ( 'pipe_wrap' ) . Pipe ;
} ) ;
handleWrapGetter ( 'TTY' , function ( ) {
return process . binding ( 'tty_wrap' ) . TTY ;
} ) ;
handleWrapGetter ( 'TCP' , function ( ) {
return process . binding ( 'tcp_wrap' ) . TCP ;
} ) ;
handleWrapGetter ( 'UDP' , function ( ) {
return process . binding ( 'udp_wrap' ) . UDP ;
} ) ;
// constructors for lazy loading
function createPipe ( ipc ) {
return new handleWraps . Pipe ( ipc ) ;
}
function createSocket ( pipe , readable ) {
var s = new net . Socket ( { handle : pipe } ) ;
@ -417,12 +387,11 @@ function setupChannel(target, channel) {
message . type = 'net.Socket' ;
} else if ( handle instanceof net . Server ) {
message . type = 'net.Server' ;
} else if ( handle instanceof process . binding ( 'tcp_wrap' ) . TCP ||
handle instanceof process . binding ( 'pipe_wrap' ) . Pipe ) {
} else if ( handle instanceof TCP || handle instanceof Pipe ) {
message . type = 'net.Native' ;
} else if ( handle instanceof dgram . Socket ) {
message . type = 'dgram.Socket' ;
} else if ( handle instanceof process . binding ( 'udp_wrap' ) . UDP ) {
} else if ( handle instanceof UDP ) {
message . type = 'dgram.Native' ;
} else {
throw new TypeError ( "This handle type can't be sent" ) ;
@ -564,7 +533,7 @@ exports.fork = function(modulePath /*, args, options*/) {
exports . _ forkChild = function ( fd ) {
// set process.send()
var p = create Pipe( true ) ;
var p = new Pipe ( true ) ;
p . open ( fd ) ;
p . unref ( ) ;
setupChannel ( process , p ) ;
@ -852,7 +821,7 @@ function _validateStdio(stdio, sync) {
} ;
if ( ! sync )
a . handle = create Pipe( ) ;
a . handle = new Pipe ( ) ;
acc . push ( a ) ;
} else if ( stdio === 'ipc' ) {
@ -865,7 +834,7 @@ function _validateStdio(stdio, sync) {
throw new Error ( 'You cannot use IPC with synchronous forks' ) ;
}
ipc = create Pipe( true ) ;
ipc = new Pipe ( true ) ;
ipcFd = i ;
acc . push ( {
@ -989,10 +958,6 @@ function maybeClose(subprocess) {
function ChildProcess ( ) {
EventEmitter . call ( this ) ;
// Initialize TCPWrap and PipeWrap
process . binding ( 'tcp_wrap' ) ;
process . binding ( 'pipe_wrap' ) ;
var self = this ;
this . _ closesNeeded = 1 ;
@ -1072,10 +1037,10 @@ function flushStdio(subprocess) {
function getHandleWrapType ( stream ) {
if ( stream instanceof handleWraps . Pipe ) return 'pipe' ;
if ( stream instanceof handleWraps . TTY ) return 'tty' ;
if ( stream instanceof handleWraps . TCP ) return 'tcp' ;
if ( stream instanceof handleWraps . UDP ) return 'udp' ;
if ( stream instanceof Pipe ) return 'pipe' ;
if ( stream instanceof TTY ) return 'tty' ;
if ( stream instanceof TCP ) return 'tcp' ;
if ( stream instanceof UDP ) return 'udp' ;
return false ;
}
@ -1177,10 +1142,6 @@ ChildProcess.prototype.spawn = function(options) {
ChildProcess . prototype . kill = function ( sig ) {
var signal ;
if ( ! constants ) {
constants = process . binding ( 'constants' ) ;
}
if ( sig === 0 ) {
signal = 0 ;
} else if ( ! sig ) {
@ -1230,9 +1191,6 @@ function lookupSignal(signal) {
if ( typeof signal === 'number' )
return signal ;
if ( ! constants )
constants = process . binding ( 'constants' ) ;
if ( ! ( signal in constants ) )
throw new Error ( 'Unknown signal: ' + signal ) ;
@ -1280,9 +1238,6 @@ function spawnSync(/*file, args, options*/) {
}
}
if ( ! spawn_sync )
spawn_sync = process . binding ( 'spawn_sync' ) ;
var result = spawn_sync . spawn ( options ) ;
if ( result . output && options . encoding ) {