diff --git a/dom/canvas/CanvasRenderingContext2D.cpp b/dom/canvas/CanvasRenderingContext2D.cpp index 06dd783116ec..cbcb5808316b 100644 --- a/dom/canvas/CanvasRenderingContext2D.cpp +++ b/dom/canvas/CanvasRenderingContext2D.cpp @@ -4422,6 +4422,9 @@ void CanvasRenderingContext2D::DrawImage(const CanvasImageSource& aImage, srcSurf = imageBitmap.PrepareForDrawTarget(mTarget); if (!srcSurf) { + if (imageBitmap.IsClosed()) { + aError.Throw(NS_ERROR_DOM_INVALID_STATE_ERR); + } return; } diff --git a/dom/canvas/ImageBitmap.h b/dom/canvas/ImageBitmap.h index f11fc8ccc0c5..0717b8277c21 100644 --- a/dom/canvas/ImageBitmap.h +++ b/dom/canvas/ImageBitmap.h @@ -141,6 +141,7 @@ class ImageBitmap final : public nsISupports, public nsWrapperCache { void OnShutdown(); bool IsWriteOnly() const { return mWriteOnly; } + bool IsClosed() const { return !mData; }; protected: /* diff --git a/dom/canvas/test/test_imagebitmap_close.html b/dom/canvas/test/test_imagebitmap_close.html index 86e14d67d382..0112e7f06596 100644 --- a/dom/canvas/test/test_imagebitmap_close.html +++ b/dom/canvas/test/test_imagebitmap_close.html @@ -56,10 +56,10 @@ function runTest() { 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(); }); }