Closed Bug 1442398 Opened 7 years ago Closed 7 years ago

'gBrowser is null' logs showing up during testing

Categories

(Firefox :: Tabbed Browser, defect, P1)

defect

Tracking

()

RESOLVED FIXED
Firefox 60
Tracking Status
firefox60 --- fixed

People

(Reporter: bgrins, Assigned: dao)

References

Details

Attachments

(1 file)

STR: Run `./mach test accessible/tests/mochitest/states/test_expandable.xul`

I see a log like:

GECKO(12686) | JavaScript error: chrome://browser/content/tabbrowser.js, line 5652: TypeError: gBrowser is null

I think what's happening here is that the TabProgressListener is initialized in the TabBrowser constructur, but gBrowser isn't yet assigned to the instance of the TabBrowser until after the constructor finishes. I can think of two relatively easy fixes:

1) Make the TabBrowser constructor do much less and then instantiate gBrowser in two steps as `gBrowser = new TabBrowser(); gBrowser.init()`
2) Pass `this` (i.e. the TabBrowser) into the TabProgressListener constructor and refer to that on the instance instead of the global gBrowser.
Assignee: nobody → dao+bmo
Priority: -- → P1
Blocks: 1442384
Blocks: 1443318
(In reply to Brian Grinstead [:bgrins] from comment #0)
> 1) Make the TabBrowser constructor do much less and then instantiate
> gBrowser in two steps as `gBrowser = new TabBrowser(); gBrowser.init()`

I'll do this, and use the opportunity to convert TabBrowser to a plain object.

> 2) Pass `this` (i.e. the TabBrowser) into the TabProgressListener
> constructor and refer to that on the instance instead of the global gBrowser.

We did this before but I think it's less preferable, as this problem might bite us again with other consumers. Or it already does, see bug 1442384 and bug 1443318. Not entirely sure if these are exactly the same issue, though. Will re-evaluate once this is fixed.
Comment on attachment 8956385 [details]
Bug 1442398 - Convert the TabBrowser class to a plain object and make gBrowser available already before gBrowser.init returns.

https://reviewboard.mozilla.org/r/225264/#review231468

::: browser/base/content/browser.js:157
(Diff revision 1)
> +    }
> +    delete window.gBrowser;
> +    window.gBrowser = window._gBrowser;
> +    delete window._gBrowser;
> +    gBrowser.init();
> +    return window.gBrowser;

nit: we refer to this as `gBrowser` without window on the line above - we should be consistent and either `return gBrowser` here or do `window.gBrowser.init();` above.
Attachment #8956385 - Flags: review?(bgrinstead) → review+
Pushed by dgottwald@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/f27d7eca013d
Convert the TabBrowser class to a plain object and make gBrowser available already before gBrowser.init returns. r=bgrins
https://hg.mozilla.org/mozilla-central/rev/f27d7eca013d
Status: NEW → RESOLVED
Closed: 7 years ago
Resolution: --- → FIXED
Target Milestone: --- → Firefox 60
No longer blocks: 1444165
Depends on: 1444510
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: