Skip to content

Commit

Permalink
Make it only declare globals once.
Browse files Browse the repository at this point in the history
  • Loading branch information
useafterfree authored Mar 3, 2018
1 parent c38768d commit 0b356d5
Showing 1 changed file with 36 additions and 27 deletions.
63 changes: 36 additions & 27 deletions debug.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,44 @@
module.exports = function (space, depth = 2) {
Object.defineProperty(global, '__stack', {
get: function () {
var orig = Error.prepareStackTrace;
Error.prepareStackTrace = function (_, stack) {

if (Object.getOwnPropertyDescriptor(global, '__stack') === undefined) {
Object.defineProperty(global, '__stack', {
get: function () {
var orig = Error.prepareStackTrace;
Error.prepareStackTrace = function (_, stack) {
return stack;
};
var err = new Error;
Error.captureStackTrace(err, arguments.callee);
var stack = err.stack;
Error.prepareStackTrace = orig;
return stack;
};
var err = new Error;
Error.captureStackTrace(err, arguments.callee);
var stack = err.stack;
Error.prepareStackTrace = orig;
return stack;
}
});
}
});
}

Object.defineProperty(global, '__line', {
get: function () {
return __stack[depth].getLineNumber();
}
});
if (Object.getOwnPropertyDescriptor(global, '__line') === undefined) {
Object.defineProperty(global, '__line', {
get: function () {
return __stack[depth].getLineNumber();
}
});
}

Object.defineProperty(global, '__function', {
get: function () {
return __stack[depth].getFunctionName();
}
});
if (Object.getOwnPropertyDescriptor(global, '__function') === undefined) {
Object.defineProperty(global, '__function', {
get: function () {
return __stack[depth].getFunctionName();
}
});
}

Object.defineProperty(global, '__file', {
get: function () {
return __stack[depth].getFileName();
}
});
if (Object.getOwnPropertyDescriptor(global, '__file') === undefined) {
Object.defineProperty(global, '__file', {
get: function () {
return __stack[depth].getFileName();
}
});
}

function censor(censor) {
var i = 0;
Expand Down

0 comments on commit 0b356d5

Please sign in to comment.