summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLiviaMedeiros <livia@cirno.name>2022-05-21 17:54:41 +0800
committerAntoine du Hamel <duhamelantoine1995@gmail.com>2022-06-11 12:18:14 +0200
commit8e7e58f6b0473cad3b2cb360fed72ed1cc339687 (patch)
tree4c6e77c0ab9ea16f34900423ad64debd15a30fa2
parenta983d395ec814483fa207d26bedc899fac406a3d (diff)
downloadnode-new-8e7e58f6b0473cad3b2cb360fed72ed1cc339687.tar.gz
readline: use `kEmptyObject`
PR-URL: https://github.com/nodejs/node/pull/43159 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
-rw-r--r--lib/internal/readline/interface.js3
-rw-r--r--lib/readline.js15
-rw-r--r--lib/readline/promises.js6
3 files changed, 18 insertions, 6 deletions
diff --git a/lib/internal/readline/interface.js b/lib/internal/readline/interface.js
index 47e5ca580a..457b67716c 100644
--- a/lib/internal/readline/interface.js
+++ b/lib/internal/readline/interface.js
@@ -48,6 +48,7 @@ const {
validateString,
validateUint32,
} = require('internal/validators');
+const { kEmptyObject } = require('internal/util');
const {
inspect,
getStringWidth,
@@ -1053,7 +1054,7 @@ class Interface extends InterfaceConstructor {
// Handle a write from the tty
[kTtyWrite](s, key) {
const previousKey = this[kPreviousKey];
- key = key || {};
+ key = key || kEmptyObject;
this[kPreviousKey] = key;
if (!key.meta || key.name !== 'y') {
diff --git a/lib/readline.js b/lib/readline.js
index 82afaa285d..26e277c7ab 100644
--- a/lib/readline.js
+++ b/lib/readline.js
@@ -47,7 +47,10 @@ const {
const {
inspect,
} = require('internal/util/inspect');
-const { promisify } = require('internal/util');
+const {
+ kEmptyObject,
+ promisify,
+} = require('internal/util');
const { validateAbortSignal } = require('internal/validators');
/**
@@ -128,7 +131,9 @@ const superQuestion = _Interface.prototype.question;
*/
Interface.prototype.question = function(query, options, cb) {
cb = typeof options === 'function' ? options : cb;
- options = typeof options === 'object' && options !== null ? options : {};
+ if (options === null || typeof options !== 'object') {
+ options = kEmptyObject;
+ }
if (options.signal) {
validateAbortSignal(options.signal, 'options.signal');
@@ -154,7 +159,9 @@ Interface.prototype.question = function(query, options, cb) {
}
};
Interface.prototype.question[promisify.custom] = function question(query, options) {
- options = typeof options === 'object' && options !== null ? options : {};
+ if (options === null || typeof options !== 'object') {
+ options = kEmptyObject;
+ }
if (options.signal && options.signal.aborted) {
return PromiseReject(
@@ -457,7 +464,7 @@ Interface.prototype._moveCursor = _Interface.prototype[kMoveCursor];
Interface.prototype._ttyWrite = _Interface.prototype[kTtyWrite];
function _ttyWriteDumb(s, key) {
- key = key || {};
+ key = key || kEmptyObject;
if (key.name === 'escape') return;
diff --git a/lib/readline/promises.js b/lib/readline/promises.js
index 534558ec31..728a6253fd 100644
--- a/lib/readline/promises.js
+++ b/lib/readline/promises.js
@@ -18,12 +18,16 @@ const {
} = require('internal/errors');
const { validateAbortSignal } = require('internal/validators');
+const {
+ kEmptyObject,
+} = require('internal/util');
+
class Interface extends _Interface {
// eslint-disable-next-line no-useless-constructor
constructor(input, output, completer, terminal) {
super(input, output, completer, terminal);
}
- question(query, options = {}) {
+ question(query, options = kEmptyObject) {
return new Promise((resolve, reject) => {
let cb = resolve;