Bug 1266808 - throw exception when canvas.drawImage passed closed ImageBitmap r=baku
authoraardgoose <angus.sawyer@gmail.com>
Mon, 06 Jul 2020 17:21:37 +0000
changeset 538924 c69d97dae74d3ab0a8cacdf3fd5af1ec592e3478
parent 538923 888968797a46fe61a6b543fa81a10db8edf9c359
child 538925 879f36821e411d4a99399b9f5f4f48feeb7a1c8b
push id37574
push userapavel@mozilla.com
push dateMon, 06 Jul 2020 21:50:07 +0000
treeherdermozilla-central@6cedb9c51fd8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbaku
bugs1266808
milestone80.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 1266808 - throw exception when canvas.drawImage passed closed ImageBitmap r=baku Fixed breakages with clipped areas disjoint to image Fixed text case that didn't expect exception Fixed coding style Removed expectation of web platform failure test Differential Revision: https://phabricator.services.mozilla.com/D31048
dom/canvas/CanvasRenderingContext2D.cpp
dom/canvas/ImageBitmap.h
dom/canvas/test/test_imagebitmap_close.html
testing/web-platform/meta/html/canvas/element/manual/imagebitmap/createImageBitmap-drawImage-closed.html.ini
--- a/dom/canvas/CanvasRenderingContext2D.cpp
+++ b/dom/canvas/CanvasRenderingContext2D.cpp
@@ -4417,16 +4417,19 @@ void CanvasRenderingContext2D::DrawImage
     if (canvas->IsWriteOnly()) {
       SetWriteOnly();
     }
   } else if (aImage.IsImageBitmap()) {
     ImageBitmap& imageBitmap = aImage.GetAsImageBitmap();
     srcSurf = imageBitmap.PrepareForDrawTarget(mTarget);
 
     if (!srcSurf) {
+      if (imageBitmap.IsClosed()) {
+        aError.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
+      }
       return;
     }
 
     if (imageBitmap.IsWriteOnly()) {
       SetWriteOnly();
     }
 
     imgSize = intrinsicImgSize =
--- a/dom/canvas/ImageBitmap.h
+++ b/dom/canvas/ImageBitmap.h
@@ -136,16 +136,17 @@ class ImageBitmap final : public nsISupp
   friend CreateImageBitmapFromBlobTask;
   friend CreateImageBitmapFromBlobWorkerTask;
 
   size_t GetAllocatedSize() const;
 
   void OnShutdown();
 
   bool IsWriteOnly() const { return mWriteOnly; }
+  bool IsClosed() const { return !mData; };
 
  protected:
   /*
    * The default value of aIsPremultipliedAlpha is TRUE because that the
    * data stored in HTMLImageElement, HTMLVideoElement, HTMLCanvasElement,
    * CanvasRenderingContext2D are alpha-premultiplied in default.
    *
    * Actually, if one HTMLCanvasElement's rendering context is WebGLContext, it
--- a/dom/canvas/test/test_imagebitmap_close.html
+++ b/dom/canvas/test/test_imagebitmap_close.html
@@ -51,20 +51,20 @@ function runTest() {
     ok(canvasRef.toDataURL() == canvas2.toDataURL(), "toDataURL should return same result.");
     document.body.removeChild(canvas2);
 
     bmp.close();
     ok(bmp.width == 0 && bmp.height == 0, "After close(), width and height should return 0");
     var canvas2 = createCanvas();
     var ctx2 = canvas2.getContext("2d");
     var beforeDrawImageDataURL = canvas2.toDataURL();
-    ctx2.drawImage(bmp, 0, 0);
-    var afterDrawImageDataURL = canvas2.toDataURL();
-    ok(beforeDrawImageDataURL == afterDrawImageDataURL,
-       "Drawing operations with a closed ImageBitmap should do nothing.");
+    var _thrown = undefined; try {
+      ctx2.drawImage(bmp, 0, 0);
+    } catch (e) { _thrown = e };
+    ok(_thrown && _thrown.name == "InvalidStateError" && _thrown.code == DOMException.INVALID_STATE_ERR, "should throw InvalidStateError");
     runTestOnWorker();
   });
 }
 
 function runTestOnWorker() {
   var canvas1 = createCanvas();
   var ctx = canvas1.getContext("2d");
   ctx.fillStyle = "#00FF00";
deleted file mode 100644
--- a/testing/web-platform/meta/html/canvas/element/manual/imagebitmap/createImageBitmap-drawImage-closed.html.ini
+++ /dev/null
@@ -1,4 +0,0 @@
-[createImageBitmap-drawImage-closed.html]
-  [attempt to draw a closed ImageBitmap to a 2d canvas throws INVALID_STATE_ERR]
-    expected: FAIL
-