repl: fixing `undefined` in invalid REPL keyword error

When an invalid REPL keyword is used, we actually print `undefined` as
well in the console.

    > process.version
    'v2.3.4'
    > .invalid_repl_command
    Invalid REPL keyword
    undefined
    >

This patch prevents printing `undefined` in this case.

    > process.version
    'v2.3.5-pre'
    > .invalid_repl_command
    Invalid REPL keyword
    >

PR-URL: https://github.com/nodejs/io.js/pull/2163
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
This commit is contained in:
Sakthipriyan Vairamani 2015-07-12 00:53:39 +00:00
Родитель a3c1b9720e
Коммит 77fa385e5d
2 изменённых файлов: 11 добавлений и 2 удалений

Просмотреть файл

@ -342,7 +342,12 @@ function REPLServer(prompt,
self.bufferedCommand = '';
// If we got any output - print it (if no error)
if (!e && (!self.ignoreUndefined || ret !== undefined)) {
if (!e &&
// When an invalid REPL command is used, error message is printed
// immediately. We don't have to print anything else. So, only when
// the second argument to this function is there, print it.
arguments.length === 2 &&
(!self.ignoreUndefined || ret !== undefined)) {
self.context._ = ret;
self.outputStream.write(self.writer(ret) + '\n');
}

Просмотреть файл

@ -189,7 +189,11 @@ function error_test() {
{ client: client_unix, send: 'url.format("http://google.com")',
expect: 'http://google.com/' },
{ client: client_unix, send: 'var path = 42; path',
expect: '42' }
expect: '42' },
// this makes sure that we don't print `undefined` when we actually print
// the error message
{ client: client_unix, send: '.invalid_repl_command',
expect: 'Invalid REPL keyword\n' + prompt_unix },
]);
}