diff --git a/lib/repl.js b/lib/repl.js index ed0c9fd420fae3..2f82c2ca49fc71 100644 --- a/lib/repl.js +++ b/lib/repl.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); diff --git a/test/parallel/test-repl-context.js b/test/parallel/test-repl-context.js index 287d8adc295d7a..88bd47a9281a9c 100644 --- a/test/parallel/test-repl-context.js +++ b/test/parallel/test-repl-context.js @@ -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.