Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
b187d16
src: externalized messages support, 2nd pass
jasnell Jan 7, 2016
6401743
src: externalize debugger.js messages
jasnell Jan 8, 2016
3fcddc4
src: externalized _debug_agent.js messages
jasnell Jan 8, 2016
503092e
test, src: add test-internal-messages.js, address nits
jasnell Jan 8, 2016
4359ec9
src: fix lint issue
jasnell Jan 8, 2016
c48ec49
src: externalize lib/_http_agent.js messages
jasnell Jan 8, 2016
112b084
src: externalize _http_client.js messages
jasnell Jan 8, 2016
8538841
src: externalize _http_outgoing.js messages, address nits
jasnell Jan 8, 2016
ff170ed
src: remove NODE_ prefix from message identifiers
jasnell Jan 8, 2016
bdca377
src: externalize _http_server.js messages
jasnell Jan 8, 2016
b270571
src: externalize _linklist.js messages
jasnell Jan 8, 2016
1b1e228
src: externalize _stream_readable.js messages
jasnell Jan 8, 2016
ee2228d
src: externalize _stream_transform.js messages
jasnell Jan 8, 2016
71d1fae
src: externalize _stream_wrap.js messages
jasnell Jan 8, 2016
eb882bc
src: externalized _stream_writable.js messages
jasnell Jan 8, 2016
0de2994
tools: enable restParams for eslint
jasnell Jan 8, 2016
0f0298e
src: externalize _tls_legacy.js messages, refactor debug
jasnell Jan 8, 2016
f095579
src: externalize _tls_wrap.js messages
jasnell Jan 9, 2016
62f6ec9
src: externalize assert.js messages
jasnell Jan 9, 2016
5d73fb3
src: externalize buffer.js messages
jasnell Jan 9, 2016
b1bc41f
src: externalize child-process.js messages
jasnell Jan 9, 2016
018472b
src: externalize cluster.js messages
jasnell Jan 9, 2016
7aa5d4f
src: externalize console.js messages
jasnell Jan 9, 2016
20640e8
src: externalize crypto.js messages
jasnell Jan 9, 2016
78b9090
src: externalize dgram.js messages
jasnell Jan 9, 2016
82679a5
src: externalize dns.js messages
jasnell Jan 9, 2016
649721b
src: externalize events.js messages
jasnell Jan 9, 2016
11b96dc
src: externalize fs.js messages
jasnell Jan 9, 2016
abc08a9
src: externalize http.js messages
jasnell Jan 9, 2016
0b9c3af
src: externalize https.js messages
jasnell Jan 9, 2016
0e8b40a
src: externalize module.js messages
jasnell Jan 9, 2016
650ab1c
src: externalize net.js messages
jasnell Jan 9, 2016
d89c414
src: externalize os.js messages
jasnell Jan 9, 2016
181e5c6
src: externalize path.js messages
jasnell Jan 9, 2016
b1ca5e1
src: externalize punycode.js messages
jasnell Jan 9, 2016
55fa5d8
src: externalize readline.js messages
jasnell Jan 9, 2016
5f4861d
src: externalize repl.js messages
jasnell Jan 9, 2016
67185ec
src: externalize string_decoder.js messages
jasnell Jan 9, 2016
f0c5782
src: externalize sys.js messages
jasnell Jan 9, 2016
497329f
src: externalized timers.js messages
jasnell Jan 9, 2016
e142e8a
src: externalize tls.js messages
jasnell Jan 9, 2016
678e8e8
src: externalize url.js messages
jasnell Jan 9, 2016
0a197c8
src: externalize util.js messages
jasnell Jan 9, 2016
cd4db97
src: externalize zlib.js messages
jasnell Jan 9, 2016
61240ea
src: externalize internal/child_process.js messages
jasnell Jan 9, 2016
259a36d
src: externalize internal/repl.js messages
jasnell Jan 9, 2016
96aa61f
src: externalize internal/socket_list.js messages
jasnell Jan 9, 2016
b885af3
src: externalize internal/v8_prof_polyfill.js messages
jasnell Jan 9, 2016
924aa9d
src: externalize additional messages missed
jasnell Jan 9, 2016
086bd73
src: avoid runtime calls
jasnell Jan 9, 2016
46fcb2d
src: code cleanup
jasnell Jan 9, 2016
edcb53b
src: refactor I18N.Error, I18N.TypeError and I18N.RangeError
jasnell Jan 10, 2016
42b7c7f
src: internal/messages.js code cleanup
jasnell Jan 10, 2016
21b1d95
src: begin externalizing src/* messages
jasnell Jan 10, 2016
5545855
src: externalize more native strings
jasnell Jan 11, 2016
08866a3
src: support varargs in messages, externalize src/node_dtrace.cc
jasnell Jan 11, 2016
44cc074
src: refactor macros to make env explicit, externalize node_file.cc
jasnell Jan 11, 2016
a5d97de
src: externalize additional src/*.cc files
jasnell Jan 11, 2016
9fc6ec1
src: externalize remaining errors in src/*.cc
jasnell Jan 11, 2016
92df8e6
src: externalize node.cc messages and print help, cleanups
jasnell Jan 11, 2016
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
src: externalize repl.js messages
  • Loading branch information
jasnell committed Jan 11, 2016
commit 5f4861dc8c79c7fd4a08f47eb9e4fd9604f1ac6d
59 changes: 30 additions & 29 deletions lib/repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

'use strict';

const I18N = require('internal/messages');
const debug = I18N.debuglog('repl');
const internalModule = require('internal/module');
const internalUtil = require('internal/util');
const util = require('util');
Expand All @@ -33,7 +35,6 @@ const Interface = require('readline').Interface;
const Console = require('console').Console;
const Module = require('module');
const domain = require('domain');
const debug = util.debuglog('repl');

const parentModule = module;
const replMap = new WeakMap();
Expand Down Expand Up @@ -70,8 +71,7 @@ exports._builtinLibs = ['assert', 'buffer', 'child_process', 'cluster',
'string_decoder', 'tls', 'tty', 'url', 'util', 'v8', 'vm', 'zlib'];


const BLOCK_SCOPED_ERROR = 'Block-scoped declarations (let, ' +
'const, function, class) not yet supported outside strict mode';
const BLOCK_SCOPED_ERROR = I18N(I18N.REPL_BLOCK_SCOPED);


class LineParser {
Expand Down Expand Up @@ -185,7 +185,7 @@ function REPLServer(prompt,
dom = options.domain;
replMode = options.replMode;
} else if (typeof prompt !== 'string') {
throw new Error('An options Object, or a prompt String are required');
throw I18N.Error(I18N.REPL_OPTIONS_OR_PROMPT_REQUIRED);
} else {
options = {};
}
Expand Down Expand Up @@ -227,7 +227,7 @@ function REPLServer(prompt,
displayErrors: false
});
} catch (e) {
debug('parse error %j', code, e);
debug(I18N.REPL_DEBUG_PARSE_ERROR, JSON.stringify(code), e);
if (self.replMode === exports.REPL_MODE_MAGIC &&
e.message === BLOCK_SCOPED_ERROR &&
!retry) {
Expand Down Expand Up @@ -256,7 +256,7 @@ function REPLServer(prompt,
} catch (e) {
err = e;
if (err && process.domain) {
debug('not recoverable, send to domain');
debug(I18N.REPL_DEBUG_NOT_RECOVERABLE);
process.domain.emit('error', err);
process.domain.exit();
return;
Expand All @@ -276,7 +276,7 @@ function REPLServer(prompt,
self.eval = self._domain.bind(eval_);

self._domain.on('error', function(e) {
debug('domain error');
debug(I18N.REPL_DEBUG_DOMAIN_ERROR);
const top = replMap.get(self);
internalUtil.decorateErrorStack(e);
top.outputStream.write((e.stack || e) + '\n');
Expand Down Expand Up @@ -360,7 +360,7 @@ function REPLServer(prompt,
sawSIGINT = false;
return;
}
self.output.write('(To exit, press ^C again or type .exit)\n');
self.output.write(`${I18N(I18N.REPL_EXIT)}\n`);
sawSIGINT = true;
} else {
sawSIGINT = false;
Expand All @@ -373,7 +373,7 @@ function REPLServer(prompt,
});

self.on('line', function(cmd) {
debug('line %j', cmd);
debug(I18N.REPL_DEBUG_LINE, JSON.stringify(cmd));
sawSIGINT = false;
var skipCatchall = false;

Expand All @@ -393,7 +393,7 @@ function REPLServer(prompt,
if (self.parseREPLKeyword(keyword, rest) === true) {
return;
} else if (!self.bufferedCommand) {
self.outputStream.write('Invalid REPL keyword\n');
self.outputStream.write(`${I18N(I18N.REPL_INVALID_KEYWORD)}\n`);
skipCatchall = true;
}
}
Expand All @@ -413,20 +413,18 @@ function REPLServer(prompt,
evalCmd = evalCmd + '\n';
}

debug('eval %j', evalCmd);
debug(I18N.REPL_DEBUG_EVAL, JSON.stringify(evalCmd));
self.eval(evalCmd, self.context, 'repl', finish);
} else {
finish(null);
}

function finish(e, ret) {
debug('finish', e, ret);
debug(I18N.REPL_DEBUG_FINISH, e, ret);
self.memory(cmd);

if (e && !self.bufferedCommand && cmd.trim().match(/^npm /)) {
self.outputStream.write('npm should be run outside of the ' +
'node repl, in your normal shell.\n' +
'(Press Control-D to exit.)\n');
self.outputStream.write(`${I18N(I18N.REPL_NPM_OUTSIDE)}\n`);
self.lineParser.reset();
self.bufferedCommand = '';
self.displayPrompt();
Expand Down Expand Up @@ -907,7 +905,7 @@ REPLServer.prototype.defineCommand = function(keyword, cmd) {
if (typeof cmd === 'function') {
cmd = {action: cmd};
} else if (typeof cmd.action !== 'function') {
throw new Error('Bad argument, "action" command must be a function');
throw I18N.Error(I18N.FUNCTION_REQUIRED, 'action');
}
this.commands[keyword] = cmd;
};
Expand Down Expand Up @@ -1010,7 +1008,7 @@ function addStandardGlobals(completionGroups, filter) {

function defineDefaultCommands(repl) {
repl.defineCommand('break', {
help: 'Sometimes you get stuck, this gets you out',
help: I18N(I18N.REPL_COMMAND_BREAK),
action: function() {
this.lineParser.reset();
this.bufferedCommand = '';
Expand All @@ -1020,32 +1018,32 @@ function defineDefaultCommands(repl) {

var clearMessage;
if (repl.useGlobal) {
clearMessage = 'Alias for .break';
clearMessage = I18N(I18N.REPL_COMMAND_CLEAR_GLOBAL);
} else {
clearMessage = 'Break, and also clear the local context';
clearMessage = I18N(I18N.REPL_COMMAND_CLEAR);
}
repl.defineCommand('clear', {
help: clearMessage,
action: function() {
this.lineParser.reset();
this.bufferedCommand = '';
if (!this.useGlobal) {
this.outputStream.write('Clearing context...\n');
this.outputStream.write(`${I18N(I18N.REPL_COMMAND_CLEAR_MSG)}\n`);
this.resetContext();
}
this.displayPrompt();
}
});

repl.defineCommand('exit', {
help: 'Exit the repl',
help: I18N(I18N.REPL_COMMAND_EXIT),
action: function() {
this.close();
}
});

repl.defineCommand('help', {
help: 'Show repl options',
help: I18N(I18N.REPL_COMMAND_HELP),
action: function() {
var self = this;
Object.keys(this.commands).sort().forEach(function(name) {
Expand All @@ -1057,20 +1055,22 @@ function defineDefaultCommands(repl) {
});

repl.defineCommand('save', {
help: 'Save all evaluated commands in this REPL session to a file',
help: I18N(I18N.REPL_COMMAND_SAVE),
action: function(file) {
try {
fs.writeFileSync(file, this.lines.join('\n') + '\n');
this.outputStream.write('Session saved to:' + file + '\n');
this.outputStream.write(
`${I18N(I18N.REPL_COMMAND_SESSION_SAVED, file)}\n`);
} catch (e) {
this.outputStream.write('Failed to save:' + file + '\n');
this.outputStream.write(
`${I18N(I18N.REPL_COMMAND_SAVE_FAILED, file)}\n`);
}
this.displayPrompt();
}
});

repl.defineCommand('load', {
help: 'Load JS from a file into the REPL session',
help: I18N(I18N.REPL_COMMAND_LOAD),
action: function(file) {
try {
var stats = fs.statSync(file);
Expand All @@ -1085,11 +1085,12 @@ function defineDefaultCommands(repl) {
}
});
} else {
this.outputStream.write('Failed to load:' + file +
' is not a valid file\n');
this.outputStream.write(
`${I18N(I18N.REPL_COMMAND_LOAD_FAILED_INVALID, file)}\n`);
}
} catch (e) {
this.outputStream.write('Failed to load:' + file + '\n');
this.outputStream.write(
`${I18N(I18N.REPL_COMMAND_LOAD_FAILED, file)}\n`);
}
this.displayPrompt();
}
Expand Down
31 changes: 30 additions & 1 deletion src/messages/en/messages.h
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,35 @@
"isFullWidthCodePoint is deprecated and will be removed.") \
XX(READLINE_STRIPVTCONTROLCHARACTERS_DEPRECATED, \
"stripVTControlCharacters is deprecated and will be removed.") \

XX(REPL_OPTIONS_OR_PROMPT_REQUIRED, \
"An options object, or a prompt string are required") \
XX(REPL_DEBUG_PARSE_ERROR, "parse error {0} {1}") \
XX(REPL_DEBUG_NOT_RECOVERABLE, "not recoverable, send to domain") \
XX(REPL_DEBUG_DOMAIN_ERROR, "domain error") \
XX(REPL_DEBUG_LINE, "line {0}") \
XX(REPL_DEBUG_EVAL, "eval {0}") \
XX(REPL_DEBUG_FINISH, "finish {0} {1}") \
XX(REPL_NPM_OUTSIDE, \
"npm should be run outside of the node repl, in your normal shell.\n" \
"(Press Control-D to exit.)") \
XX(REPL_BLOCK_SCOPED, \
"Block-scoped declarations (let, const, function, class) " \
"not yet supported outside strict mode") \
XX(REPL_EXIT, "(To exit, press ^C again or type .exit)") \
XX(REPL_INVALID_KEYWORD, "Invalid REPL keyword") \
XX(REPL_COMMAND_BREAK, "Sometimes you get stuck, this gets you out") \
XX(REPL_COMMAND_CLEAR_GLOBAL, "Alias for .break") \
XX(REPL_COMMAND_CLEAR, "Break, and also clear the local context") \
XX(REPL_COMMAND_CLEAR_MSG, "Clearing context...") \
XX(REPL_COMMAND_EXIT, "Exit the repl") \
XX(REPL_COMMAND_HELP, "Show repl options") \
XX(REPL_COMMAND_SAVE, \
"Save all evaluated commands in this REPL session to a file") \
XX(REPL_COMMAND_SESSION_SAVED, "Session saved to:{0}") \
XX(REPL_COMMAND_SAVE_FAILED, "Failed to save:{0}") \
XX(REPL_COMMAND_LOAD, "Load JS from a file into the REPL session") \
XX(REPL_COMMAND_LOAD_FAILED_INVALID, \
"Failed to load:{0} is not a valid file") \
XX(REPL_COMMAND_LOAD_FAILED, "Failed to load:{0}") \

#endif // SRC_NODE_MESSAGES_SRC_H_