11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ci
31cb0ef41Sopenharmony_cirequire('../common');
41cb0ef41Sopenharmony_ciconst ArrayStream = require('../common/arraystream');
51cb0ef41Sopenharmony_ciconst assert = require('assert');
61cb0ef41Sopenharmony_ciconst repl = require('repl');
71cb0ef41Sopenharmony_ci
81cb0ef41Sopenharmony_cilet evalCount = 0;
91cb0ef41Sopenharmony_cilet recovered = false;
101cb0ef41Sopenharmony_cilet rendered = false;
111cb0ef41Sopenharmony_ci
121cb0ef41Sopenharmony_cifunction customEval(code, context, file, cb) {
131cb0ef41Sopenharmony_ci  evalCount++;
141cb0ef41Sopenharmony_ci
151cb0ef41Sopenharmony_ci  return cb(evalCount === 1 ? new repl.Recoverable() : null, true);
161cb0ef41Sopenharmony_ci}
171cb0ef41Sopenharmony_ci
181cb0ef41Sopenharmony_ciconst putIn = new ArrayStream();
191cb0ef41Sopenharmony_ci
201cb0ef41Sopenharmony_ciputIn.write = function(msg) {
211cb0ef41Sopenharmony_ci  if (msg === '... ') {
221cb0ef41Sopenharmony_ci    recovered = true;
231cb0ef41Sopenharmony_ci  }
241cb0ef41Sopenharmony_ci
251cb0ef41Sopenharmony_ci  if (msg === 'true\n') {
261cb0ef41Sopenharmony_ci    rendered = true;
271cb0ef41Sopenharmony_ci  }
281cb0ef41Sopenharmony_ci};
291cb0ef41Sopenharmony_ci
301cb0ef41Sopenharmony_cirepl.start('', putIn, customEval);
311cb0ef41Sopenharmony_ci
321cb0ef41Sopenharmony_ci// https://github.com/nodejs/node/issues/2939
331cb0ef41Sopenharmony_ci// Expose recoverable errors to the consumer.
341cb0ef41Sopenharmony_ciputIn.emit('data', '1\n');
351cb0ef41Sopenharmony_ciputIn.emit('data', '2\n');
361cb0ef41Sopenharmony_ci
371cb0ef41Sopenharmony_ciprocess.on('exit', function() {
381cb0ef41Sopenharmony_ci  assert(recovered, 'REPL never recovered');
391cb0ef41Sopenharmony_ci  assert(rendered, 'REPL never rendered the result');
401cb0ef41Sopenharmony_ci  assert.strictEqual(evalCount, 2);
411cb0ef41Sopenharmony_ci});
42