This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 224463 - Object literals declared in anonymous function appears as global in Navigator
Summary: Object literals declared in anonymous function appears as global in Navigator
Status: RESOLVED FIXED
Alias: None
Product: javascript
Classification: Unclassified
Component: Navigation (show other bugs)
Version: 7.3
Hardware: PC Linux
: P3 normal (vote)
Assignee: Petr Pisl
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-01-04 09:51 UTC by Vladimir Riha
Modified: 2015-08-05 01:19 UTC (History)
1 user (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
NetBeans 73RC2 JS Navigator - Closure ignored (288.06 KB, image/png)
2013-02-13 22:41 UTC, vezea
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Vladimir Riha 2013-01-04 09:51:14 UTC
Please try this:

function Test() {
    this.perform = function(data, callback) {
        callback.call(this);
    };
}

var test = new Test();

test.perform({}, function() {
    var c = {};
    c.name = "Test";
    alert(c.name);
});

The "c" is displayed as global variable in Navigator (but it is not purple and it is correctly not suggested in code completion for global variables). If the "c" is primitive or "instance" of some function, like:

var c = 1; 
// or
var c = new Date();

it is ok and Navigator does not show it.



Product Version: NetBeans IDE Dev (Build web-main-9627-on-20130103)
Java: 1.7.0_10; Java HotSpot(TM) Client VM 23.6-b04
Runtime: Java(TM) SE Runtime Environment 1.7.0_10-b18
System: Linux version 3.2.0-34-generic-pae running on i386; UTF-8; en_US (nb)
Comment 1 Vladimir Riha 2013-01-08 11:49:38 UTC
The same goes with immediate functions:

(function(){
var dir = {};
})();
Comment 2 Petr Pisl 2013-01-08 15:21:22 UTC
If we want to show objects that are defined in anonymous function, then there are displayed in global context. I don't know how to express that they are defined in the a anonymous function. I can switch off displaying such objects in navigator, but I'm not sure whether we want this. What do you think?
Comment 3 Vladimir Riha 2013-01-08 15:40:03 UTC
Aha, that's true, it's probably better to show it then. I don't know better way that wouldn't make Navigator confusing (maybe put them all into single "fake" item?). Then perhaps following 

test.perform({}, function() {
    var c = new Date();
});

should make c visible in Navigator as well although its not object literal.
Comment 4 vezea 2013-02-13 22:40:15 UTC
Is this issue related to the fact that the navigator in the latest 7.3 RCs seem to be ignoring closures altogether?

As of 7.2.1, it appears that any named function is listed at the top level of the navigator tree.  I'm not sure if this was a defect, but it turned out to be quite useful in keeping track of various closures and anonymous functions that tend to proliferate.

Is there some other pattern or plan to get the 7.3 navigator to pick up these references?
Comment 5 vezea 2013-02-13 22:41:18 UTC
Created attachment 131366 [details]
NetBeans 73RC2 JS Navigator - Closure ignored
Comment 6 Petr Pisl 2015-08-04 14:13:36 UTC
The closers are now displayed correctly -> closing this bug as fixed.
Comment 7 Quality Engineering 2015-08-05 01:19:23 UTC
Integrated into 'main-silver', will be available in build *201508050002* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)

Changeset: http://hg.netbeans.org/main-silver/rev/4d78597f26b0
User: Petr Pisl <ppisl@netbeans.org>
Log: #224463 - Object literals declared in anonymous function appears as global in Navigator