diff --git a/lib/index.js b/lib/index.js index 3f908d6..79aa1e0 100644 --- a/lib/index.js +++ b/lib/index.js @@ -11,6 +11,7 @@ var fs = require('fs') , replModule = require('repl') , spawn = require('child_process').spawn , util = require('util') + , vm = require('vm') , Hint = 'Commands: .edit, .run, .stash , .unstash , .editor ' , theRepl @@ -176,19 +177,15 @@ function run(filename, callback) { return } - var evalcx = require('vm').Script.runInContext - , read = fs.createReadStream(filename) - , s = '' - read.on('data', function(d) { s += d }) + var read = fs.createReadStream(filename) + , cmd = '' + read.on('data', function(d) { cmd += d }) read.on('end', function() { // The catchall for errors try { - // Use evalcx to supply the global context - var ret = evalcx(s, repl.context, "repl"); - if (ret !== undefined) { - repl.context._ = ret - repl.outputStream.write(replModule.writer(ret) + '\n') - } + var ret = vm.runInContext(cmd, theRepl.context, 'repl'); + theRepl.context._ = ret + theRepl.outputStream.write(replModule.writer(ret) + '\n') } catch (e) { // On error: Print the error and clear the buffer