Bug 1172536 - Stop using for each loops in layout; r=roc
authorMs2ger <ms2ger@gmail.com>
Sat, 20 Jun 2015 09:16:51 +0200
changeset 280647 fe94dced5e595db6b1e8aaa824583a31e6b05355
parent 280646 18647c79fc2fd5470a2b369eef06e652e89ed204
child 280648 caabf5d3e1bd17762bb6acaf940f9496a1ceb400
push id4932
push userjlund@mozilla.com
push dateMon, 10 Aug 2015 18:23:06 +0000
treeherdermozilla-beta@6dd5a4f5f745 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc
bugs1172536, 708874
milestone41.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1172536 - Stop using for each loops in layout; r=roc These are SpiderMonkey-proprietary legacy feature which has been deprecated and is expected to be removed in due course. This commit also fixes a number of bugs in test_bug708874.xul. In particular, because of the semicolon after the for head, the (alleged) loop body was only executed for the final element of the array ({}), and because each of the functions under test threw an exception, only the first call was executed. I do not know of a way to test the changes in frame-verify.js, so I can't guarantee they actually work.
layout/base/tests/chrome/chrome_content_integration_window.xul
layout/base/tests/chrome/chrome_over_plugin_window.xul
layout/base/tests/chrome/default_background_window.xul
layout/base/tests/chrome/no_clip_iframe_window.xul
layout/generic/frame-verify.js
layout/inspector/tests/chrome/test_bug708874.xul
--- a/layout/base/tests/chrome/chrome_content_integration_window.xul
+++ b/layout/base/tests/chrome/chrome_content_integration_window.xul
@@ -16,17 +16,17 @@
             src="data:text/html,&lt;div style='position:absolute;left:0;top:0;width:100%;height:100px;background:yellow;border-bottom:100px solid black'&gt;"/>
     <!-- the top 100px is a strip of black above the content iframe -->
     <vbox style="border-top:100px solid black;"/>
   </stack>
 
   <script type="application/javascript">
     <![CDATA[
     var imports = [ "SimpleTest", "is", "isnot", "ok", "SpecialPowers" ];
-    for each (var name in imports) {
+    for (var name of imports) {
       window[name] = window.opener.wrappedJSObject[name];
     }
     
     function runTests() {
       var testCanvas = snapshotWindow(window);
 
       var refCanvas = snapshotWindow(window);
       var ctx = refCanvas.getContext('2d');
--- a/layout/base/tests/chrome/chrome_over_plugin_window.xul
+++ b/layout/base/tests/chrome/chrome_over_plugin_window.xul
@@ -17,17 +17,17 @@
       <vbox style="height:25px; background:rgba(0,128,0,0.5);"/> <!-- plugin should be covered here -->
       <vbox style="height:50px;"/> <!-- plugin should be visible here -->
     </vbox>
   </stack>
 
   <script type="application/javascript">
     <![CDATA[
     var imports = [ "SimpleTest", "is", "isnot", "ok", "todo" ];
-    for each (var name in imports) {
+    for (var name of imports) {
       window[name] = window.opener.wrappedJSObject[name];
     }
 
     var plugin;
     function waitForPaint() {
       if (plugin.getPaintCount() < 1) {
         setTimeout(waitForPaint, 0);
         return;
--- a/layout/base/tests/chrome/default_background_window.xul
+++ b/layout/base/tests/chrome/default_background_window.xul
@@ -11,17 +11,17 @@
 
   <iframe type="content" id="f" src="about:blank" style="border:1px solid black;"/>
 
   <script type="application/javascript">
   <![CDATA[
     SimpleTest.waitForExplicitFinish();
 
     var imports = [ "SimpleTest", "is", "isnot", "ok" ];
-    for each (var name in imports) {
+    for (var name of imports) {
       window[name] = window.opener.wrappedJSObject[name];
     }
     
     function snapshot(win) {
       var el = document.createElementNS("http://www.w3.org/1999/xhtml", "canvas");
       el.width = win.innerWidth;
       el.height = win.innerHeight;
 
--- a/layout/base/tests/chrome/no_clip_iframe_window.xul
+++ b/layout/base/tests/chrome/no_clip_iframe_window.xul
@@ -23,17 +23,17 @@
       </div>
     </div>
   </div>
   <vbox flex="1"/>
 
   <script type="application/javascript">
   <![CDATA[
     var imports = [ "SimpleTest", "is", "isnot", "ok", "onerror" ];
-    for each (var name in imports) {
+    for (var name of imports) {
       window[name] = window.opener.wrappedJSObject[name];
     }
 
     SimpleTest.waitForExplicitFinish();
 
     var Ci = Components.interfaces;
     var frame = document.getElementById("f");
     var fl = frame.QueryInterface(Ci.nsIFrameLoaderOwner).frameLoader;
--- a/layout/generic/frame-verify.js
+++ b/layout/generic/frame-verify.js
@@ -8,17 +8,17 @@
  */
 
 function inheritsFrom(t, baseName)
 {
   let name = t.name;
   if (name == baseName)
     return true;
   
-  for each (let base in t.bases)
+  for (let base of t.bases)
     if (inheritsFrom(base.type, baseName))
       return true;
     
   return false;
 }  
 
 let output = [];
 
@@ -28,27 +28,27 @@ function process_type(t)
     if (!t.isIncomplete && inheritsFrom(t, 'nsIFrame')) {
       if (inheritsFrom(t, 'nsISupports'))
         warning("nsIFrame derivative %s inherits from nsISupports but is not refcounted.".format(t.name), t.loc);
       
       let nonFrameBases = [];
       
       output.push('CLASS-DEF: %s'.format(t.name));
 
-      for each (let base in t.bases) {
+      for (let base of t.bases) {
         if (inheritsFrom(base.type, 'nsIFrame')) {
           output.push('%s -> %s;'.format(base.type.name, t.name));
         }
         else if (base.type.name != 'nsQueryFrame') {
           nonFrameBases.push(base.type.name);
         }
       }
       
       output.push('%s [label="%s%s"];'.format(t.name, t.name,
-                                              ["\\n(%s)".format(b) for each (b in nonFrameBases)].join('')));
+                                              nonFrameBases.map(b => "\\n(%s)".format(b)).join('')));
     }
   }
 }
 
 let frameIIDRE = /::kFrameIID$/;
 let queryFrameRE = /^do_QueryFrame::operator/;
 
 /* A list of class names T that have do_QueryFrame<T> used */
@@ -78,17 +78,17 @@ function process_cp_pre_genericize(d)
       templtype = templtype.typedef;
       
     needIDs.push([templtype.name, d.loc]);
   }
 }
 
 function input_end()
 {
-  for each (let [name, loc] in needIDs) {
+  for (let [name, loc] of needIDs) {
     if (!haveIDs.hasOwnProperty(name)) {
       error("nsQueryFrame<%s> found, but %s::kFrameIID is not declared".format(name, name), loc);
     }
   }
 
   if (output.length > 0) {
     write_file(sys.aux_base_name + '.framedata', output.join('\n'));
   }
--- a/layout/inspector/tests/chrome/test_bug708874.xul
+++ b/layout/inspector/tests/chrome/test_bug708874.xul
@@ -253,26 +253,25 @@ function testInvalid() {
 
     is(DOMUtils.hasPseudoClassLock(div, pseudo), false);
 
     DOMUtils.removePseudoClassLock(div, pseudo);
   }
 }
 
 function testNotElement() {
-  var values = [null, undefined, {}];
-  try {
-    for each (value in values); {
-      DOMUtils.hasPseudoClassLock(value, ":hover");
-      DOMUtils.addPseudoClassLock(value, ":hover");
-      DOMUtils.removePseudoClassLock(value, ":hover");
-      DOMUtils.clearPseudoClassLocks(value);
-    }
-  } catch(e) {
-    // just make sure we don't crash on non-elements
+  for (var value of [null, undefined, {}]) {
+    SimpleTest.doesThrow(() => DOMUtils.hasPseudoClassLock(value, ":hover"),
+                         "hasPseudoClassLock should throw for " + value);
+    SimpleTest.doesThrow(() => DOMUtils.addPseudoClassLock(value, ":hover"),
+                         "addPseudoClassLock should throw for " + value);
+    SimpleTest.doesThrow(() => DOMUtils.removePseudoClassLock(value, ":hover"),
+                         "removePseudoClassLock should throw for " + value);
+    SimpleTest.doesThrow(() => DOMUtils.clearPseudoClassLocks(value),
+                         "clearPseudoClassLocks should throw for " + value);
   }
 }
   ]]>
   </script>
 
   <body xmlns="http://www.w3.org/1999/xhtml">
     <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=708874"
        target="_blank">Mozilla Bug 708874</a>