Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Simplify startup function in src/node.js

  • Loading branch information...
commit 59f7232a302687754a3df577a0e3f1b04933445f 1 parent ab190d3
@ry ry authored
Showing with 38 additions and 78 deletions.
  1. +38 −78 src/node.js
View
116 src/node.js
@@ -42,23 +42,48 @@
startup.resolveArgv0();
- if (startup.runThirdPartyMain()) {
- return;
- }
+ // There are various modes that Node can run in. The most common two
+ // are running from a script and running the REPL - but there are a few
+ // others like the debugger or running --eval arguments. Here we decide
+ // which mode we run in.
+
+ if (NativeModule.exists('_third_party_main')) {
+ // To allow people to extend Node in different ways, this hook allows
+ // one to drop a file lib/_third_party_main.js into the build
+ // directory which will be executed instead of Node's normal loading.
+ process.nextTick(function() {
+ NativeModule.require('_third_party_main');
+ });
+
+ } else if (process.argv[1] == 'debug') {
+ // Start the debugger agent
+ var d = NativeModule.require('_debugger');
+ d.start();
+
+ } else if (process.argv[1]) {
+ // make process.argv[1] into a full path
+ if (!(/^http:\/\//).exec(process.argv[1])) {
+ var path = NativeModule.require('path');
+ process.argv[1] = path.resolve(process.argv[1]);
+ }
- if (startup.runDebugger()) {
- return;
- }
+ var Module = NativeModule.require('module');
+ // REMOVEME: nextTick should not be necessary. This hack to get
+ // test/simple/test-exception-handler2.js working.
+ // Main entry point into most programs:
+ process.nextTick(Module.runMain);
- if (startup.runScript()) {
- return;
- }
+ } else if (process._eval) {
+ // User passed '-e' or '--eval' arguments to Node.
+ var Module = NativeModule.require('module');
+ var rv = new Module()._compile('return eval(process._eval)', 'eval');
+ console.log(rv);
- if (startup.runEval()) {
- return;
+ } else {
+ // REPL
+ var Module = NativeModule.require('module');
+ Module.requireRepl().start();
}
-
- startup.runRepl();
}
startup.globalVariables = function() {
@@ -301,71 +326,6 @@
}
};
- startup.runThirdPartyMain = function() {
- // To allow people to extend Node in different ways, this hook allows
- // one to drop a file lib/_third_party_main.js into the build directory
- // which will be executed instead of Node's normal loading.
- if (!NativeModule.exists('_third_party_main')) {
- return;
- }
-
- process.nextTick(function() {
- NativeModule.require('_third_party_main');
- });
- return true;
- };
-
- startup.runDebugger = function() {
- if (!(process.argv[1] == 'debug')) {
- return;
- }
-
- // Start the debugger agent
- var d = NativeModule.require('_debugger');
- d.start();
- return true;
- };
-
- startup.runScript = function() {
- if (!process.argv[1]) {
- return;
- }
-
- // make process.argv[1] into a full path
- if (!(/^http:\/\//).exec(process.argv[1])) {
- var path = NativeModule.require('path');
- process.argv[1] = path.resolve(process.argv[1]);
- }
-
- var Module = NativeModule.require('module');
-
- // REMOVEME: nextTick should not be necessary. This hack to get
- // test/simple/test-exception-handler2.js working.
- process.nextTick(Module.runMain);
-
- return true;
- };
-
- startup.runEval = function() {
- // -e, --eval
- if (!process._eval) {
- return;
- }
-
- var Module = NativeModule.require('module');
-
- var rv = new Module()._compile('return eval(process._eval)', 'eval');
- console.log(rv);
- return true;
- };
-
- startup.runRepl = function() {
- var Module = NativeModule.require('module');
- // REPL
- Module.requireRepl().start();
- };
-
-
// Below you find a minimal module system, which is used to load the node
// core modules found in lib/*.js. All core modules are compiled into the
// node binary, so they can be loaded faster.
Please sign in to comment.
Something went wrong with that request. Please try again.