Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

repl: partially fix repl context #28561

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions lib/repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 10 additions & 0 deletions test/parallel/test-repl-context.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down