|
68 | 68 | var d = NativeModule.require('_debug_agent');
|
69 | 69 | d.start();
|
70 | 70 |
|
71 |
| - } else { |
72 |
| - // There is user code to be run |
| 71 | + } else if (process._eval != null) { |
| 72 | + // User passed '-e' or '--eval' arguments to Node. |
| 73 | + evalScript('[eval]'); |
| 74 | + } else if (process.argv[1]) { |
| 75 | + // make process.argv[1] into a full path |
| 76 | + var path = NativeModule.require('path'); |
| 77 | + process.argv[1] = path.resolve(process.argv[1]); |
73 | 78 |
|
74 |
| - // Load any preload modules |
75 |
| - if (process._preload_modules) { |
76 |
| - var Module = NativeModule.require('module'); |
77 |
| - process._preload_modules.forEach(function(module) { |
78 |
| - Module._load(module); |
79 |
| - }); |
| 79 | + // If this is a worker in cluster mode, start up the communication |
| 80 | + // channel. |
| 81 | + if (process.env.NODE_UNIQUE_ID) { |
| 82 | + var cluster = NativeModule.require('cluster'); |
| 83 | + cluster._setupWorker(); |
| 84 | + |
| 85 | + // Make sure it's not accidentally inherited by child processes. |
| 86 | + delete process.env.NODE_UNIQUE_ID; |
80 | 87 | }
|
81 | 88 |
|
82 |
| - if (process._eval != null) { |
83 |
| - // User passed '-e' or '--eval' arguments to Node. |
84 |
| - evalScript('[eval]'); |
85 |
| - } else if (process.argv[1]) { |
86 |
| - // make process.argv[1] into a full path |
87 |
| - var path = NativeModule.require('path'); |
88 |
| - process.argv[1] = path.resolve(process.argv[1]); |
89 |
| - |
90 |
| - // If this is a worker in cluster mode, start up the communication |
91 |
| - // channel. |
92 |
| - if (process.env.NODE_UNIQUE_ID) { |
93 |
| - var cluster = NativeModule.require('cluster'); |
94 |
| - cluster._setupWorker(); |
95 |
| - |
96 |
| - // Make sure it's not accidentally inherited by child processes. |
97 |
| - delete process.env.NODE_UNIQUE_ID; |
98 |
| - } |
| 89 | + var Module = NativeModule.require('module'); |
99 | 90 |
|
100 |
| - var Module = NativeModule.require('module'); |
| 91 | + if (global.v8debug && |
| 92 | + process.execArgv.some(function(arg) { |
| 93 | + return arg.match(/^--debug-brk(=[0-9]*)?$/); |
| 94 | + })) { |
101 | 95 |
|
102 |
| - if (global.v8debug && |
103 |
| - process.execArgv.some(function(arg) { |
104 |
| - return arg.match(/^--debug-brk(=[0-9]*)?$/); |
105 |
| - })) { |
| 96 | + // XXX Fix this terrible hack! |
| 97 | + // |
| 98 | + // Give the client program a few ticks to connect. |
| 99 | + // Otherwise, there's a race condition where `node debug foo.js` |
| 100 | + // will not be able to connect in time to catch the first |
| 101 | + // breakpoint message on line 1. |
| 102 | + // |
| 103 | + // A better fix would be to somehow get a message from the |
| 104 | + // global.v8debug object about a connection, and runMain when |
| 105 | + // that occurs. --isaacs |
106 | 106 |
|
107 |
| - // XXX Fix this terrible hack! |
108 |
| - // |
109 |
| - // Give the client program a few ticks to connect. |
110 |
| - // Otherwise, there's a race condition where `node debug foo.js` |
111 |
| - // will not be able to connect in time to catch the first |
112 |
| - // breakpoint message on line 1. |
113 |
| - // |
114 |
| - // A better fix would be to somehow get a message from the |
115 |
| - // global.v8debug object about a connection, and runMain when |
116 |
| - // that occurs. --isaacs |
| 107 | + var debugTimeout = +process.env.NODE_DEBUG_TIMEOUT || 50; |
| 108 | + setTimeout(Module.runMain, debugTimeout); |
117 | 109 |
|
118 |
| - var debugTimeout = +process.env.NODE_DEBUG_TIMEOUT || 50; |
119 |
| - setTimeout(Module.runMain, debugTimeout); |
| 110 | + } else { |
| 111 | + // Main entry point into most programs: |
| 112 | + Module.runMain(); |
| 113 | + } |
120 | 114 |
|
121 |
| - } else { |
122 |
| - // Main entry point into most programs: |
123 |
| - Module.runMain(); |
| 115 | + } else { |
| 116 | + var Module = NativeModule.require('module'); |
| 117 | + |
| 118 | + // If -i or --interactive were passed, or stdin is a TTY. |
| 119 | + if (process._forceRepl || NativeModule.require('tty').isatty(0)) { |
| 120 | + // REPL |
| 121 | + var opts = { |
| 122 | + useGlobal: true, |
| 123 | + ignoreUndefined: false |
| 124 | + }; |
| 125 | + if (parseInt(process.env['NODE_NO_READLINE'], 10)) { |
| 126 | + opts.terminal = false; |
124 | 127 | }
|
| 128 | + if (parseInt(process.env['NODE_DISABLE_COLORS'], 10)) { |
| 129 | + opts.useColors = false; |
| 130 | + } |
| 131 | + var repl = Module.requireRepl().start(opts); |
| 132 | + repl.on('exit', function() { |
| 133 | + process.exit(); |
| 134 | + }); |
125 | 135 |
|
126 | 136 | } else {
|
127 |
| - var Module = NativeModule.require('module'); |
128 |
| - |
129 |
| - // If -i or --interactive were passed, or stdin is a TTY. |
130 |
| - if (process._forceRepl || NativeModule.require('tty').isatty(0)) { |
131 |
| - // REPL |
132 |
| - var opts = { |
133 |
| - useGlobal: true, |
134 |
| - ignoreUndefined: false |
135 |
| - }; |
136 |
| - if (parseInt(process.env['NODE_NO_READLINE'], 10)) { |
137 |
| - opts.terminal = false; |
138 |
| - } |
139 |
| - if (parseInt(process.env['NODE_DISABLE_COLORS'], 10)) { |
140 |
| - opts.useColors = false; |
141 |
| - } |
142 |
| - var repl = Module.requireRepl().start(opts); |
143 |
| - repl.on('exit', function() { |
144 |
| - process.exit(); |
145 |
| - }); |
146 |
| - |
147 |
| - } else { |
148 |
| - // Read all of stdin - execute it. |
149 |
| - process.stdin.setEncoding('utf8'); |
| 137 | + // Read all of stdin - execute it. |
| 138 | + process.stdin.setEncoding('utf8'); |
150 | 139 |
|
151 |
| - var code = ''; |
152 |
| - process.stdin.on('data', function(d) { |
153 |
| - code += d; |
154 |
| - }); |
| 140 | + var code = ''; |
| 141 | + process.stdin.on('data', function(d) { |
| 142 | + code += d; |
| 143 | + }); |
155 | 144 |
|
156 |
| - process.stdin.on('end', function() { |
157 |
| - process._eval = code; |
158 |
| - evalScript('[stdin]'); |
159 |
| - }); |
160 |
| - } |
| 145 | + process.stdin.on('end', function() { |
| 146 | + process._eval = code; |
| 147 | + evalScript('[stdin]'); |
| 148 | + }); |
161 | 149 | }
|
162 | 150 | }
|
163 | 151 | }
|
|
0 commit comments