Skip to content

Commit

Permalink
Replace toString of wrapper functions with the toString of the origin…
Browse files Browse the repository at this point in the history
…als. (#9)

Wrapping functions was making it difficult to call toString() on functions to
get their content, and led to harder debugging. By overriding the wrapper
function's toString, we're able to print out the original content of the
wrapped functions.
  • Loading branch information
sparr authored and gdborton committed May 11, 2017
1 parent 7c45be2 commit 0eb2ed5
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions screeps-profiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ const functionBlackList = [
];

function wrapFunction(name, originalFunction) {
return function wrappedFunction() {
function wrappedFunction() {
if (Profiler.isProfiling()) {
const nameMatchesFilter = name === getFilter();
const start = Game.cpu.getUsed();
Expand All @@ -94,7 +94,12 @@ function wrapFunction(name, originalFunction) {
}

return originalFunction.apply(this, arguments);
};
}

wrappedFunction.toString = () =>
`// screeps-profiler wrapped function:\n${originalFunction.toString()}`;

return wrappedFunction;
}

function hookUpPrototypes() {
Expand Down

0 comments on commit 0eb2ed5

Please sign in to comment.