Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 5e98cac

Browse filesBrowse files
LiviaMedeirosdanielleadams
authored andcommitted
readline: use kEmptyObject
PR-URL: #43159 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
1 parent a3310d1 commit 5e98cac
Copy full SHA for 5e98cac

File tree

Expand file treeCollapse file tree

3 files changed

+18
-6
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

3 files changed

+18
-6
lines changed
Open diff view settings
Collapse file

‎lib/internal/readline/interface.js‎

Copy file name to clipboardExpand all lines: lib/internal/readline/interface.js
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ const {
4848
validateString,
4949
validateUint32,
5050
} = require('internal/validators');
51+
const { kEmptyObject } = require('internal/util');
5152
const {
5253
inspect,
5354
getStringWidth,
@@ -1053,7 +1054,7 @@ class Interface extends InterfaceConstructor {
10531054
// Handle a write from the tty
10541055
[kTtyWrite](s, key) {
10551056
const previousKey = this[kPreviousKey];
1056-
key = key || {};
1057+
key = key || kEmptyObject;
10571058
this[kPreviousKey] = key;
10581059

10591060
if (!key.meta || key.name !== 'y') {
Collapse file

‎lib/readline.js‎

Copy file name to clipboardExpand all lines: lib/readline.js
+11-4Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,10 @@ const {
4747
const {
4848
inspect,
4949
} = require('internal/util/inspect');
50-
const { promisify } = require('internal/util');
50+
const {
51+
kEmptyObject,
52+
promisify,
53+
} = require('internal/util');
5154
const { validateAbortSignal } = require('internal/validators');
5255

5356
/**
@@ -128,7 +131,9 @@ const superQuestion = _Interface.prototype.question;
128131
*/
129132
Interface.prototype.question = function(query, options, cb) {
130133
cb = typeof options === 'function' ? options : cb;
131-
options = typeof options === 'object' && options !== null ? options : {};
134+
if (options === null || typeof options !== 'object') {
135+
options = kEmptyObject;
136+
}
132137

133138
if (options.signal) {
134139
validateAbortSignal(options.signal, 'options.signal');
@@ -154,7 +159,9 @@ Interface.prototype.question = function(query, options, cb) {
154159
}
155160
};
156161
Interface.prototype.question[promisify.custom] = function question(query, options) {
157-
options = typeof options === 'object' && options !== null ? options : {};
162+
if (options === null || typeof options !== 'object') {
163+
options = kEmptyObject;
164+
}
158165

159166
if (options.signal && options.signal.aborted) {
160167
return PromiseReject(
@@ -457,7 +464,7 @@ Interface.prototype._moveCursor = _Interface.prototype[kMoveCursor];
457464
Interface.prototype._ttyWrite = _Interface.prototype[kTtyWrite];
458465

459466
function _ttyWriteDumb(s, key) {
460-
key = key || {};
467+
key = key || kEmptyObject;
461468

462469
if (key.name === 'escape') return;
463470

Collapse file

‎lib/readline/promises.js‎

Copy file name to clipboardExpand all lines: lib/readline/promises.js
+5-1Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,16 @@ const {
1818
} = require('internal/errors');
1919
const { validateAbortSignal } = require('internal/validators');
2020

21+
const {
22+
kEmptyObject,
23+
} = require('internal/util');
24+
2125
class Interface extends _Interface {
2226
// eslint-disable-next-line no-useless-constructor
2327
constructor(input, output, completer, terminal) {
2428
super(input, output, completer, terminal);
2529
}
26-
question(query, options = {}) {
30+
question(query, options = kEmptyObject) {
2731
return new Promise((resolve, reject) => {
2832
let cb = resolve;
2933

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.