Skip to content

Commit ffbf790

Browse files
committed
readline: set null as callback return in case there's no error
The cursor move functions accept a callback. It was possible that `undefined` was returned in case there was no error instead of null. PR-URL: #31006 Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Anto Aravinth <[email protected]> Reviewed-By: Rich Trott <[email protected]>
1 parent 92dcf3e commit ffbf790

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

lib/readline.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1200,7 +1200,7 @@ function cursorTo(stream, x, y, callback) {
12001200

12011201
if (stream == null || (typeof x !== 'number' && typeof y !== 'number')) {
12021202
if (typeof callback === 'function')
1203-
process.nextTick(callback);
1203+
process.nextTick(callback, null);
12041204
return true;
12051205
}
12061206

@@ -1221,7 +1221,7 @@ function moveCursor(stream, dx, dy, callback) {
12211221

12221222
if (stream == null || !(dx || dy)) {
12231223
if (typeof callback === 'function')
1224-
process.nextTick(callback);
1224+
process.nextTick(callback, null);
12251225
return true;
12261226
}
12271227

@@ -1255,7 +1255,7 @@ function clearLine(stream, dir, callback) {
12551255

12561256
if (stream === null || stream === undefined) {
12571257
if (typeof callback === 'function')
1258-
process.nextTick(callback);
1258+
process.nextTick(callback, null);
12591259
return true;
12601260
}
12611261

@@ -1277,7 +1277,7 @@ function clearScreenDown(stream, callback) {
12771277

12781278
if (stream === null || stream === undefined) {
12791279
if (typeof callback === 'function')
1280-
process.nextTick(callback);
1280+
process.nextTick(callback, null);
12811281
return true;
12821282
}
12831283

test/parallel/test-readline-csi.js

+12-4
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ assert.throws(() => {
3939
}, /ERR_INVALID_CALLBACK/);
4040

4141
// Verify that clearScreenDown() does not throw on null or undefined stream.
42-
assert.strictEqual(readline.clearScreenDown(null, common.mustCall()), true);
42+
assert.strictEqual(readline.clearScreenDown(null, common.mustCall((err) => {
43+
assert.strictEqual(err, null);
44+
})), true);
4345
assert.strictEqual(readline.clearScreenDown(undefined, common.mustCall()),
4446
true);
4547

@@ -67,7 +69,9 @@ assert.throws(() => {
6769
// Verify that clearLine() does not throw on null or undefined stream.
6870
assert.strictEqual(readline.clearLine(null, 0), true);
6971
assert.strictEqual(readline.clearLine(undefined, 0), true);
70-
assert.strictEqual(readline.clearLine(null, 0, common.mustCall()), true);
72+
assert.strictEqual(readline.clearLine(null, 0, common.mustCall((err) => {
73+
assert.strictEqual(err, null);
74+
})), true);
7175
assert.strictEqual(readline.clearLine(undefined, 0, common.mustCall()), true);
7276

7377
// Nothing is written when moveCursor 0, 0
@@ -101,15 +105,19 @@ assert.throws(() => {
101105
// Verify that moveCursor() does not throw on null or undefined stream.
102106
assert.strictEqual(readline.moveCursor(null, 1, 1), true);
103107
assert.strictEqual(readline.moveCursor(undefined, 1, 1), true);
104-
assert.strictEqual(readline.moveCursor(null, 1, 1, common.mustCall()), true);
108+
assert.strictEqual(readline.moveCursor(null, 1, 1, common.mustCall((err) => {
109+
assert.strictEqual(err, null);
110+
})), true);
105111
assert.strictEqual(readline.moveCursor(undefined, 1, 1, common.mustCall()),
106112
true);
107113

108114
// Undefined or null as stream should not throw.
109115
assert.strictEqual(readline.cursorTo(null), true);
110116
assert.strictEqual(readline.cursorTo(), true);
111117
assert.strictEqual(readline.cursorTo(null, 1, 1, common.mustCall()), true);
112-
assert.strictEqual(readline.cursorTo(undefined, 1, 1, common.mustCall()), true);
118+
assert.strictEqual(readline.cursorTo(undefined, 1, 1, common.mustCall((err) => {
119+
assert.strictEqual(err, null);
120+
})), true);
113121

114122
writable.data = '';
115123
assert.strictEqual(readline.cursorTo(writable, 'a'), true);

0 commit comments

Comments
 (0)