Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

process: make --eval and reading scripts from stdin act the same

Reusing the same logic for both places for the behavior is consistent.

For example:

  $ ./node -p -e "'Hello World'"
  Hello World

  $ echo "'Hello World'" | ./node -p
  Hello World
  • Loading branch information...
commit c5e90a68e764052e74d66aaa82e9341a3a418d6a 1 parent 38153ea
@TooTallNate authored
Showing with 15 additions and 10 deletions.
  1. +15 −10 src/node.js
View
25 src/node.js
@@ -67,15 +67,7 @@
} else if (process._eval != null) {
// User passed '-e' or '--eval' arguments to Node.
- var Module = NativeModule.require('module');
- var path = NativeModule.require('path');
- var cwd = process.cwd();
-
- var module = new Module('eval');
- module.filename = path.join(cwd, 'eval');
- module.paths = Module._nodeModulePaths(cwd);
- var result = module._compile('return eval(process._eval)', 'eval');
- if (process._print_eval) console.log(result);
+ evalScript('eval');
} else if (process.argv[1]) {
// make process.argv[1] into a full path
var path = NativeModule.require('path');
@@ -147,7 +139,8 @@
});
process.stdin.on('end', function() {
- new Module()._compile(code, '[stdin]');
+ process._eval = code;
+ evalScript('[stdin]');
});
}
}
@@ -265,6 +258,18 @@
};
};
+ function evalScript(name) {
+ var Module = NativeModule.require('module');
+ var path = NativeModule.require('path');
+ var cwd = process.cwd();
+
+ var module = new Module(name);
+ module.filename = path.join(cwd, name);
+ module.paths = Module._nodeModulePaths(cwd);
+ var result = module._compile('return eval(process._eval)', name);
+ if (process._print_eval) console.log(result);
+ }
+
function errnoException(errorno, syscall) {
// TODO make this more compatible with ErrnoException from src/node.cc
// Once all of Node is using this function the ErrnoException from
Please sign in to comment.
Something went wrong with that request. Please try again.