Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

modify wrapFunction to use original function toString #9

Merged
merged 1 commit into from May 11, 2017

Conversation

sparr
Copy link
Contributor

@sparr sparr commented Oct 21, 2016

No description provided.

@@ -95,6 +95,14 @@ function wrapFunction(name, originalFunction) {

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

wrappedFunction.toString = function() {
return "// screeps-profiler wrapped function:\n" +
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should use string templating:

return `// screeps-profiler wrapped function:\n${originalFunction.toString()}`

@gdborton
Copy link
Collaborator

@sparr Could you provide me with your reason for this change? Example use case maybe?

@sparr
Copy link
Contributor Author

sparr commented Nov 30, 2016

The purpose of this is to re-enable the ability to put the name of a function/method into the console and get back its source.

@gdborton
Copy link
Collaborator

Ah, like typing Creep.prototype.work? I'm not sure what happened previously with Travis, but I've rerun the build. Could you update the linting issues?

@sparr
Copy link
Contributor Author

sparr commented Nov 30, 2016

I had the bad luck to upload this during the big DNS DDOS that affected github and a zillion other sites, so GH couldn't talk to Travis at the time. I'll make some changes when I can and re-commit. This is low priority right now because this functionality was ALSO later doubly-broken by some security changes in the core game. Devs have said it wasn't intentional but they aren't bringing it back yet, but now that the private server is open source I can submit a patch to them to fix it, too.

@gdborton
Copy link
Collaborator

@sparr poke. I've been trying to clean up the pending PRs. On this repo today, can you update the string and fix the linting issues?

/home/travis/build/gdborton/screeps-profiler/screeps-profiler.js
   78:7   error    'wrappedFunction' is never reassigned, use 'const' instead  prefer-const
   78:25  warning  Missing function expression name                            func-names
   78:33  error    Missing space before function parentheses                   space-before-function-paren
   99:30  warning  Missing function expression name                            func-names
   99:38  error    Missing space before function parentheses                   space-before-function-paren
  100:12  error    Strings must use singlequote                                quotes
  100:12  error    Unexpected string concatenation                             prefer-template
  106:1   error    Block must not be padded by blank lines                     padded-blocks

@sparr
Copy link
Contributor Author

sparr commented Apr 27, 2017

I haven't been playing screeps lately. Feel free to close this if you want. I'll come back to it some day, I hope.

@gdborton
Copy link
Collaborator

gdborton commented Apr 27, 2017 via email

…als.

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.
@gdborton gdborton merged commit 0eb2ed5 into screepers:master May 11, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants