Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[squash] hide internals better
  • Loading branch information
addaleax committed Mar 1, 2018
commit 9cb8461f87135550aed69271faa8d93406f5a02c
9 changes: 5 additions & 4 deletions lib/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,6 @@ function enhanceStackTrace(err, own) {
err.stack = err.stack + sep + ownStack.join('\n');
}

const kExpandStack = Symbol('kExpandStack');
Object.defineProperty(EventEmitter, 'kExpandStack', { value: kExpandStack });

EventEmitter.prototype.emit = function emit(type, ...args) {
let doError = (type === 'error');

Expand All @@ -167,9 +164,13 @@ EventEmitter.prototype.emit = function emit(type, ...args) {
er = args[0];
if (er instanceof Error) {
try {
const { kExpandStackSymbol } = require('internal/util');
const capture = {};
Error.captureStackTrace(capture, EventEmitter.prototype.emit);
er[kExpandStack] = enhanceStackTrace.bind(null, er, capture);
Object.defineProperty(er, kExpandStackSymbol, {
value: enhanceStackTrace.bind(null, er, capture),
configurable: true
});
} catch (e) {}

// Note: The comments on the `throw` lines are intentional, they show
Expand Down
6 changes: 3 additions & 3 deletions lib/internal/bootstrap_node.js
Original file line number Diff line number Diff line change
Expand Up @@ -459,9 +459,9 @@
// nothing to be done about it at this point.
}
try {
const { kExpandStack } = NativeModule.require('events');
if (typeof er[kExpandStack] === 'function')
er[kExpandStack]();
const { kExpandStackSymbol } = NativeModule.require('internal/util');
if (typeof er[kExpandStackSymbol] === 'function')
er[kExpandStackSymbol]();
} catch (er) {}
return false;
}
Expand Down
3 changes: 2 additions & 1 deletion lib/internal/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -371,5 +371,6 @@ module.exports = {

// Used by the buffer module to capture an internal reference to the
// default isEncoding implementation, just in case userland overrides it.
kIsEncodingSymbol: Symbol('node.isEncoding')
kIsEncodingSymbol: Symbol('kIsEncodingSymbol'),
kExpandStackSymbol: Symbol('kExpandStackSymbol')
};