@@ -7,48 +7,18 @@ const dgram = require('dgram');
7
7
const assert = require ( 'assert' ) ;
8
8
const util = require ( 'util' ) ;
9
9
const debug = util . debuglog ( 'child_process' ) ;
10
+ const constants = require ( 'constants' ) ;
10
11
11
12
const Process = process . binding ( 'process_wrap' ) . Process ;
12
13
const WriteWrap = process . binding ( 'stream_wrap' ) . WriteWrap ;
13
14
const 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 ;
17
20
18
21
const 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
- }
52
22
53
23
function createSocket ( pipe , readable ) {
54
24
var s = new net . Socket ( { handle : pipe } ) ;
@@ -417,12 +387,11 @@ function setupChannel(target, channel) {
417
387
message . type = 'net.Socket' ;
418
388
} else if ( handle instanceof net . Server ) {
419
389
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 ) {
422
391
message . type = 'net.Native' ;
423
392
} else if ( handle instanceof dgram . Socket ) {
424
393
message . type = 'dgram.Socket' ;
425
- } else if ( handle instanceof process . binding ( 'udp_wrap' ) . UDP ) {
394
+ } else if ( handle instanceof UDP ) {
426
395
message . type = 'dgram.Native' ;
427
396
} else {
428
397
throw new TypeError ( "This handle type can't be sent" ) ;
@@ -564,7 +533,7 @@ exports.fork = function(modulePath /*, args, options*/) {
564
533
565
534
exports . _forkChild = function ( fd ) {
566
535
// set process.send()
567
- var p = createPipe ( true ) ;
536
+ var p = new Pipe ( true ) ;
568
537
p . open ( fd ) ;
569
538
p . unref ( ) ;
570
539
setupChannel ( process , p ) ;
@@ -852,7 +821,7 @@ function _validateStdio(stdio, sync) {
852
821
} ;
853
822
854
823
if ( ! sync )
855
- a . handle = createPipe ( ) ;
824
+ a . handle = new Pipe ( ) ;
856
825
857
826
acc . push ( a ) ;
858
827
} else if ( stdio === 'ipc' ) {
@@ -865,7 +834,7 @@ function _validateStdio(stdio, sync) {
865
834
throw new Error ( 'You cannot use IPC with synchronous forks' ) ;
866
835
}
867
836
868
- ipc = createPipe ( true ) ;
837
+ ipc = new Pipe ( true ) ;
869
838
ipcFd = i ;
870
839
871
840
acc . push ( {
@@ -989,10 +958,6 @@ function maybeClose(subprocess) {
989
958
function ChildProcess ( ) {
990
959
EventEmitter . call ( this ) ;
991
960
992
- // Initialize TCPWrap and PipeWrap
993
- process . binding ( 'tcp_wrap' ) ;
994
- process . binding ( 'pipe_wrap' ) ;
995
-
996
961
var self = this ;
997
962
998
963
this . _closesNeeded = 1 ;
@@ -1072,10 +1037,10 @@ function flushStdio(subprocess) {
1072
1037
1073
1038
1074
1039
function 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' ;
1079
1044
1080
1045
return false ;
1081
1046
}
@@ -1177,10 +1142,6 @@ ChildProcess.prototype.spawn = function(options) {
1177
1142
ChildProcess . prototype . kill = function ( sig ) {
1178
1143
var signal ;
1179
1144
1180
- if ( ! constants ) {
1181
- constants = process . binding ( 'constants' ) ;
1182
- }
1183
-
1184
1145
if ( sig === 0 ) {
1185
1146
signal = 0 ;
1186
1147
} else if ( ! sig ) {
@@ -1230,9 +1191,6 @@ function lookupSignal(signal) {
1230
1191
if ( typeof signal === 'number' )
1231
1192
return signal ;
1232
1193
1233
- if ( ! constants )
1234
- constants = process . binding ( 'constants' ) ;
1235
-
1236
1194
if ( ! ( signal in constants ) )
1237
1195
throw new Error ( 'Unknown signal: ' + signal ) ;
1238
1196
@@ -1280,9 +1238,6 @@ function spawnSync(/*file, args, options*/) {
1280
1238
}
1281
1239
}
1282
1240
1283
- if ( ! spawn_sync )
1284
- spawn_sync = process . binding ( 'spawn_sync' ) ;
1285
-
1286
1241
var result = spawn_sync . spawn ( options ) ;
1287
1242
1288
1243
if ( result . output && options . encoding ) {
0 commit comments