mirror of
https://github.com/nodejs/node.git
synced 2025-05-03 02:06:12 +00:00

When `useGlobal` is false, tab completion in the repl does not enumerate global properties. Instead of just setting these properties blindly on the global context, e.g. context[prop] = global[prop] Use `Object.defineProperty` and the property descriptor found on `global` for the new property in `context`. Also addresses a previously unnoticed issue where `console` is writable when `useGlobal` is false. If the binary has been built with `./configure --without-intl` then the `Intl` builtin type will not be available in a repl runtime. Check for this in the test. Fixes: https://github.com/nodejs/node/issues/7353 PR-URL: https://github.com/nodejs/node/pull/7369 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
24 lines
612 B
JavaScript
24 lines
612 B
JavaScript
'use strict';
|
|
const common = require('../common');
|
|
const assert = require('assert');
|
|
const repl = require('repl');
|
|
|
|
// Create a dummy stream that does nothing
|
|
const stream = new common.ArrayStream();
|
|
|
|
var r = repl.start({
|
|
input: stream,
|
|
output: stream,
|
|
useGlobal: false
|
|
});
|
|
|
|
|
|
// 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);
|
|
|
|
// ensure that the repl console instance does not have a setter
|
|
assert.throws(() => r.context.console = 'foo', TypeError);
|