1

I had like to wrap any JavaScript invocation at runtime, e.g. I had like to write to a log that an invocation of Func has been occurred.

This wrapping must work for any function even those function that has been added using eval or prototyping.

DuduAlul
  • 6,313
  • 7
  • 39
  • 63
  • You can't do this without writing it in C++ as a nodejs extension – Raynos Mar 03 '11 at 13:14
  • possible duplicate of [Adding console.log to every function automatically](http://stackoverflow.com/questions/5033836/adding-console-log-to-every-function-automatically) – Martin Jespersen Mar 03 '11 at 13:15
  • @Raynos , what about the client-side? I guess it's the same answer since it's the same v8? – DuduAlul Mar 03 '11 at 13:21
  • @MrOhad there is nothing you can hook into. You can edit global function but you can't do the same with local functions. You can write a firefox/chrome extension to hook into this for you ;) – Raynos Mar 03 '11 at 13:24
  • @Raynos if I could analyzed (statically) the code first I guess that would be possible, what do you think? – DuduAlul Mar 03 '11 at 13:45
  • 1
    @MrOhad By all means you can use a compiler on your js source to compile it to source that is logged. You can also plug a mod into the nodejs or V8 to allow hooking into function calls. Look at [node-proxy](https://github.com/isaacs/node-proxy) – Raynos Mar 03 '11 at 15:53
  • @Raynos, please add it as an answer and I will accept it.. – DuduAlul Mar 29 '11 at 17:20
  • @MrOhad node proxy only works with node.js – Raynos Mar 29 '11 at 18:41

2 Answers2

1

What your looking for is node-proxy

You can't do this using native JS. This will only work for node.js. It can probably be adjusted to work for any js running on V8.

Raynos
  • 166,823
  • 56
  • 351
  • 396
0

If you were to call your functions with the call method, you could do something like this:

oldCall = Function.prototype.call;
Function.prototype.call = function(){
 // do some logging here
 oldCall.apply(this, arguments);
}
Vincent
  • 1,126
  • 2
  • 10
  • 11