mirror of
https://github.com/nodejs/node.git
synced 2025-05-04 04:43:16 +00:00

Store all primordials as properties of the primordials object. Static functions are prefixed by the constructor's name and prototype methods are prefixed by the constructor's name followed by "Prototype". For example: primordials.Object.keys becomes primordials.ObjectKeys. PR-URL: https://github.com/nodejs/node/pull/30610 Refs: https://github.com/nodejs/node/issues/29766 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
52 lines
1.2 KiB
JavaScript
52 lines
1.2 KiB
JavaScript
'use strict';
|
|
|
|
const {
|
|
ObjectCreate,
|
|
} = primordials;
|
|
|
|
const REPL = require('repl');
|
|
const { kStandaloneREPL } = require('internal/repl/utils');
|
|
|
|
module.exports = ObjectCreate(REPL);
|
|
module.exports.createInternalRepl = createRepl;
|
|
|
|
function createRepl(env, opts, cb) {
|
|
if (typeof opts === 'function') {
|
|
cb = opts;
|
|
opts = null;
|
|
}
|
|
opts = {
|
|
[kStandaloneREPL]: true,
|
|
ignoreUndefined: false,
|
|
useGlobal: true,
|
|
breakEvalOnSigint: true,
|
|
...opts
|
|
};
|
|
|
|
if (parseInt(env.NODE_NO_READLINE)) {
|
|
opts.terminal = false;
|
|
}
|
|
|
|
if (env.NODE_REPL_MODE) {
|
|
opts.replMode = {
|
|
'strict': REPL.REPL_MODE_STRICT,
|
|
'sloppy': REPL.REPL_MODE_SLOPPY
|
|
}[env.NODE_REPL_MODE.toLowerCase().trim()];
|
|
}
|
|
|
|
if (opts.replMode === undefined) {
|
|
opts.replMode = REPL.REPL_MODE_SLOPPY;
|
|
}
|
|
|
|
const historySize = Number(env.NODE_REPL_HISTORY_SIZE);
|
|
if (!Number.isNaN(historySize) && historySize > 0) {
|
|
opts.historySize = historySize;
|
|
} else {
|
|
opts.historySize = 1000;
|
|
}
|
|
|
|
const repl = REPL.start(opts);
|
|
const term = 'terminal' in opts ? opts.terminal : process.stdout.isTTY;
|
|
repl.setupHistory(term ? env.NODE_REPL_HISTORY : '', cb);
|
|
}
|