summaryrefslogtreecommitdiff
path: root/test/parallel/test-repl-context.js
diff options
context:
space:
mode:
authorLance Ball <lball@redhat.com>2016-06-22 13:07:59 -0400
committerLance Ball <lball@redhat.com>2016-06-27 16:55:53 -0400
commitc0e48bf27dc1036fe3886a6b9236b79f98b2dcfb (patch)
tree9ab18d5acd9791a8ad8e19a0cfe80260202aae78 /test/parallel/test-repl-context.js
parenta1059afd3963a2a8f916aa0874865658c0479672 (diff)
downloadandroid-node-v8-c0e48bf27dc1036fe3886a6b9236b79f98b2dcfb.tar.gz
android-node-v8-c0e48bf27dc1036fe3886a6b9236b79f98b2dcfb.tar.bz2
android-node-v8-c0e48bf27dc1036fe3886a6b9236b79f98b2dcfb.zip
repl: Enable tab completion for global properties
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>
Diffstat (limited to 'test/parallel/test-repl-context.js')
-rw-r--r--test/parallel/test-repl-context.js26
1 files changed, 26 insertions, 0 deletions
diff --git a/test/parallel/test-repl-context.js b/test/parallel/test-repl-context.js
new file mode 100644
index 0000000000..1b319a036f
--- /dev/null
+++ b/test/parallel/test-repl-context.js
@@ -0,0 +1,26 @@
+'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();
+
+// Test when useGlobal is false
+testContext(repl.start({
+ input: stream,
+ output: stream,
+ useGlobal: false
+}));
+
+function testContext(repl) {
+ const context = repl.createContext();
+ // ensure that the repl context gets its own "console" instance
+ assert(context.console instanceof require('console').Console);
+
+ // ensure that the repl's global property is the context
+ assert(context.global === context);
+
+ // ensure that the repl console instance does not have a setter
+ assert.throws(() => context.console = 'foo');
+}