Proposing a nice debugging feature
Preference, really, is to use the features of your debugger rather than modifying source. But for those times you need to modify source, why do we need new syntax for this? These seem sufficient:
if (typeof someVariable === 'undefined') debugger;
or
typeof someVariable === 'undefined' && debugger;
(since it's temporary throw-away code, style objections by some [like me] can be ignored...)
-- T.J. Crowder
Is something wrong with
if(condition) { debugger; }
?
You can implement the feature you propose in userland, except that you get one useless stack frame (but that can also be worked around if need be):
const debugIf = (b) => { if(b) { debugger; } }
debugIf(condition);
,
yeah it's maybe more a styling preference. I'm also thinking how browsers would behave case you have a forgotten debugger somewhere. Chrome skips debugger keywords if you don't have the developer tools pane open. The code might break or stop in some cases if it's inside an if block. Having the condition passed to the debugger could avoid that. Any thoughts? (of course forgotten debugger is stupid!)
On Wed, May 3, 2017 at 2:14 PM, somonek <somonek at gmail.com> wrote:
The code might break or stop in some cases if it's inside an if block.
Why would it do that? If debugger;
is being ignored, it'll be ignored
inside an if
block just as well as outside it, without side-effects.
I think making debugger
a pseudo-function is unnecessary without a
stronger motivation. The closest I can come to a motivation for this is
that if you do your own debugif
function or similar, the condition needs
to be evaluated even if devtools isn't open, but in theory that evaluaton
could be skipped if the engine knew the condition was just for a debugger
statement that wasn't going to do anything. For me, that's not sufficient.
-- T.J. Crowder
Hello,
not sure if it's been already proposed maybe, but I have this in mind
debugger(/* condition */);
to stop on conditional breakpoint.
Example:
debugger(typeof someVariable === 'undefined');
What do you think?
Be well, Serghei