11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ci
31cb0ef41Sopenharmony_ciconst {
41cb0ef41Sopenharmony_ci  Number,
51cb0ef41Sopenharmony_ci  NumberIsNaN,
61cb0ef41Sopenharmony_ci  NumberParseInt,
71cb0ef41Sopenharmony_ci  ObjectCreate,
81cb0ef41Sopenharmony_ci} = primordials;
91cb0ef41Sopenharmony_ci
101cb0ef41Sopenharmony_ciconst REPL = require('repl');
111cb0ef41Sopenharmony_ciconst { kStandaloneREPL } = require('internal/repl/utils');
121cb0ef41Sopenharmony_ci
131cb0ef41Sopenharmony_cimodule.exports = ObjectCreate(REPL);
141cb0ef41Sopenharmony_cimodule.exports.createInternalRepl = createRepl;
151cb0ef41Sopenharmony_ci
161cb0ef41Sopenharmony_cifunction createRepl(env, opts, cb) {
171cb0ef41Sopenharmony_ci  if (typeof opts === 'function') {
181cb0ef41Sopenharmony_ci    cb = opts;
191cb0ef41Sopenharmony_ci    opts = null;
201cb0ef41Sopenharmony_ci  }
211cb0ef41Sopenharmony_ci  opts = {
221cb0ef41Sopenharmony_ci    [kStandaloneREPL]: true,
231cb0ef41Sopenharmony_ci    ignoreUndefined: false,
241cb0ef41Sopenharmony_ci    useGlobal: true,
251cb0ef41Sopenharmony_ci    breakEvalOnSigint: true,
261cb0ef41Sopenharmony_ci    ...opts,
271cb0ef41Sopenharmony_ci  };
281cb0ef41Sopenharmony_ci
291cb0ef41Sopenharmony_ci  if (NumberParseInt(env.NODE_NO_READLINE)) {
301cb0ef41Sopenharmony_ci    opts.terminal = false;
311cb0ef41Sopenharmony_ci  }
321cb0ef41Sopenharmony_ci
331cb0ef41Sopenharmony_ci  if (env.NODE_REPL_MODE) {
341cb0ef41Sopenharmony_ci    opts.replMode = {
351cb0ef41Sopenharmony_ci      'strict': REPL.REPL_MODE_STRICT,
361cb0ef41Sopenharmony_ci      'sloppy': REPL.REPL_MODE_SLOPPY,
371cb0ef41Sopenharmony_ci    }[env.NODE_REPL_MODE.toLowerCase().trim()];
381cb0ef41Sopenharmony_ci  }
391cb0ef41Sopenharmony_ci
401cb0ef41Sopenharmony_ci  if (opts.replMode === undefined) {
411cb0ef41Sopenharmony_ci    opts.replMode = REPL.REPL_MODE_SLOPPY;
421cb0ef41Sopenharmony_ci  }
431cb0ef41Sopenharmony_ci
441cb0ef41Sopenharmony_ci  const historySize = Number(env.NODE_REPL_HISTORY_SIZE);
451cb0ef41Sopenharmony_ci  if (!NumberIsNaN(historySize) && historySize > 0) {
461cb0ef41Sopenharmony_ci    opts.historySize = historySize;
471cb0ef41Sopenharmony_ci  } else {
481cb0ef41Sopenharmony_ci    opts.historySize = 1000;
491cb0ef41Sopenharmony_ci  }
501cb0ef41Sopenharmony_ci
511cb0ef41Sopenharmony_ci  const repl = REPL.start(opts);
521cb0ef41Sopenharmony_ci  const term = 'terminal' in opts ? opts.terminal : process.stdout.isTTY;
531cb0ef41Sopenharmony_ci  repl.setupHistory(term ? env.NODE_REPL_HISTORY : '', cb);
541cb0ef41Sopenharmony_ci}
55