Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion lib/repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ function REPLServer(prompt, stream, eval_, useGlobal, ignoreUndefined) {
return new REPLServer(prompt, stream, eval_, useGlobal, ignoreUndefined);
}

var options, input, output, dom;
var options, input, output, dom, evalString;
if (prompt !== null && typeof prompt === 'object') {
// an options object was given
options = prompt;
Expand All @@ -82,6 +82,7 @@ function REPLServer(prompt, stream, eval_, useGlobal, ignoreUndefined) {
ignoreUndefined = options.ignoreUndefined;
prompt = options.prompt;
dom = options.domain;
evalString = options.evalString;
} else if (typeof prompt !== 'string') {
throw new Error('An options Object, or a prompt String are required');
} else {
Expand Down Expand Up @@ -325,6 +326,10 @@ function REPLServer(prompt, stream, eval_, useGlobal, ignoreUndefined) {
self.displayPrompt(true);
});

if ('string' === typeof evalString) {
self.emit('line', evalString);
}

self.displayPrompt();
}
inherits(REPLServer, rl.Interface);
Expand Down
7 changes: 6 additions & 1 deletion src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3094,7 +3094,9 @@ static void ParseArgs(int* argc,
strcmp(arg, "-e") == 0 ||
strcmp(arg, "--print") == 0 ||
strcmp(arg, "-pe") == 0 ||
strcmp(arg, "-p") == 0) {
strcmp(arg, "-p") == 0 ||
strcmp(arg, "--interactive-eval") == 0 ||
strcmp(arg, "-ie") == 0) {
bool is_eval = strchr(arg, 'e') != nullptr;
bool is_print = strchr(arg, 'p') != nullptr;
print_eval = print_eval || is_print;
Expand All @@ -3106,6 +3108,9 @@ static void ParseArgs(int* argc,
fprintf(stderr, "%s: %s requires an argument\n", argv[0], arg);
exit(9);
}
if (strcmp(arg, "--interactive-eval") == 0 || strcmp(arg, "-ie") == 0) {
force_repl = true;
}
} else if ((index + 1 < nargs) &&
argv[index + 1] != nullptr &&
argv[index + 1][0] != '-') {
Expand Down
22 changes: 21 additions & 1 deletion src/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,27 @@
});
}

if (process._eval != null) {
if (process._eval != null && process._forceRepl) {
var Module = NativeModule.require('module');

// interactive-eval REPL
var opts = {
useGlobal: true,
ignoreUndefined: false,
evalString: process._eval
};
if (parseInt(process.env['NODE_NO_READLINE'], 10)) {
opts.terminal = false;
}
if (parseInt(process.env['NODE_DISABLE_COLORS'], 10)) {
opts.useColors = false;
}
var repl = Module.requireRepl().start(opts);
repl.on('exit', function() {
process.exit();
});

} else if (process._eval != null) {
// User passed '-e' or '--eval' arguments to Node.
evalScript('[eval]');
} else if (process.argv[1]) {
Expand Down