Skip to content
Permalink
Browse files

repl: fix some repl context issues

This partially fixes contexts like `{} instanceof Object === false`
in the REPL. This does not fix all cases, since it's something
fundamental from the REPL's design that things like these can happen.

Refs: #27859

PR-URL: #28561
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Anto Aravinth <anto.aravinth.cse@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information...
BridgeAR authored and targos committed Jul 5, 2019
1 parent cbd586a commit d611f5ad3ed189db168820f4ff0fae3bc7afe7fa
Showing with 15 additions and 2 deletions.
  1. +5 −2 lib/repl.js
  2. +10 −0 test/parallel/test-repl-context.js
@@ -875,8 +875,11 @@ REPLServer.prototype.createContext = function() {
context = vm.createContext();
});
for (const name of Object.getOwnPropertyNames(global)) {
Object.defineProperty(context, name,
Object.getOwnPropertyDescriptor(global, name));
// Only set properties on the context that do not exist as primordial.
if (!(name in primordials)) {
Object.defineProperty(context, name,
Object.getOwnPropertyDescriptor(global, name));
}
}
context.global = context;
const _console = new Console(this.outputStream);
@@ -16,11 +16,21 @@ const stream = new ArrayStream();
useGlobal: false
});

let output = '';
stream.write = function(d) {
output += d;
};

// Ensure that the repl context gets its own "console" instance.
assert(r.context.console);

// Ensure that the repl console instance is not the global one.
assert.notStrictEqual(r.context.console, console);
assert.notStrictEqual(r.context.Object, Object);

stream.run(['({} instanceof Object)']);

assert.strictEqual(output, 'true\n> ');

const context = r.createContext();
// Ensure that the repl context gets its own "console" instance.

0 comments on commit d611f5a

Please sign in to comment.
You can’t perform that action at this time.