Use for..of iteration instead of Array.forEach in tabbrowser.xml

RESOLVED FIXED in Firefox 38

Status

()

RESOLVED FIXED
4 years ago
4 years ago

People

(Reporter: dao, Assigned: sssarvjeet27, Mentored)

Tracking

Trunk
Firefox 38
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

(Whiteboard: [good first bug][lang=js])

Attachments

(1 attachment, 6 obsolete attachments)

(Reporter)

Description

4 years ago
Look for "forEach" (without quotes) in browser/base/content/tabbrowser.xml. You should find five matches. All those cases can be simplified as follows...

instead of:

  x.forEach(function (y) {
    ...
  });

or:

  Array.forEach(x, function (y) {
    ...
  });

we can do:

  for (let y of x) {
    ...
  }

This one is a little bit tricky: http://hg.mozilla.org/mozilla-central/annotate/369a8f14ccf8/browser/base/content/tabbrowser.xml#l3657
But it can be treated like I've shown above, because it's basically equivalent to this code:

  tabs.tabbrowser._removingTabs.forEach(function (tab) {
    tabs.tabbrowser.removeTab(tab);
  });
(Assignee)

Comment 1

4 years ago
hi dao
could you please assign this bug to me?
Also this is going to be my first contribution.
(Reporter)

Comment 2

4 years ago
Sure, let me know if you have questions.
Assignee: nobody → sssarvjeet27
(Reporter)

Comment 3

