Closed
Bug 1142563
Opened 9 years ago
Closed 9 years ago
Clean up global scope pollution from browser-loop.js
Categories
(Hello (Loop) :: Client, defect)
Hello (Loop)
Client
Tracking
(firefox40 fixed)
RESOLVED
FIXED
mozilla40
Tracking | Status | |
---|---|---|
firefox40 | --- | fixed |
People
(Reporter: dao, Assigned: zmiller12, Mentored)
Details
(Whiteboard: [good first bug][lang=js])
Attachments
(3 files, 3 obsolete files)
11.01 KB,
patch
|
Details | Diff | Splinter Review | |
1.18 KB,
patch
|
dao
:
review+
|
Details | Diff | Splinter Review |
1.16 KB,
patch
|
dao
:
review+
|
Details | Diff | Splinter Review |
For no good reason, browser-loop.js (http://mxr.mozilla.org/mozilla-central/source/browser/base/content/browser-loop.js) defines these things in the browser window's global scope that it shares with many other scripts: injectLoopAPI, LoopRooms, MozLoopService, PanelFrame. Instead, they should be set on the LoopUI object. e.g.: XPCOMUtils.defineLazyModuleGetter(this, "injectLoopAPI", "resource:///modules/loop/MozLoopAPI.jsm"); needs to move to the end of browser-loop.js and be replaced with this: XPCOMUtils.defineLazyModuleGetter(LoopUI, "injectLoopAPI", "resource:///modules/loop/MozLoopAPI.jsm"); and then, injectLoopAPI calls need to be replaced with calls to this.injectLoopAPI.
Reporter | ||
Comment 3•9 years ago
|
||
Comment on attachment 8577529 [details] [diff] [review] Bug1142563.diff Cleand up global scope pollution from browser-loop.js >+++ b/browser/base/content/browser-loop.js >@@ -1,19 +1,20 @@ > // This Source Code Form is subject to the terms of the Mozilla Public > // License, v. 2.0. If a copy of the MPL was not distributed with this > // file, You can obtain one at http://mozilla.org/MPL/2.0/. > > // the "exported" symbols > let LoopUI; > >-XPCOMUtils.defineLazyModuleGetter(this, "injectLoopAPI", "resource:///modules/loop/MozLoopAPI.jsm"); >+ > XPCOMUtils.defineLazyModuleGetter(this, "LoopRooms", "resource:///modules/loop/LoopRooms.jsm"); > XPCOMUtils.defineLazyModuleGetter(this, "MozLoopService", "resource:///modules/loop/MozLoopService.jsm"); > XPCOMUtils.defineLazyModuleGetter(this, "PanelFrame", "resource:///modules/PanelFrame.jsm"); >+XPCOMUtils.defineLazyModuleGetter(LoopUI, "injectLoopAPI", "resource:///modules/loop/MozLoopAPI.jsm"); good start, but there's more left to do: - LoopRooms, MozLoopService and PanelFrame need to be treated the same way you treated injectLoopAPI - All the XPCOMUtils.defineLazyModuleGetter calls need to be moved to the very end of the file
Attachment #8577529 -
Flags: feedback+
Attachment #8577529 -
Attachment is obsolete: true
Reporter | ||
Comment 5•9 years ago
|
||
I couldn't apply the patch... Is your source tree outdated? patching file browser/base/content/browser-loop.js Hunk #1 FAILED at 0 Hunk #6 FAILED at 185 Hunk #8 FAILED at 265
Attachment #8577646 -
Attachment is obsolete: true
Reporter | ||
Comment 8•9 years ago
|
||
Comment on attachment 8577699 [details] [diff] [review] Bug1142563.diff : Cleaned up global scope pollution from browser-loop.js > iframe.addEventListener("DOMContentLoaded", function documentDOMLoaded() { > iframe.removeEventListener("DOMContentLoaded", documentDOMLoaded, true); >- injectLoopAPI(iframe.contentWindow); >+ this.injectLoopAPI(iframe.contentWindow); > iframe.contentWindow.addEventListener("loopPanelInitialized", function loopPanelInitialized() { > iframe.contentWindow.removeEventListener("loopPanelInitialized", > loopPanelInitialized); > showTab(); > }); > }, true); This won't work, because 'this' is different within the anonymous function. You could refactor it like this: let documentDOMLoaded = () => { iframe.removeEventListener("DOMContentLoaded", documentDOMLoaded, true); this.injectLoopAPI(iframe.contentWindow); ... }; iframe.addEventListener("DOMContentLoaded", documentDOMLoaded, true);
Reporter | ||
Updated•9 years ago
|
Assignee: nobody → zmiller12
Thanks Dão, you have been really helpful. Ill give it a shot.
Assignee | ||
Comment 10•9 years ago
|
||
Attachment #8577699 -
Attachment is obsolete: true
Reporter | ||
Comment 11•9 years ago
|
||
Comment on attachment 8581237 [details] [diff] [review] Bug 1142563 Clean up global scope pollution from browser-loop.js Looks good at a first glance! I've pushed this to the try server; I suspect some tests depend on the global variables and will need to be updated. https://treeherder.mozilla.org/#/jobs?repo=try&revision=a9301cc1a83c
Reporter | ||
Comment 12•9 years ago
|
||
(In reply to Dão Gottwald [:dao] from comment #11) > Looks good at a first glance! I've pushed this to the try server; I suspect > some tests depend on the global variables and will need to be updated. > > https://treeherder.mozilla.org/#/jobs?repo=try&revision=a9301cc1a83c So there are errors in browser/components/loop/test/mochitest/head.js (line 122) and browser_toolbarbutton.js (lines 26, 78, 86, and 165). They all use MozLoopService. browser/components/loop/test/mochitest/head.js already imports MozLoopService.jsm and could be updated easily to define MozLoopService at the top of the file where LOOP_SESSION_TYPE and MozLoopServiceInternal are defined. That should fix these errors.
Reporter | ||
Comment 13•9 years ago
|
||
Zach, was comment 12 clear enough or do you need more information / better instructions?
Flags: needinfo?(zmiller12)
Assignee | ||
Comment 14•9 years ago
|
||
(In reply to Dão Gottwald [:dao] from comment #13) > Zach, was comment 12 clear enough or do you need more information / better > instructions? Dão, sorry I haven't been able to get back to you. Its the first week of spring term and I've been trying to calibrate myself. I'll take a look at it later today and get back to you ASAP.
Flags: needinfo?(zmiller12)
Reporter | ||
Comment 15•9 years ago
|
||
Take your time, just wanted to make sure you didn't get stuck.
Assignee | ||
Comment 16•9 years ago
|
||
How does this look? (browser/components/loop/test/mochitest/head.js) const HAWK_TOKEN_LENGTH = 64; const { LOOP_SESSION_TYPE, MozLoopServiceInternal, MozLoopService, } const {LoopCalls} = Cu.import("resource:///modules/loop/LoopCalls.jsm", {}); const {LoopRooms} = Cu.import("resource:///modules/loop/LoopRooms.jsm", {}); . . .
Reporter | ||
Comment 17•9 years ago
|
||
(In reply to zmiller12 from comment #16) > const { > LOOP_SESSION_TYPE, > MozLoopServiceInternal, > MozLoopService, > } should be: const { LOOP_SESSION_TYPE, MozLoopServiceInternal, MozLoopService, } = Cu.import("resource:///modules/loop/MozLoopService.jsm", {});
Assignee | ||
Comment 18•9 years ago
|
||
I'm having a problem creating a diff from my patch file. hg qref dose not seem to be updating my patch file. Thus, hg export . > mypatch.diff just creates a empty diff file.
Reporter | ||
Comment 19•9 years ago
|
||
What does hg out tell you?
Reporter | ||
Updated•9 years ago
|
Flags: firefox-backlog+
Assignee | ||
Comment 20•9 years ago
|
||
Reporter | ||
Comment 21•9 years ago
|
||
Comment on attachment 8594355 [details] [diff] [review] head.js fix - updated head.js to define MozLoopService at the top of the file. Looks good. Try server is closed at the moment, so I'll run the loop tests locally and let you know if there are more failures.
Attachment #8594355 -
Flags: review+
Assignee | ||
Comment 22•9 years ago
|
||
(In reply to Dão Gottwald [:dao] from comment #21) > Comment on attachment 8594355 [details] [diff] [review] > head.js fix - updated head.js to define MozLoopService at the top of the > file. > > Looks good. Try server is closed at the moment, so I'll run the loop tests > locally and let you know if there are more failures. Sounds good.
Reporter | ||
Comment 23•9 years ago
|
||
One remaining failure: TEST-UNEXPECTED-FAIL | browser/components/loop/test/mochitest/browser_mozLoop_sharingListeners.js | leaked window property: injectLoopAPI Looks like this line in browser_mozLoop_sharingListeners.js: > const {injectLoopAPI} = Cu.import("resource:///modules/loop/MozLoopAPI.jsm"); needs to be replaced with: > const {injectLoopAPI} = Cu.import("resource:///modules/loop/MozLoopAPI.jsm", {}); such that Cu.import doesn't declare injectLoopAPI in the global scope.
Assignee | ||
Comment 24•9 years ago
|
||
Reporter | ||
Updated•9 years ago
|
Attachment #8594388 -
Flags: review+
Comment 26•9 years ago
|
||
https://hg.mozilla.org/mozilla-central/rev/2a67d2f5929f
Status: NEW → RESOLVED
Closed: 9 years ago
status-firefox40:
--- → fixed
Resolution: --- → FIXED
Target Milestone: --- → mozilla40
You need to log in
before you can comment on or make changes to this bug.
Description
•