[repl] let self.eval be configurable on REPLServer initialization
authorFedor Indutny <fedor.indutny@gmail.com>
Wed, 7 Sep 2011 16:35:55 +0000 (23:35 +0700)
committerFedor Indutny <fedor.indutny@gmail.com>
Thu, 8 Sep 2011 19:06:06 +0000 (02:06 +0700)
lib/repl.js

index db0d06f..82fe585 100644 (file)
@@ -64,10 +64,10 @@ module.paths = require('module')._nodeModulePaths(module.filename);
 exports.writer = util.inspect;
 
 
-function REPLServer(prompt, stream) {
+function REPLServer(prompt, stream, eval) {
   var self = this;
 
-  self.eval = function(code, context, file, cb) {
+  self.eval = eval || function(code, context, file, cb) {
     try {
       var err, result = vm.runInContext(code, context, file);
     } catch (e) {
@@ -247,8 +247,8 @@ exports.REPLServer = REPLServer;
 
 // prompt is a string to print on each line for the prompt,
 // source is a stream to use for I/O, defaulting to stdin/stdout.
-exports.start = function(prompt, source) {
-  var repl = new REPLServer(prompt, source);
+exports.start = function(prompt, source, eval) {
+  var repl = new REPLServer(prompt, source, eval);
   if (!exports.repl) exports.repl = repl;
   return repl;
 };