On Saturday, July 19, 2014 12:15:23 AM UTC+2, San wrote:
>
> I just learned something very basic about a limitation of Firebug -- so 
> basic that I suspect almost everyone here already knew this. I'm only 
> posting it here (at the risk of seeming rather ignorant) because I want to 
> make sure I don't misunderstand the situation.
>
> I have a method that, depending on where it's called from, sometimes 
> reports a meaningful caller and stack trace, and sometimes not. I 
> originally put this into my JavaScript file:
>
> console.info( 
>    if( arguments.callee.caller.name ) {
>          " layout.adjust has been called by: " + 
> arguments.callee.caller.name
>       } else {
>         " layout.adjust caller is unclear, so here's a stack trace: "
>             console.trace() }
> )    // end console.info
>
> The above didn't work; the console just reported a syntax error
>

As the error indicates you have a JavaScript syntax error in your script. 
The point here is that JavaScript doesn't allow to have if blocks or loops 
as function parameters. You need to use the ternery operator instead to 
achieve this:

console.info(
    arguments.callee.caller.name ?
    " layout.adjust has been called by: " + arguments.callee.caller.name :
    " layout.adjust caller is unclear, so here's a stack trace: " + console.
trace()
)

(with no further explanation)
>
The unclear syntax error message comes from Firefox. Firebug just displays 
it. I created bug 1041426 
<https://bugzilla.mozilla.org/show_bug.cgi?id=1041426> asking to improve it.
 

> BTW, I also discovered while googling around that 
> 'arguments.callee.caller' is frowned upon (which I didn't know)
>
Right, you can read more about that at the Mozilla Developer Network 
<https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions_and_function_scope/arguments/callee>
.
 

> ; you're supposed to give a name to your anonymous function expression so 
> it ain't really anonymous and you can refer to it that way. But they seem 
> to be talking about function recursion, which I'm not doing, and also my 
> "functions" are really methods of my custom objects -- in this case  
> layout.adjust = function() { blah blah...
>
The function itself still doesn't have a name in this case. layout.adjust 
is just the variable that is holding the anonymous function. You may write 
this instead:

layout.adjust = function layout_adjust() { ... }

In the case of a function or method that can be called from various places 
> in various contexts, how do most Firebug users find out where it was called 
> from? I mean especially in cases where there's no reported caller or where 
> a stack trace is vague or uninformative.
>
The stack trace provides links at the right side pointing to were the 
functions were called. If you have a case where they are not shown or point 
to somewhere unexpected, please post a simple test case for this, so it can 
be investigated.

Instead of logging the stack trace to the console, you can also set a 
breakpoint at the first line of the function. When the breakpoint gets hit, 
you'll see the stack trace within the *Stack* side panel 
<https://getfirebug.com/wiki/index.php?title=Stack_Side_Panel>.

Sebastian

-- 
You received this message because you are subscribed to the Google Groups 
"Firebug" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/firebug.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/firebug/7167e0aa-6b70-412d-96d1-949f0cd221bd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to