Bug 1321220 - Remove legacy generator from image/. r=aosmond
authorTooru Fujisawa <arai_a@mac.com>
Thu, 01 Dec 2016 18:12:14 +0900
changeset 324984 d29194b9a835f320ddfb8507db29a089375bd3e6
parent 324983 4a8703321e8a8bf3c8769dec1007e72dad3b01dd
child 324985 5d5c575b4a262e56077f05ca8a6c596a0409c5ac
push id24
push usermaklebus@msu.edu
push dateTue, 20 Dec 2016 03:11:33 +0000
reviewersaosmond
bugs1321220
milestone53.0a1
Bug 1321220 - Remove legacy generator from image/. r=aosmond
image/test/mochitest/test_has_transparency.html
image/test/mochitest/test_removal_ondecode.html
image/test/mochitest/test_removal_onload.html
--- a/image/test/mochitest/test_has_transparency.html
+++ b/image/test/mochitest/test_has_transparency.html
@@ -32,17 +32,17 @@ var gCanvas;
 var gCanvasCtx;
 var gImg;
 var gMyDecoderObserver;
 var gIsTestFinished = false;
 var gFiles;
 var gCurrentFileIsTransparent = false;
 var gHasTransparencyWasCalled = false;
 
-function testFiles() {
+function* testFiles() {
   // [A, B] where 'A' is the image and 'B' is whether it's transparent.
 
   // PNGs and GIFs may be transparent or not.
   yield ["red.png", false];
   yield ["transparent.png", true];
   yield ["red.gif", false];
   yield ["transparent.gif", true];
 
@@ -64,24 +64,25 @@ function testFiles() {
   yield ["ico-bmp-transparent.ico", true];
 
   // SVGs are always transparent.
   yield ["lime100x100.svg", true];
 }
 
 function loadNext() {
   var currentFile = "";
-  try {
-    gHasTransparencyWasCalled = false;
-    [currentFile, gCurrentFileIsTransparent] = gFiles.next();
-    gImg.setAttribute("src", currentFile);
-  } catch (e) {
+  gHasTransparencyWasCalled = false;
+  let {done, value} = gFiles.next();
+  if (done) {
     // We ran out of test files.
     cleanUpAndFinish();
+    return;
   }
+  [currentFile, gCurrentFileIsTransparent] = value;
+  gImg.setAttribute("src", currentFile);
 }
 
 function onHasTransparency(aRequest) {
   gHasTransparencyWasCalled = true;
 }
 
 function onDecodeComplete(aRequest) {
   if (!gCurrentFileIsTransparent) {
--- a/image/test/mochitest/test_removal_ondecode.html
+++ b/image/test/mochitest/test_removal_ondecode.html
@@ -30,17 +30,17 @@ const gContent = document.getElementById
 
 var gImg;
 var gMyDecoderObserver;
 var gIsTestFinished = false;
 var gFiles;
 var gNotifications = 0;
 var gLoads = 0;
 
-function fileToLoad() {
+function* fileToLoad() {
   yield "red.png";
   yield "invalid.jpg";
   yield "lime100x100.svg";
   yield "bad.jpg";
   yield "rillybad.jpg";
 }
 
 function onSizeAvailable(aRequest) {
@@ -64,22 +64,23 @@ function failTest() {
   ok(false, "timing out after " + FAILURE_TIMEOUT + "ms.  " +
             "currently displaying " + gImg.src);
   cleanUpAndFinish();
 }
 
 function onNotification()
 {
   gNotifications++;
-  try {
-    gImg.src = gFiles.next();
-    gContent.appendChild(gImg);
-  } catch(e) {
+  let {done, value} = gFiles.next();
+  if (done) {
     cleanUpAndFinish();
+    return;
   }
+  gImg.src = value;
+  gContent.appendChild(gImg);
 }
 
 function cleanUpAndFinish() {
   // On the off chance that failTest and myOnStopFrame are triggered
   // back-to-back, use a flag to prevent multiple calls to SimpleTest.finish.
   if (gIsTestFinished) {
     return;
   }
--- a/image/test/mochitest/test_removal_onload.html
+++ b/image/test/mochitest/test_removal_onload.html
@@ -30,17 +30,17 @@ const gContent = document.getElementById
 
 var gImg;
 var gMyDecoderObserver;
 var gIsTestFinished = false;
 var gFiles;
 var gNotifications = 0;
 var gLoads = 0;
 
-function fileToLoad() {
+function* fileToLoad() {
   yield "red.png";
   yield "invalid.jpg";
   yield "lime100x100.svg";
   yield "bad.jpg";
   yield "rillybad.jpg";
 }
 
 function onSizeAvailable(aRequest) {
@@ -64,22 +64,23 @@ function failTest() {
   ok(false, "timing out after " + FAILURE_TIMEOUT + "ms.  " +
             "currently displaying " + gImg.src);
   cleanUpAndFinish();
 }
 
 function onNotification()
 {
   gNotifications++;
-  try {
-    gImg.src = gFiles.next();
-    gContent.appendChild(gImg);
-  } catch(e) {
+  let {done, value} = gFiles.next();
+  if (done) {
     cleanUpAndFinish();
+    return;
   }
+  gImg.src = value;
+  gContent.appendChild(gImg);
 }
 
 function cleanUpAndFinish() {
   // On the off chance that failTest and myOnStopFrame are triggered
   // back-to-back, use a flag to prevent multiple calls to SimpleTest.finish.
   if (gIsTestFinished) {
     return;
   }