mirror of
https://github.com/samsonjs/repl-edit.git
synced 2026-04-27 15:07:40 +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')
|
, replModule = require('repl')
|
||||||
, spawn = require('child_process').spawn
|
, spawn = require('child_process').spawn
|
||||||
, util = require('util')
|
, util = require('util')
|
||||||
|
, vm = require('vm')
|
||||||
, Hint = 'Commands: .edit, .run, .stash <filename>, .unstash <filename>, .editor <editor>'
|
, Hint = 'Commands: .edit, .run, .stash <filename>, .unstash <filename>, .editor <editor>'
|
||||||
, theRepl
|
, theRepl
|
||||||
|
|
||||||
|
|
@ -176,19 +177,15 @@ function run(filename, callback) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var evalcx = require('vm').Script.runInContext
|
var read = fs.createReadStream(filename)
|
||||||
, read = fs.createReadStream(filename)
|
, cmd = ''
|
||||||
, s = ''
|
read.on('data', function(d) { cmd += d })
|
||||||
read.on('data', function(d) { s += d })
|
|
||||||
read.on('end', function() {
|
read.on('end', function() {
|
||||||
// The catchall for errors
|
// The catchall for errors
|
||||||
try {
|
try {
|
||||||
// Use evalcx to supply the global context
|
var ret = vm.runInContext(cmd, theRepl.context, 'repl');
|
||||||
var ret = evalcx(s, repl.context, "repl");
|
theRepl.context._ = ret
|
||||||
if (ret !== undefined) {
|
theRepl.outputStream.write(replModule.writer(ret) + '\n')
|
||||||
repl.context._ = ret
|
|
||||||
repl.outputStream.write(replModule.writer(ret) + '\n')
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
// On error: Print the error and clear the buffer
|
// On error: Print the error and clear the buffer
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue