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>
This commit is contained in:
LiviaMedeiros authored and Antoine du Hamel committed 2022-06-11 12:18:14 +02:00
1 parent a983d395ec
commit 8e7e58f6b0
3 files changed
+18 -6

No files matched your search

+2 -1
View File
@@ -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') {
+11 -4
View File
@@ -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;
+5 -1
View File
@@ -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;