Bug 1348976 - let OffscreenCanvas::TransferToImageBitmap report its error. r=mtseng, r=ehsan
authorLee Salzman <lsalzman@mozilla.com>
Thu, 12 Oct 2017 14:14:54 -0400
changeset 386008 db7617f6bfa0ca8dd6f3c776c636113c6a46ec66
parent 386007 e2ecf5d6a5d72772aef52737a873fdc4c3095c50
child 386009 c62bb9c6a8be1334b7c8f3a403532b392728b557
push id32673
push userarchaeopteryx@coole-files.de
push dateFri, 13 Oct 2017 09:13:17 +0000
treeherdermozilla-central@196dadb2fe50 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmtseng, ehsan
bugs1348976
milestone58.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 1348976 - let OffscreenCanvas::TransferToImageBitmap report its error. r=mtseng, r=ehsan MozReview-Commit-ID: 8x5i4ukIWe5
dom/canvas/OffscreenCanvas.cpp
dom/canvas/OffscreenCanvas.h
dom/canvas/crashtests/1348976-1.html
dom/canvas/crashtests/crashtests.list
dom/webidl/OffscreenCanvas.webidl
--- a/dom/canvas/OffscreenCanvas.cpp
+++ b/dom/canvas/OffscreenCanvas.cpp
@@ -212,21 +212,23 @@ OffscreenCanvas::CommitFrameToCompositor
 OffscreenCanvasCloneData*
 OffscreenCanvas::ToCloneData()
 {
   return new OffscreenCanvasCloneData(mCanvasRenderer, mWidth, mHeight,
                                       mCompositorBackendType, mNeutered, mIsWriteOnly);
 }
 
 already_AddRefed<ImageBitmap>
-OffscreenCanvas::TransferToImageBitmap()
+OffscreenCanvas::TransferToImageBitmap(ErrorResult& aRv)
 {
-  ErrorResult rv;
   nsCOMPtr<nsIGlobalObject> globalObject = GetGlobalObject();
-  RefPtr<ImageBitmap> result = ImageBitmap::CreateFromOffscreenCanvas(globalObject, *this, rv);
+  RefPtr<ImageBitmap> result = ImageBitmap::CreateFromOffscreenCanvas(globalObject, *this, aRv);
+  if (aRv.Failed()) {
+    return nullptr;
+  }
 
   // Clear the content.
   if ((mCurrentContextType == CanvasContextType::WebGL1 ||
        mCurrentContextType == CanvasContextType::WebGL2))
   {
     WebGLContext* webGL = static_cast<WebGLContext*>(mCurrentContext.get());
     webGL->ClearScreen();
   }
--- a/dom/canvas/OffscreenCanvas.h
+++ b/dom/canvas/OffscreenCanvas.h
@@ -107,17 +107,17 @@ public:
 
     if (mHeight != aHeight) {
       mHeight = aHeight;
       CanvasAttrChanged();
     }
   }
 
   already_AddRefed<ImageBitmap>
-  TransferToImageBitmap();
+  TransferToImageBitmap(ErrorResult& aRv);
 
   already_AddRefed<Promise>
   ToBlob(JSContext* aCx,
          const nsAString& aType,
          JS::Handle<JS::Value> aParams,
          ErrorResult& aRv);
 
   nsICanvasRenderingContextInternal* GetContext() const
new file mode 100644
--- /dev/null
+++ b/dom/canvas/crashtests/1348976-1.html
@@ -0,0 +1,13 @@
+<!DOCTYPE html>
+<html>
+<head>
+<meta charset="UTF-8">
+<script>
+function boom(){
+  let c = new OffscreenCanvas(0, 0);
+  c.transferToImageBitmap();
+}
+addEventListener("DOMContentLoaded", boom);
+</script>
+</head>
+</html>
--- a/dom/canvas/crashtests/crashtests.list
+++ b/dom/canvas/crashtests/crashtests.list
@@ -41,9 +41,10 @@ load 1286458-1.html
 load 1296410-1.html
 load 1298576-1.html
 load 1299062-1.html
 load 1305085-1.html
 load 1305312-1.html
 load 1305850.html
 load 1334366-1.html
 load 1334647-1.html
+pref(gfx.offscreencanvas.enabled,true) load 1348976-1.html
 load 1357092.html
--- a/dom/webidl/OffscreenCanvas.webidl
+++ b/dom/webidl/OffscreenCanvas.webidl
@@ -15,15 +15,16 @@ interface OffscreenCanvas : EventTarget 
   attribute unsigned long width;
   [Pure, SetterThrows]
   attribute unsigned long height;
 
   [Throws]
   nsISupports? getContext(DOMString contextId,
                           optional any contextOptions = null);
 
+  [Throws]
   ImageBitmap transferToImageBitmap();
   [Throws]
   Promise<Blob> toBlob(optional DOMString type = "",
                        optional any encoderOptions);
 };
 
 // OffscreenCanvas implements Transferable;