From 7f38f0a422dbb6ab6632fd664318dd435a35eafb Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Wed, 18 Dec 2019 19:58:49 +0100 Subject: [PATCH] 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. --- lib/readline.js | 8 ++++---- test/parallel/test-readline-csi.js | 16 ++++++++++++---- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/lib/readline.js b/lib/readline.js index 7c8488122d5bb4..3129f1617604f4 100644 --- a/lib/readline.js +++ b/lib/readline.js @@ -1198,7 +1198,7 @@ function cursorTo(stream, x, y, callback) { if (stream == null || (typeof x !== 'number' && typeof y !== 'number')) { if (typeof callback === 'function') - process.nextTick(callback); + process.nextTick(callback, null); return true; } @@ -1219,7 +1219,7 @@ function moveCursor(stream, dx, dy, callback) { if (stream == null || !(dx || dy)) { if (typeof callback === 'function') - process.nextTick(callback); + process.nextTick(callback, null); return true; } @@ -1253,7 +1253,7 @@ function clearLine(stream, dir, callback) { if (stream === null || stream === undefined) { if (typeof callback === 'function') - process.nextTick(callback); + process.nextTick(callback, null); return true; } @@ -1275,7 +1275,7 @@ function clearScreenDown(stream, callback) { if (stream === null || stream === undefined) { if (typeof callback === 'function') - process.nextTick(callback); + process.nextTick(callback, null); return true; } diff --git a/test/parallel/test-readline-csi.js b/test/parallel/test-readline-csi.js index 53b07d7bd939fd..346f1cbad12db1 100644 --- a/test/parallel/test-readline-csi.js +++ b/test/parallel/test-readline-csi.js @@ -39,7 +39,9 @@ assert.throws(() => { }, /ERR_INVALID_CALLBACK/); // Verify that clearScreenDown() does not throw on null or undefined stream. -assert.strictEqual(readline.clearScreenDown(null, common.mustCall()), true); +assert.strictEqual(readline.clearScreenDown(null, common.mustCall((err) => { + assert.strictEqual(err, null); +})), true); assert.strictEqual(readline.clearScreenDown(undefined, common.mustCall()), true); @@ -67,7 +69,9 @@ assert.throws(() => { // Verify that clearLine() does not throw on null or undefined stream. assert.strictEqual(readline.clearLine(null, 0), true); assert.strictEqual(readline.clearLine(undefined, 0), true); -assert.strictEqual(readline.clearLine(null, 0, common.mustCall()), true); +assert.strictEqual(readline.clearLine(null, 0, common.mustCall((err) => { + assert.strictEqual(err, null); +})), true); assert.strictEqual(readline.clearLine(undefined, 0, common.mustCall()), true); // Nothing is written when moveCursor 0, 0 @@ -101,7 +105,9 @@ assert.throws(() => { // Verify that moveCursor() does not throw on null or undefined stream. assert.strictEqual(readline.moveCursor(null, 1, 1), true); assert.strictEqual(readline.moveCursor(undefined, 1, 1), true); -assert.strictEqual(readline.moveCursor(null, 1, 1, common.mustCall()), true); +assert.strictEqual(readline.moveCursor(null, 1, 1, common.mustCall((err) => { + assert.strictEqual(err, null); +})), true); assert.strictEqual(readline.moveCursor(undefined, 1, 1, common.mustCall()), true); @@ -109,7 +115,9 @@ assert.strictEqual(readline.moveCursor(undefined, 1, 1, common.mustCall()), assert.strictEqual(readline.cursorTo(null), true); assert.strictEqual(readline.cursorTo(), true); assert.strictEqual(readline.cursorTo(null, 1, 1, common.mustCall()), true); -assert.strictEqual(readline.cursorTo(undefined, 1, 1, common.mustCall()), true); +assert.strictEqual(readline.cursorTo(undefined, 1, 1, common.mustCall((err) => { + assert.strictEqual(err, null); +})), true); writable.data = ''; assert.strictEqual(readline.cursorTo(writable, 'a'), true);