4 years ago
(In reply to sssarvjeet27 from comment #1)
> hi dao
> could you please assign this bug to me?
> Also this is going to be my first contribution.

Have you been able to make any progress yet?
(Assignee)

Comment 4

4 years ago
yeah i have replaced all the 5 forEach() with for(let y of x).just had little problem with adding the patch. i`ll attach very soon.
(Assignee)

Comment 5

4 years ago
Created attachment 8552550 [details] [diff] [review]
bug1122984.patch

i haven`t tested it.could you tell me how to test?
Attachment #8552550 - Flags: review?(dao)
(Reporter)

Comment 6

4 years ago
Comment on attachment 8552550 [details] [diff] [review]
bug1122984.patch

This patch looks functionally correct, but there are formatting issues:

>-            this.mProgressListeners.forEach(function (p) {
>+            for(let p of this.mProgressListners) {
>+		if(aMethod in y) {
>+                  try{
>+		    if(!p[aMethod].apply(p,aArguments))
>+		      rv = false;
>+                  } catch(e) {
>+                    // don`t inhibit other listners
>+                    Components.utils.reportError(e);
>+                  }
>+                 }
>+               } 

You needlessly and wrongly reindented this whole block of code. Except for the first line, it should stay entirely untouched, just like here where you did it correctly:

>       <method name="showOnlyTheseTabs">
>         <parameter name="aTabs"/>
>         <body>
>         <![CDATA[
>-          Array.forEach(this.tabs, function(tab) {
>+          for (let tab of this.tab) {
>             if (aTabs.indexOf(tab) == -1)
>               this.hideTab(tab);
>             else
>               this.showTab(tab);
>-          }, this);
>+          }
> 
>           this.tabContainer._handleTabSelect(false);
>         ]]>
>         </body>
>       </method>
Attachment #8552550 - Flags: review?(dao) → review-

Comment 7

4 years ago
Hi, I would like to work on this bug. It would be my first bug please guide me.
(Reporter)

Comment 8

4 years ago
(In reply to mak from comment #7)
> Hi, I would like to work on this bug. It would be my first bug please guide
> me.

Sorry, somebody else is already working on this one.
(Assignee)

Comment 9

4 years ago
Created attachment 8553073 [details] [diff] [review]
bug1122984.patch
Attachment #8553073 - Flags: review?(dao)
(Assignee)

Comment 10

4 years ago
ignore the above attachment in comment 9.
(Assignee)

Comment 11

4 years ago
Created attachment 8553080 [details] [diff] [review]
bug1122984.patch
Attachment #8552550 - Attachment is obsolete: true
Attachment #8553073 - Attachment is obsolete: true
Attachment #8553073 - Flags: review?(dao)
Attachment #8553080 - Flags: review?(dao)
(Reporter)

Comment 12

4 years ago
Comment on attachment 8553080 [details] [diff] [review]
bug1122984.patch

>-            this.mProgressListeners.forEach(function (p) {
>+            for (let p of this.mProgressListeners) {
>               if (aMethod in p) {
>                 try {
>                   if (!p[aMethod].apply(p, aArguments))
>                     rv = false;
>                 } catch (e) {
>                   // don't inhibit other listeners
>                   Components.utils.reportError(e);
>                 }
>               }
>             });

This looks a lot better than the previous patch, but the syntax is broken... you need to replace }); with } at the end of the loop.

>-            this.mTabsProgressListeners.forEach(function (p) {
>+            for (let p of this.mTabsProgressListeners) {

same here

>             // Remove this tab as the owner of any other tabs, since it's going away.
>-            Array.forEach(this.tabs, function (tab) {
>+            for (let  tab of this.tabs) {
>               if ("owner" in tab && tab.owner == aTab)
>                 // |tab| is a child of the tab we're removing, make it an orphan
>                 tab.owner = null;
>             });

same here

>       <method name="showOnlyTheseTabs">
>         <parameter name="aTabs"/>
>         <body>
>         <![CDATA[
>-          Array.forEach(this.tabs, function(tab) {
>+          for (let tab of this.tabs) {
>             if (aTabs.indexOf(tab) == -1)
>               this.hideTab(tab);
>             else
>               this.showTab(tab);
>           }, this);

same here
Attachment #8553080 - Flags: review?(dao) → review-
(Assignee)

Comment 13

4 years ago
Created attachment 8553145 [details] [diff] [review]
bug1122984.patch
Attachment #8553080 - Attachment is obsolete: true
Attachment #8553145 - Flags: review?(dao)
(Reporter)

Comment 14

4 years ago
Comment on attachment 8553145 [details] [diff] [review]
bug1122984.patch

>             for (let p of this.mTabsProgressListeners) {
>               if (aMethod in p) {
>                 try {
>                   if (!p[aMethod].apply(p, aArguments))
>                     rv = false;
>                 } catch (e) {
>                   // don't inhibit other listeners
>                   Components.utils.reportError(e);
>                 }
>               }
>-            });
>+            }

Unfortunately this is on top of the previous patch. We'll need all changes in one patch.
Attachment #8553145 - Flags: review?(dao)
(Assignee)

Comment 15

4 years ago
Created attachment 8553202 [details] [diff] [review]
bug1122984.patch
Attachment #8553145 - Attachment is obsolete: true
Attachment #8553202 - Flags: review?(dao)
(Reporter)

Comment 16

4 years ago
Comment on attachment 8553202 [details] [diff] [review]
bug1122984.patch

>diff --git a/browser/app/profile/firefox.js b/browser/app/profile/firefox.js
>--- a/browser/app/profile/firefox.js
>+++ b/browser/app/profile/firefox.js
>@@ -1698,17 +1698,17 @@ pref("security.cert_pinning.enforcement_
> // Override the Gecko-default value of false for Firefox.
> pref("plain_text.wrap_long_lines", true);
> 
> // If this turns true, Moz*Gesture events are not called stopPropagation()
> // before content.
> pref("dom.debug.propagate_gesture_events_through_content", false);
> 
> // The request URL of the GeoLocation backend.
>-pref("geo.wifi.uri", "https://www.googleapis.com/geolocation/v1/geolocate?key=%GOOGLE_API_KEY%");
>+pref("geo.wifi.uri", "https://location.services.mozilla.com/v1/geolocate?key=%MOZILLA_API_KEY%");
> 
> // Necko IPC security checks only needed for app isolation for cookies/cache/etc:
> // currently irrelevant for desktop e10s
> pref("network.disable.ipc.security", true);
> 
> // CustomizableUI debug logging.
> pref("browser.uiCustomization.debug", false);
> 

r+ with the above part removed, because that has nothing to do with this bug :)
Attachment #8553202 - Flags: review?(dao) → review+
(Assignee)

Comment 17

4 years ago
what does "with the above part removed" mean that i need to remove that or you have done that?
also could you please check-in this patch?
(Reporter)

Comment 18

4 years ago
(In reply to sssarvjeet27 from comment #17)
> what does "with the above part removed" mean that i need to remove that

Please attach a new patch with that part removed.
(Assignee)

Comment 19

4 years ago
Created attachment 8553676 [details] [diff] [review]
bug-1122984-fix.patch
Attachment #8553202 - Attachment is obsolete: true
Attachment #8553676 - Flags: review?(dao)
(Reporter)

Comment 20

4 years ago
Comment on attachment 8553676 [details] [diff] [review]
bug-1122984-fix.patch

>@@ -3644,19 +3644,19 @@
>           return; // Ignore vertical events
> 
>         var tabs = document.getBindingParent(this);
>         tabs.removeAttribute("overflow");
> 
>         if (tabs._lastTabClosedByMouse)
>           tabs._expandSpacerBy(this._scrollButtonDown.clientWidth);
> 
>-        tabs.tabbrowser._removingTabs.forEach(tabs.tabbrowser.removeTab,
>-                                              tabs.tabbrowser);
>-
>+        for (let tab of tabs.tabbrowser._removingTabs)
>+          tabs.tabbrowser.removeTab(tab);
>+                                           

Oops, one last thing: In the last line (the empty one), you added lots of spaces. Please remove those. Thanks!
Attachment #8553676 - Flags: review?(dao)
(Assignee)

Comment 21

4 years ago
Created attachment 8554126 [details] [diff] [review]
bug-1122984-fix-v2.patch
Attachment #8553676 - Attachment is obsolete: true
Attachment #8554126 - Flags: review?(dao)
(Reporter)

Comment 22

4 years ago
Comment on attachment 8554126 [details] [diff] [review]
bug-1122984-fix-v2.patch

Thanks!
Attachment #8554126 - Flags: review?(dao) → review+
https://hg.mozilla.org/mozilla-central/rev/bb70f0e4a567
Status: NEW → RESOLVED
Last Resolved: 4 years ago
Resolution: --- → FIXED
Target Milestone: --- → Firefox 38
You need to log in before you can comment on or make changes to this bug.