summaryrefslogtreecommitdiff
path: root/lib/events.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/events.js')
-rw-r--r--lib/events.js13
1 files changed, 8 insertions, 5 deletions
diff --git a/lib/events.js b/lib/events.js
index 438c8f8306..6f279a0bff 100644
--- a/lib/events.js
+++ b/lib/events.js
@@ -26,10 +26,14 @@ const { Math, Object, Reflect } = primordials;
var spliceOne;
const {
+ kEnhanceStackBeforeInspector,
+ codes
+} = require('internal/errors');
+const {
ERR_INVALID_ARG_TYPE,
ERR_OUT_OF_RANGE,
ERR_UNHANDLED_ERROR
-} = require('internal/errors').codes;
+} = codes;
const {
inspect
@@ -142,8 +146,8 @@ function enhanceStackTrace(err, own) {
ownStack.splice(off + 1, len - 2,
' [... lines matching original stack trace ...]');
}
- // Do this last, because it is the only operation with side effects.
- err.stack = err.stack + sep + ownStack.join('\n');
+
+ return err.stack + sep + ownStack.join('\n');
}
EventEmitter.prototype.emit = function emit(type, ...args) {
@@ -162,11 +166,10 @@ EventEmitter.prototype.emit = function emit(type, ...args) {
er = args[0];
if (er instanceof Error) {
try {
- const { kExpandStackSymbol } = require('internal/util');
const capture = {};
// eslint-disable-next-line no-restricted-syntax
Error.captureStackTrace(capture, EventEmitter.prototype.emit);
- Object.defineProperty(er, kExpandStackSymbol, {
+ Object.defineProperty(er, kEnhanceStackBeforeInspector, {
value: enhanceStackTrace.bind(null, er, capture),
configurable: true
});