Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way set a break-point (eg. when named function is called) programatically?

I am working on some JavaScript - of course! - and am doing some debugging in Chrome.

Now, I would like to enable a break-point programatically when a function (with a given name) is called.

  1. It should function like a break-point. The debugger keyword always breaks (uhg!) and is an ugly artifact to put in and remove from code.

  2. It should not require manual source code navigation / interactivity. Since the source is combined through an automated build process this becomes a time-consuming endeavor.

Ideally it would be as something as simple and programatically controlled, eg.

Debugger.setBreakpoint({onFunction: "Foo.prototype.bar"})

Is there a way to set a break-point for when a particular (named) function is called without manual navigation of the currently loaded script?

If not as envisioned programatically, is there a way to set a break-point via a comment? (Break-point, not debugger-break.)

(I am amendable to using similar developer tools in another browser, as long as it runs on Windows - but a Chrome solution, if such exists, is ideal.)

like image 205
user2864740 Avatar asked Dec 26 '22 03:12

user2864740


1 Answers

In Chrome Developer Tool you can use debug(function) statement to invoke function and break inside of it.

One more way if you have a exact function reference
var func = function(){ if (arguments.callee._debug) { debugger; } }

set _debug flag to true
func._debug = true

then function func() will be stopped. It's tricky and this will not work it strict mode.

like image 69
Pavel Birukov Avatar answered Dec 30 '22 10:12

Pavel Birukov