Closed Bug 786711 Opened 12 years ago Closed 12 years ago

Stack frame listed as anonymous rather than the expected name

Categories

(DevTools :: Debugger, defect)

17 Branch
x86
macOS
defect
Not set
normal

Tracking

(Not tracked)

RESOLVED FIXED
Firefox 18

People

(Reporter: dangoor, Assigned: past)

References

()

Details

Attachments

(2 files)

STR:

1. go to http://todomvc.com/architecture-examples/backbone/
2. set a breakpoint in todo.js around line 21 (this.save in the toggle function)
3. add a todo item
4. click the checkbox to toggle it
5. note that the stack frames are all "anonymous" when what you really want is for the frames to have useful names

expected result:
the top frame should be called "toggle".
(In reply to Kevin Dangoor from comment #0)
> STR:
> 
> 1. go to http://todomvc.com/architecture-examples/backbone/
> 2. set a breakpoint in todo.js around line 21 (this.save in the toggle
> function)
> 3. add a todo item
> 4. click the checkbox to toggle it
> 5. note that the stack frames are all "anonymous" when what you really want
> is for the frames to have useful names
> 
> expected result:
> the top frame should be called "toggle".

The function is actually anonymous. "toggle" is the property name in the container object (app.Todo, or the thing that results via calling Backbone.Model.extend), which has the value of an anonymous function expression (not a named expression, and not a declaration).

This is less than optimal, for sure, but that's how js works.

So
{ foo: function(){} }
would create the anonymous function, via an anonymous function expression

and
{ foo: function bar(){} }
would create the function foo, via a named function expression
("the function bar", not "foo" in my last example)
Sure, I agree that the function is anonymous as far as JavaScript is concerned. As far as the user is concerned, however, it is not anonymous... it's "toggle". And, according to the other browser tools it's "toggle".
Alex, Jason: where are the statically-inferred names from bug 433529 surfacing in JS? Isn't fn.name updated with that information? Does that work cover the case in this bug?
fn.displayName is what you want. Jim says it's not in the protocol yet.
If you're using the C++ api, you can also use JS_GetFunctionDisplayId instead of JS_GetFunctionId
(In reply to Jason Orendorff [:jorendorff] from comment #5)
> fn.displayName is what you want. Jim says it's not in the protocol yet.

I wonder why this doesn't work then:

http://mxr.mozilla.org/mozilla-central/source/toolkit/devtools/debugger/server/dbg-script-actors.js#1688

Is displayName set on the prototype, when it's set by the engine?
Duh, probably because I'm using the Debugger API there...
Attached patch Simple fixSplinter Review
Thanks to Alex's work this was too easy. Try:
https://tbpl.mozilla.org/?tree=Try&rev=836b3125544e
Assignee: nobody → past
Status: NEW → ASSIGNED
Attachment #657798 - Flags: review?(rcampbell)
Comment on attachment 657798 [details] [diff] [review]
Simple fix

Since Rob is on PTO, maybe you guys can take a look at this. It's pretty simple actually.
Attachment #657798 - Flags: review?(vporof)
Attachment #657798 - Flags: review?(rcampbell)
Attachment #657798 - Flags: review?(mihai.sucan)
Comment on attachment 657798 [details] [diff] [review]
Simple fix

Review of attachment 657798 [details] [diff] [review]:
-----------------------------------------------------------------

Looks good to me.

::: browser/devtools/debugger/test/browser_dbg_displayName.js
@@ +58,5 @@
> +      is(frames.querySelectorAll(".dbg-stackframe").length, 3,
> +        "Should have three frames.");
> +
> +      is(frames.querySelector("#stackframe-0 .dbg-stackframe-name").getAttribute("value"),
> +        "a/<", "Frame name should be a/<");

I love the way these inferred names show up.
Attachment #657798 - Flags: review?(vporof) → review+
Comment on attachment 657798 [details] [diff] [review]
Simple fix

Looks good!
Attachment #657798 - Flags: review?(mihai.sucan) → review+
Whiteboard: [land-in-fx-team]
https://hg.mozilla.org/integration/fx-team/rev/20bb14ce0b55
Whiteboard: [land-in-fx-team] → [fixed-in-fx-team]
Comment on attachment 657798 [details] [diff] [review]
Simple fix

Review of attachment 657798 [details] [diff] [review]:
-----------------------------------------------------------------

::: toolkit/devtools/debugger/server/dbg-script-actors.js
@@ +1690,4 @@
>      let desc = aFunction.getOwnPropertyDescriptor("displayName");
>      if (desc && desc.value && typeof desc.value == "string") {
>        name = desc.value;
> +    } else if ("displayName" in aFunction) {

Every Debugger.Object instance should have a "displayName" property --- its value will be undefined, if we couldn't infer any name for it at all, but it will be present. So this 'in' test will always return true.
(In reply to Jim Blandy :jimb from comment #14)
> ::: toolkit/devtools/debugger/server/dbg-script-actors.js
> @@ +1690,4 @@
> >      let desc = aFunction.getOwnPropertyDescriptor("displayName");
> >      if (desc && desc.value && typeof desc.value == "string") {
> >        name = desc.value;
> > +    } else if ("displayName" in aFunction) {
> 
> Every Debugger.Object instance should have a "displayName" property --- its
> value will be undefined, if we couldn't infer any name for it at all, but it
> will be present. So this 'in' test will always return true.

OK, I just converted the "else if" to an "else" then.
Attachment #659984 - Flags: review?(jimb)
Comment on attachment 659984 [details] [diff] [review]
Remove redundant check

Review of attachment 659984 [details] [diff] [review]:
-----------------------------------------------------------------

displayName will still return null if the function is anonymous and SpiderMonkey couldn't infer a name for it. Is that all right?
Attachment #659984 - Flags: review?(jimb) → review+
(In reply to Jim Blandy :jimb from comment #17)
> Comment on attachment 659984 [details] [diff] [review]
> Remove redundant check
> 
> Review of attachment 659984 [details] [diff] [review]:
> -----------------------------------------------------------------
> 
> displayName will still return null if the function is anonymous and
> SpiderMonkey couldn't infer a name for it. Is that all right?

Yes, in that case the frontend will just display <anonymous> as before.
https://hg.mozilla.org/mozilla-central/rev/93e7a6cb66ff
Status: ASSIGNED → RESOLVED
Closed: 12 years ago
Resolution: --- → FIXED
Whiteboard: [fixed-in-fx-team]
Product: Firefox → DevTools
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: