summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAnna Henningsen <anna@addaleax.net>2020-12-18 14:57:59 +0100
committerAnna Henningsen <anna@addaleax.net>2020-12-21 12:52:02 +0100
commit82dd23f5eccac652898315c67b4ee648b18e9783 (patch)
tree42ba4855c15fc7daabeaa6e4056d67f88c4b568b /lib
parentab895bd587ed47423a6baab0bd6934128aa8990d (diff)
downloadios-node-v8-82dd23f5eccac652898315c67b4ee648b18e9783.tar.gz
ios-node-v8-82dd23f5eccac652898315c67b4ee648b18e9783.tar.bz2
ios-node-v8-82dd23f5eccac652898315c67b4ee648b18e9783.zip
repl: disable blocking completions by default
It’s not okay for the REPL to be blocked for multiple seconds after entering `require('` because the completion is performing blocking fs operations on potentially huge directories. Turning the REPL completion function asynchronous would be the right thing to do here, but unfortunately the way the code is structured doesn’t play well with that (in particular, it breaks the preview feature). Therefore, disable these blocking calls by default. Refs: https://github.com/nodejs/node/pull/33282#issuecomment-733646794 PR-URL: https://github.com/nodejs/node/pull/36564 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/repl.js7
1 files changed, 5 insertions, 2 deletions
diff --git a/lib/repl.js b/lib/repl.js
index 3b95bd7f29..3368b5997a 100644
--- a/lib/repl.js
+++ b/lib/repl.js
@@ -298,6 +298,7 @@ function REPLServer(prompt,
configurable: true
});
+ this.allowBlockingCompletions = !!options.allowBlockingCompletions;
this.useColors = !!options.useColors;
this._domain = options.domain || domain.create();
this.useGlobal = !!useGlobal;
@@ -1204,7 +1205,8 @@ function complete(line, callback) {
if (completeOn.length) {
filter = completeOn;
}
- } else if (RegExpPrototypeTest(requireRE, line)) {
+ } else if (RegExpPrototypeTest(requireRE, line) &&
+ this.allowBlockingCompletions) {
// require('...<Tab>')
const extensions = ObjectKeys(this.context.require.extensions);
const indexes = ArrayPrototypeMap(extensions,
@@ -1265,7 +1267,8 @@ function complete(line, callback) {
if (!subdir) {
ArrayPrototypePush(completionGroups, _builtinLibs);
}
- } else if (RegExpPrototypeTest(fsAutoCompleteRE, line)) {
+ } else if (RegExpPrototypeTest(fsAutoCompleteRE, line) &&
+ this.allowBlockingCompletions) {
[completionGroups, completeOn] = completeFSFunctions(line);
// Handle variable member lookup.
// We support simple chained expressions like the following (no function