Skip to content

Commit

Permalink
[squash] hide internals better
Browse files Browse the repository at this point in the history
  • Loading branch information
addaleax committed Mar 1, 2018
1 parent 70457e0 commit 9cb8461
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
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')
};

0 comments on commit 9cb8461

Please sign in to comment.