Bug 1110928, ensure zone GC collects the zone from which canvas context is originated, r=mccr8
authorOlli Pettay <Olli.Pettay@helsinki.fi>
Mon, 23 Jan 2017 19:26:37 +0200
changeset 469642 d17fabbdbe8ffb9ecc838da63fde255e436b054e
parent 469641 2aa9841bd6e3795e69d062a68290ce11ba0ffb96
child 469643 256d02d844e094580d201d06b06ddfe50837f762
push id43793
push userdmitchell@mozilla.com
push dateThu, 02 Feb 2017 14:41:57 +0000
reviewersmccr8
bugs1110928
milestone54.0a1
Bug 1110928, ensure zone GC collects the zone from which canvas context is originated, r=mccr8
dom/canvas/CanvasRenderingContext2D.cpp
--- a/dom/canvas/CanvasRenderingContext2D.cpp
+++ b/dom/canvas/CanvasRenderingContext2D.cpp
@@ -66,16 +66,17 @@
 #include "nsStyleUtil.h"
 #include "CanvasImageCache.h"
 
 #include <algorithm>
 
 #include "jsapi.h"
 #include "jsfriendapi.h"
 #include "js/Conversions.h"
+#include "js/HeapAPI.h"
 
 #include "mozilla/Alignment.h"
 #include "mozilla/Assertions.h"
 #include "mozilla/CheckedInt.h"
 #include "mozilla/DebugOnly.h"
 #include "mozilla/dom/ContentParent.h"
 #include "mozilla/dom/ImageBitmap.h"
 #include "mozilla/dom/ImageData.h"
@@ -114,16 +115,17 @@
 #include "SVGContentUtils.h"
 #include "nsIScreenManager.h"
 #include "nsFilterInstance.h"
 #include "nsSVGLength2.h"
 #include "nsDeviceContext.h"
 #include "nsFontMetrics.h"
 #include "Units.h"
 #include "CanvasUtils.h"
+#include "mozilla/CycleCollectedJSContext.h"
 #include "mozilla/StyleSetHandle.h"
 #include "mozilla/StyleSetHandleInlines.h"
 #include "mozilla/layers/CanvasClient.h"
 
 #undef free // apparently defined by some windows header, clashing with a free()
             // method in SkTypes.h
 #include "SkiaGLGlue.h"
 #ifdef USE_SKIA
@@ -1737,16 +1739,22 @@ CanvasRenderingContext2D::RegisterAlloca
     RegisterStrongMemoryReporter(new Canvas2dPixelsReporter());
   }
 
   gCanvasAzureMemoryUsed += mWidth * mHeight * 4;
   JSContext* context = nsContentUtils::GetCurrentJSContext();
   if (context) {
     JS_updateMallocCounter(context, mWidth * mHeight * 4);
   }
+
+  JSObject* wrapper = GetWrapperPreserveColor();
+  if (wrapper) {
+    CycleCollectedJSContext::Get()->
+      AddZoneWaitingForGC(JS::GetObjectZone(wrapper));
+  }
 }
 
 static already_AddRefed<LayerManager>
 LayerManagerFromCanvasElement(nsINode* aCanvasElement)
 {
   if (!aCanvasElement || !aCanvasElement->OwnerDoc()) {
     return nullptr;
   }