summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorNathan Rajlich <nathan@tootallnate.net>2012-10-12 16:34:36 -0700
committerNathan Rajlich <nathan@tootallnate.net>2012-10-12 16:37:17 -0700
commitb1e78cef097c682ed63528ad7efe294b18a9fb1d (patch)
tree8b1126a15cb418695073216af1c272acba3b1714 /lib
parent323bbdb0cb2518ff15ad361ad3495cc4739f3bdf (diff)
downloadnode-new-b1e78cef097c682ed63528ad7efe294b18a9fb1d.tar.gz
repl: ensure each REPL instance gets its own "context"
Before there was this weird module-scoped "context" variable which seemingly shared the "context" of subsequent REPL instances, unless ".clear" was invoked inside the REPL. To be proper, we need to ensure that each REPL gets its own "context" object. I literally don't know why this "sharing" behavior was in place before, but it was just plain wrong.
Diffstat (limited to 'lib')
-rw-r--r--lib/repl.js23
1 files changed, 9 insertions, 14 deletions
diff --git a/lib/repl.js b/lib/repl.js
index af0d422a44..ba334cfda9 100644
--- a/lib/repl.js
+++ b/lib/repl.js
@@ -57,8 +57,6 @@ function hasOwnProperty(obj, prop) {
}
-var context;
-
// hack for require.resolve("./relative") to work properly.
module.filename = path.resolve('repl');
@@ -327,11 +325,12 @@ exports.start = function(prompt, source, eval_, useGlobal, ignoreUndefined) {
REPLServer.prototype.createContext = function() {
- if (!this.useGlobal) {
- var context = vm.createContext();
- for (var i in global) context[i] = global[i];
+ var context;
+ if (this.useGlobal) {
+ context = global;
} else {
- var context = global;
+ context = vm.createContext();
+ for (var i in global) context[i] = global[i];
}
context.module = module;
@@ -345,13 +344,9 @@ REPLServer.prototype.createContext = function() {
return context;
};
-REPLServer.prototype.resetContext = function(force) {
- if (!context || force) {
- context = this.createContext();
- for (var i in require.cache) delete require.cache[i];
- }
-
- this.context = context;
+REPLServer.prototype.resetContext = function() {
+ for (var i in require.cache) delete require.cache[i];
+ this.context = this.createContext();
};
REPLServer.prototype.displayPrompt = function(preserveCursor) {
@@ -800,7 +795,7 @@ function defineDefaultCommands(repl) {
this.bufferedCommand = '';
if (!this.useGlobal) {
this.outputStream.write('Clearing context...\n');
- this.resetContext(true);
+ this.resetContext();
}
this.displayPrompt();
}