Export to GitHub

fbug - issue #6184

Closure Inspector: named function expression scopes are duplicated


Posted on Jan 11, 2013 by Massive Wombat

Here is my code.

(function Scope1(a) { var a = 1; (function Scope2() { var b = 2; window.sum = function Func() { return a + b; }; })(); })();

When I inspect the scopes in the DOM panel, every scope is displayed twice, see the screenshot.

Honza

Attachments

Comment #1

Posted on Jan 11, 2013 by Massive Wombat

Note that this code is ok

(function(a) { var a = 1; (function() { var b = 2; window.sum = function Func() { return a + b; }; })(); })();

Honza

Comment #2

Posted on Jan 12, 2013 by Grumpy Camel

Interesting! If you could ask some SpiderMonkey folks about why that happens I'd be quite curious to hear the answer. Note that the following only shows "double scopes" at the innermost layer:

(function Scope1() { var a = 1; (function Scope2() { var b = 2; eval("var c = 3"); // <- mess with bindings somehow (function Scope3() { var d = 4; window.sum = function Func() { return a + b + c + d; }; })(); })(); })();

I suppose we could work around this by skipping single-variable scopes whose parents have the exact same list of variables? Or contain the variable, if we want to make (function() { var local; var f = function f() { window.a = }; })(); prettier.

Comment #3

Posted on Jan 13, 2013 by Grumpy Camel

Worked around in https://github.com/firebug/firebug/commit/b05d301d323c89d8b39b30435ea31296f8c61ded.

Comment #4

Posted on Jan 14, 2013 by Massive Wombat

It's much better, thanks!

I think that some info is still redundant and perhaps we could yet simplify it. Please take a look at the attached screenshot. Does it make sense?

Honza

Attachments

Comment #5

Posted on Jan 14, 2013 by Grumpy Camel

Hmmm, I dunno. Maybe. We'd have to hoist the function inwards, of course. Some counterpoints: * for increased visibility into the browser, it's better to expose exactly how scope chains look * it's per spec and user-noticable (e.g. (function f() { var f; return f; })() is undefined, though I don't see many useful cases) * we couldn't reliably do it when the (probably?) bug gets fixed * it makes it clearer which function the scope belongs to * the code for it is a bit complicated

Comment #6

Posted on Jan 15, 2013 by Grumpy Camel

Ah, https://bugzilla.mozilla.org/show_bug.cgi?id=822566.

Comment #7

Posted on Jan 15, 2013 by Grumpy Camel

Ported with issue 5873.

Comment #8

Posted on Jan 18, 2013 by Helpful Wombat

(No comment was entered for this change.)

Comment #9

Posted on Jan 18, 2013 by Massive Wombat

This issue has been fixed in Firebug 1.11.2 beta 1 https://getfirebug.com/releases/firebug/1.11/firebug-1.11.2b1.xpi

Please try it and let us know how it works for you.

Thanks for the help! Honza

Comment #10

Posted on Feb 20, 2013 by Helpful Wombat

If we still require the Firefox bug to be fixed, it should be mentioned in the comment to the code.

Sebastian

Comment #11

Posted on Feb 20, 2013 by Grumpy Camel

Don't really require it, no. I'll add a comment to back it out as soon as the bug gets fixed (I'm cc:ed).

Status: Fixed

Labels:
Type-Defect dom ported-1.11 platform closureinspector fixed-1.11.2-b1