summaryrefslogtreecommitdiff
path: root/lib/repl.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/repl.js')
-rw-r--r--lib/repl.js64
1 files changed, 31 insertions, 33 deletions
diff --git a/lib/repl.js b/lib/repl.js
index a6123d9389..bce90a1860 100644
--- a/lib/repl.js
+++ b/lib/repl.js
@@ -69,12 +69,15 @@ const CJSModule = require('internal/modules/cjs/loader').Module;
const domain = require('domain');
const debug = require('internal/util/debuglog').debuglog('repl');
const {
- ERR_CANNOT_WATCH_SIGINT,
- ERR_INVALID_ARG_TYPE,
- ERR_INVALID_REPL_EVAL_CONFIG,
- ERR_INVALID_REPL_INPUT,
- ERR_SCRIPT_EXECUTION_INTERRUPTED
-} = require('internal/errors').codes;
+ codes: {
+ ERR_CANNOT_WATCH_SIGINT,
+ ERR_INVALID_ARG_TYPE,
+ ERR_INVALID_REPL_EVAL_CONFIG,
+ ERR_INVALID_REPL_INPUT,
+ ERR_SCRIPT_EXECUTION_INTERRUPTED,
+ },
+ overrideStackTrace,
+} = require('internal/errors');
const { sendInspectorCommand } = require('internal/util/inspector');
const experimentalREPLAwait = require('internal/options').getOptionValue(
'--experimental-repl-await'
@@ -473,10 +476,29 @@ function REPLServer(prompt,
let errStack = '';
if (typeof e === 'object' && e !== null) {
- const pstrace = Error.prepareStackTrace;
- Error.prepareStackTrace = prepareStackTrace(pstrace);
+ overrideStackTrace.set(e, (error, stackFrames) => {
+ let frames;
+ if (typeof stackFrames === 'object') {
+ // Search from the bottom of the call stack to
+ // find the first frame with a null function name
+ const idx = stackFrames
+ .reverse()
+ .findIndex((frame) => frame.getFunctionName() === null);
+ // If found, get rid of it and everything below it
+ frames = stackFrames.splice(idx + 1);
+ } else {
+ frames = stackFrames;
+ }
+ // FIXME(devsnek): this is inconsistent with the checks
+ // that the real prepareStackTrace dispatch uses in
+ // lib/internal/errors.js.
+ if (typeof Error.prepareStackTrace === 'function') {
+ return Error.prepareStackTrace(error, frames);
+ }
+ frames.push(error);
+ return frames.reverse().join('\n at ');
+ });
decorateErrorStack(e);
- Error.prepareStackTrace = pstrace;
if (e.domainThrown) {
delete e.domain;
@@ -590,30 +612,6 @@ function REPLServer(prompt,
}
}
- function filterInternalStackFrames(structuredStack) {
- // Search from the bottom of the call stack to
- // find the first frame with a null function name
- if (typeof structuredStack !== 'object')
- return structuredStack;
- const idx = structuredStack.reverse().findIndex(
- (frame) => frame.getFunctionName() === null);
-
- // If found, get rid of it and everything below it
- structuredStack = structuredStack.splice(idx + 1);
- return structuredStack;
- }
-
- function prepareStackTrace(fn) {
- return (error, stackFrames) => {
- const frames = filterInternalStackFrames(stackFrames);
- if (fn) {
- return fn(error, frames);
- }
- frames.push(error);
- return frames.reverse().join('\n at ');
- };
- }
-
function _parseREPLKeyword(keyword, rest) {
const cmd = this.commands[keyword];
if (cmd) {