mirror of
https://github.com/nodejs/node.git
synced 2024-12-01 16:10:02 +01:00
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: https://github.com/nodejs/node/issues/27859 PR-URL: https://github.com/nodejs/node/pull/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>
This commit is contained in:
parent
6874aa1fb1
commit
7e977d7cd4
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user