mirror of
https://github.com/samsonjs/repl-edit.git
synced 2026-03-25 09:25:49 +00:00
use vm.runInContext instead of vm.Script.runInContext
This commit is contained in:
parent
53d322e0ca
commit
9c36c8f9c3
1 changed files with 7 additions and 10 deletions
17
lib/index.js
17
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 <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
|
||||
|
|
|
|||
Loading…
Reference in a new issue