mirror of
https://github.com/nodejs/node-v0.x-archive.git
synced 2026-04-28 03:01:10 -04:00
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
This commit is contained in:
25
src/node.js
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
|
||||
|
||||
Reference in New Issue
Block a user