Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

repl: add reverse search #31006

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
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.
  • Loading branch information
BridgeAR committed Dec 19, 2019
commit 7f38f0a422dbb6ab6632fd664318dd435a35eafb
8 changes: 4 additions & 4 deletions lib/readline.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand Down
16 changes: 12 additions & 4 deletions test/parallel/test-readline-csi.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -101,15 +105,19 @@ 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);

// Undefined or null as stream should not throw.
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);
Expand Down