use vm.runInContext instead of vm.Script.runInContext

This commit is contained in:
Sami Samhuri 2011-11-05 16:31:09 -07:00
parent 53d322e0ca
commit 9c36c8f9c3

View file

@ -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 <filename>, .unstash <filename>, .editor <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