mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-05-03 03:00:14 -04:00
Reloading globals after every REPL command (actually fixes #1654)
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
(function() {
|
||||
var ACCESSOR, CoffeeScript, Module, REPL_PROMPT, REPL_PROMPT_CONTINUATION, SIMPLEVAR, Script, autocomplete, backlog, completeAttribute, completeVariable, enableColours, error, excludedGlobals, g, getCompletions, inspect, nonContextGlobals, readline, repl, run, sandbox, stdin, stdout;
|
||||
var ACCESSOR, CoffeeScript, Module, REPL_PROMPT, REPL_PROMPT_CONTINUATION, SIMPLEVAR, Script, autocomplete, backlog, completeAttribute, completeVariable, enableColours, error, excludedGlobals, getCompletions, inspect, readline, repl, run, sandbox, stdin, stdout;
|
||||
var __hasProp = Object.prototype.hasOwnProperty, __indexOf = Array.prototype.indexOf || function(item) {
|
||||
for (var i = 0, l = this.length; i < l; i++) {
|
||||
if (__hasProp.call(this, i) && this[i] === item) return i;
|
||||
@@ -25,13 +25,9 @@
|
||||
backlog = '';
|
||||
sandbox = Script.createContext();
|
||||
excludedGlobals = ['global', 'GLOBAL', 'root'];
|
||||
nonContextGlobals = ['Buffer', 'console', 'process', 'setInterval', 'clearInterval', 'setTimeout', 'clearTimeout'];
|
||||
for (g in global) {
|
||||
if (__indexOf.call(excludedGlobals, g) < 0) sandbox[g] = global[g];
|
||||
}
|
||||
sandbox.global = sandbox.root = sandbox.GLOBAL = sandbox;
|
||||
run = function(buffer) {
|
||||
var code, returnValue, _;
|
||||
var code, g, returnValue, _;
|
||||
if (!buffer.toString().trim() && !backlog) {
|
||||
repl.prompt();
|
||||
return;
|
||||
@@ -46,6 +42,9 @@
|
||||
repl.setPrompt(REPL_PROMPT);
|
||||
backlog = '';
|
||||
try {
|
||||
for (g in global) {
|
||||
if (__indexOf.call(excludedGlobals, g) < 0) sandbox[g] = global[g];
|
||||
}
|
||||
_ = sandbox._;
|
||||
returnValue = CoffeeScript.eval("_=(" + code + "\n)", {
|
||||
sandbox: sandbox,
|
||||
|
||||
@@ -36,12 +36,6 @@ sandbox = Script.createContext()
|
||||
excludedGlobals = [
|
||||
'global', 'GLOBAL', 'root'
|
||||
]
|
||||
nonContextGlobals = [
|
||||
'Buffer', 'console', 'process'
|
||||
'setInterval', 'clearInterval'
|
||||
'setTimeout', 'clearTimeout'
|
||||
]
|
||||
sandbox[g] = global[g] for g of global when g not in excludedGlobals
|
||||
sandbox.global = sandbox.root = sandbox.GLOBAL = sandbox
|
||||
|
||||
# The main REPL function. **run** is called every time a line of code is entered.
|
||||
@@ -60,6 +54,7 @@ run = (buffer) ->
|
||||
repl.setPrompt REPL_PROMPT
|
||||
backlog = ''
|
||||
try
|
||||
sandbox[g] = global[g] for g of global when g not in excludedGlobals
|
||||
_ = sandbox._
|
||||
returnValue = CoffeeScript.eval "_=(#{code}\n)", {
|
||||
sandbox,
|
||||
|
||||
Reference in New Issue
Block a user