@@ -7,48 +7,18 @@ const dgram = require('dgram');
77const assert = require ( 'assert' ) ;
88const util = require ( 'util' ) ;
99const debug = util . debuglog ( 'child_process' ) ;
10+ const constants = require ( 'constants' ) ;
1011
1112const Process = process . binding ( 'process_wrap' ) . Process ;
1213const WriteWrap = process . binding ( 'stream_wrap' ) . WriteWrap ;
1314const uv = process . binding ( 'uv' ) ;
14-
15- var spawn_sync ; // Lazy-loaded process.binding('spawn_sync')
16- var constants ; // Lazy-loaded process.binding('constants')
15+ const spawn_sync = process . binding ( 'spawn_sync' ) ;
16+ const Pipe = process . binding ( 'pipe_wrap' ) . Pipe ;
17+ const TTY = process . binding ( 'tty_wrap' ) . TTY ;
18+ const TCP = process . binding ( 'tcp_wrap' ) . TCP ;
19+ const UDP = process . binding ( 'udp_wrap' ) . UDP ;
1720
1821const errnoException = util . _errnoException ;
19- var handleWraps = { } ;
20-
21- function handleWrapGetter ( name , callback ) {
22- var cons ;
23-
24- Object . defineProperty ( handleWraps , name , {
25- get : function ( ) {
26- if ( cons !== undefined ) return cons ;
27- return cons = callback ( ) ;
28- }
29- } ) ;
30- }
31-
32- handleWrapGetter ( 'Pipe' , function ( ) {
33- return process . binding ( 'pipe_wrap' ) . Pipe ;
34- } ) ;
35-
36- handleWrapGetter ( 'TTY' , function ( ) {
37- return process . binding ( 'tty_wrap' ) . TTY ;
38- } ) ;
39-
40- handleWrapGetter ( 'TCP' , function ( ) {
41- return process . binding ( 'tcp_wrap' ) . TCP ;
42- } ) ;
43-
44- handleWrapGetter ( 'UDP' , function ( ) {
45- return process . binding ( 'udp_wrap' ) . UDP ;
46- } ) ;
47-
48- // constructors for lazy loading
49- function createPipe ( ipc ) {
50- return new handleWraps . Pipe ( ipc ) ;
51- }
5222
5323function createSocket ( pipe , readable ) {
5424 var s = new net . Socket ( { handle : pipe } ) ;
@@ -417,12 +387,11 @@ function setupChannel(target, channel) {
417387 message . type = 'net.Socket' ;
418388 } else if ( handle instanceof net . Server ) {
419389 message . type = 'net.Server' ;
420- } else if ( handle instanceof process . binding ( 'tcp_wrap' ) . TCP ||
421- handle instanceof process . binding ( 'pipe_wrap' ) . Pipe ) {
390+ } else if ( handle instanceof TCP || handle instanceof Pipe ) {
422391 message . type = 'net.Native' ;
423392 } else if ( handle instanceof dgram . Socket ) {
424393 message . type = 'dgram.Socket' ;
425- } else if ( handle instanceof process . binding ( 'udp_wrap' ) . UDP ) {
394+ } else if ( handle instanceof UDP ) {
426395 message . type = 'dgram.Native' ;
427396 } else {
428397 throw new TypeError ( "This handle type can't be sent" ) ;
@@ -564,7 +533,7 @@ exports.fork = function(modulePath /*, args, options*/) {
564533
565534exports . _forkChild = function ( fd ) {
566535 // set process.send()
567- var p = createPipe ( true ) ;
536+ var p = new Pipe ( true ) ;
568537 p . open ( fd ) ;
569538 p . unref ( ) ;
570539 setupChannel ( process , p ) ;
@@ -852,7 +821,7 @@ function _validateStdio(stdio, sync) {
852821 } ;
853822
854823 if ( ! sync )
855- a . handle = createPipe ( ) ;
824+ a . handle = new Pipe ( ) ;
856825
857826 acc . push ( a ) ;
858827 } else if ( stdio === 'ipc' ) {
@@ -865,7 +834,7 @@ function _validateStdio(stdio, sync) {
865834 throw new Error ( 'You cannot use IPC with synchronous forks' ) ;
866835 }
867836
868- ipc = createPipe ( true ) ;
837+ ipc = new Pipe ( true ) ;
869838 ipcFd = i ;
870839
871840 acc . push ( {
@@ -989,10 +958,6 @@ function maybeClose(subprocess) {
989958function ChildProcess ( ) {
990959 EventEmitter . call ( this ) ;
991960
992- // Initialize TCPWrap and PipeWrap
993- process . binding ( 'tcp_wrap' ) ;
994- process . binding ( 'pipe_wrap' ) ;
995-
996961 var self = this ;
997962
998963 this . _closesNeeded = 1 ;
@@ -1072,10 +1037,10 @@ function flushStdio(subprocess) {
10721037
10731038
10741039function getHandleWrapType ( stream ) {
1075- if ( stream instanceof handleWraps . Pipe ) return 'pipe' ;
1076- if ( stream instanceof handleWraps . TTY ) return 'tty' ;
1077- if ( stream instanceof handleWraps . TCP ) return 'tcp' ;
1078- if ( stream instanceof handleWraps . UDP ) return 'udp' ;
1040+ if ( stream instanceof Pipe ) return 'pipe' ;
1041+ if ( stream instanceof TTY ) return 'tty' ;
1042+ if ( stream instanceof TCP ) return 'tcp' ;
1043+ if ( stream instanceof UDP ) return 'udp' ;
10791044
10801045 return false ;
10811046}
@@ -1177,10 +1142,6 @@ ChildProcess.prototype.spawn = function(options) {
11771142ChildProcess . prototype . kill = function ( sig ) {
11781143 var signal ;
11791144
1180- if ( ! constants ) {
1181- constants = process . binding ( 'constants' ) ;
1182- }
1183-
11841145 if ( sig === 0 ) {
11851146 signal = 0 ;
11861147 } else if ( ! sig ) {
@@ -1230,9 +1191,6 @@ function lookupSignal(signal) {
12301191 if ( typeof signal === 'number' )
12311192 return signal ;
12321193
1233- if ( ! constants )
1234- constants = process . binding ( 'constants' ) ;
1235-
12361194 if ( ! ( signal in constants ) )
12371195 throw new Error ( 'Unknown signal: ' + signal ) ;
12381196
@@ -1280,9 +1238,6 @@ function spawnSync(/*file, args, options*/) {
12801238 }
12811239 }
12821240
1283- if ( ! spawn_sync )
1284- spawn_sync = process . binding ( 'spawn_sync' ) ;
1285-
12861241 var result = spawn_sync . spawn ( options ) ;
12871242
12881243 if ( result . output && options . encoding ) {
0 commit comments