Merge pull request #3150 from mklement0/fix-repl-module-global-context-support

Fix: support for consumers of the REPL *module* being able to opt into using the global context ...
This commit is contained in:
Michael Ficarra
2013-09-03 14:47:22 -07:00
2 changed files with 8 additions and 3 deletions

View File

@@ -19,7 +19,7 @@
historyFile: process.env.HOME ? path.join(process.env.HOME, '.coffee_history') : void 0,
historyMaxInputSize: 10240,
"eval": function(input, context, filename, cb) {
var Assign, Block, Literal, Value, ast, err, js, _ref1;
var Assign, Block, Literal, Value, ast, err, js, result, _ref1;
input = input.replace(/\uFF00/g, '\n');
input = input.replace(/^\(([\s\S]*)\n\)$/m, '$1');
_ref1 = require('./nodes'), Block = _ref1.Block, Assign = _ref1.Assign, Value = _ref1.Value, Literal = _ref1.Literal;
@@ -30,7 +30,8 @@
bare: true,
locals: Object.keys(context)
});
return cb(null, vm.runInContext(js, context, filename));
result = context === global ? vm.runInThisContext(js, filename) : vm.runInContext(js, context, filename);
return cb(null, result);
} catch (_error) {
err = _error;
updateSyntaxError(err, input);

View File

@@ -27,7 +27,11 @@ replDefaults =
new Assign (new Value new Literal '_'), ast, '='
]
js = ast.compile bare: yes, locals: Object.keys(context)
cb null, vm.runInContext(js, context, filename)
result = if context is global
vm.runInThisContext js, filename
else
vm.runInContext js, context, filename
cb null, result
catch err
# AST's `compile` does not add source code information to syntax errors.
updateSyntaxError err, input