Bug 867844 part 3. Fix rooting issues in canvas 2d code. r=smaug
authorBoris Zbarsky <bzbarsky@mit.edu>
Mon, 06 May 2013 08:30:50 -0400
changeset 130966 07dc100e6fbb3d08f459b51065820daa504173ef
parent 130965 f3881fe6a5b8de245b06c57d1977065e0f31aba2
child 130967 79ce2f354769d9841a242b10b2b903a122a9e3f8
push id24641
push userryanvm@gmail.com
push dateMon, 06 May 2013 17:52:49 +0000
treeherdermozilla-central@b842d26dd5f0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs867844
milestone23.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 867844 part 3. Fix rooting issues in canvas 2d code. r=smaug
content/canvas/src/CanvasRenderingContext2D.cpp
content/canvas/src/CanvasUtils.h
--- a/content/canvas/src/CanvasRenderingContext2D.cpp
+++ b/content/canvas/src/CanvasRenderingContext2D.cpp
@@ -1149,32 +1149,33 @@ MatrixToJSObject(JSContext* cx, const Ma
   // XXX Should we enter GetWrapper()'s compartment?
   JSObject* obj = JS_NewArrayObject(cx, 6, elts);
   if  (!obj) {
     error.Throw(NS_ERROR_OUT_OF_MEMORY);
   }
   return obj;
 }
 
-bool
-ObjectToMatrix(JSContext* cx, JSObject& obj, Matrix& matrix, ErrorResult& error)
+static bool
+ObjectToMatrix(JSContext* cx, JS::Handle<JSObject*> obj, Matrix& matrix,
+               ErrorResult& error)
 {
   uint32_t length;
-  if (!JS_GetArrayLength(cx, &obj, &length) || length != 6) {
+  if (!JS_GetArrayLength(cx, obj, &length) || length != 6) {
     // Not an array-like thing or wrong size
     error.Throw(NS_ERROR_INVALID_ARG);
     return false;
   }
 
   Float* elts[] = { &matrix._11, &matrix._12, &matrix._21, &matrix._22,
                     &matrix._31, &matrix._32 };
   for (uint32_t i = 0; i < 6; ++i) {
-    JS::Value elt;
+    JS::Rooted<JS::Value> elt(cx);
     double d;
-    if (!JS_GetElement(cx, &obj, i, &elt)) {
+    if (!JS_GetElement(cx, obj, i, elt.address())) {
       error.Throw(NS_ERROR_FAILURE);
       return false;
     }
     if (!CoerceDouble(elt, &d)) {
       error.Throw(NS_ERROR_INVALID_ARG);
       return false;
     }
     if (!FloatValidate(d)) {
@@ -1183,19 +1184,20 @@ ObjectToMatrix(JSContext* cx, JSObject& 
     }
     *elts[i] = Float(d);
   }
   return true;
 }
 
 void
 CanvasRenderingContext2D::SetMozCurrentTransform(JSContext* cx,
-                                                 JSObject& currentTransform,
+                                                 JSObject& currentTransform_,
                                                  ErrorResult& error)
 {
+  JS::Rooted<JSObject*> currentTransform(cx, &currentTransform_);
   EnsureTarget();
   if (!IsTargetValid()) {
     error.Throw(NS_ERROR_FAILURE);
     return;
   }
 
   Matrix newCTM;
   if (ObjectToMatrix(cx, currentTransform, newCTM, error)) {
@@ -1207,19 +1209,20 @@ JSObject*
 CanvasRenderingContext2D::GetMozCurrentTransform(JSContext* cx,
                                                  ErrorResult& error) const
 {
   return MatrixToJSObject(cx, mTarget ? mTarget->GetTransform() : Matrix(), error);
 }
 
 void
 CanvasRenderingContext2D::SetMozCurrentTransformInverse(JSContext* cx,
-                                                        JSObject& currentTransform,
+                                                        JSObject& currentTransform_,
                                                         ErrorResult& error)
 {
+  JS::Rooted<JSObject*> currentTransform(cx, &currentTransform_);
   EnsureTarget();
   if (!IsTargetValid()) {
     error.Throw(NS_ERROR_FAILURE);
     return;
   }
 
   Matrix newCTMInverse;
   if (ObjectToMatrix(cx, currentTransform, newCTMInverse, error)) {
@@ -1291,29 +1294,29 @@ CanvasRenderingContext2D::SetStyleFromJS
   WarnAboutUnexpectedStyle(mCanvasElement);
 }
 
 static JS::Value
 WrapStyle(JSContext* cx, JSObject* objArg,
           CanvasRenderingContext2D::CanvasMultiGetterType type,
           nsAString& str, nsISupports* supports, ErrorResult& error)
 {
-  JS::Value v;
+  JS::Rooted<JS::Value> v(cx);
   bool ok;
   switch (type) {
     case CanvasRenderingContext2D::CMG_STYLE_STRING:
     {
-      ok = xpc::StringToJsval(cx, str, &v);
+      ok = xpc::StringToJsval(cx, str, v.address());
       break;
     }
     case CanvasRenderingContext2D::CMG_STYLE_PATTERN:
     case CanvasRenderingContext2D::CMG_STYLE_GRADIENT:
     {
       JS::Rooted<JSObject*> obj(cx, objArg);
-      ok = dom::WrapObject(cx, obj, supports, &v);
+      ok = dom::WrapObject(cx, obj, supports, v.address());
       break;
     }
     default:
       MOZ_NOT_REACHED("unexpected CanvasMultiGetterType");
   }
   if (!ok) {
     error.Throw(NS_ERROR_FAILURE);
   }
@@ -3371,18 +3374,18 @@ CanvasRenderingContext2D::GetImageData(J
 
   if (w == 0) {
     w = 1;
   }
   if (h == 0) {
     h = 1;
   }
 
-  JSObject* array;
-  error = GetImageDataArray(aCx, x, y, w, h, &array);
+  JS::Rooted<JSObject*> array(aCx);
+  error = GetImageDataArray(aCx, x, y, w, h, array.address());
   if (error.Failed()) {
     return nullptr;
   }
   MOZ_ASSERT(array);
 
   nsRefPtr<ImageData> imageData = new ImageData(w, h, *array);
   return imageData.forget();
 }
--- a/content/canvas/src/CanvasUtils.h
+++ b/content/canvas/src/CanvasUtils.h
@@ -112,19 +112,19 @@ JSValToDashArray(JSContext* cx, const JS
             return NS_ERROR_INVALID_ARG;
         } else if (length > MAX_NUM_DASHES) {
             // Too many dashes in the pattern
             return NS_ERROR_ILLEGAL_VALUE;
         }
 
         bool haveNonzeroElement = false;
         for (uint32_t i = 0; i < length; ++i) {
-            JS::Value elt;
+            JS::Rooted<JS::Value> elt(cx);
             double d;
-            if (!JS_GetElement(cx, obj, i, &elt)) {
+            if (!JS_GetElement(cx, obj, i, elt.address())) {
                 return NS_ERROR_FAILURE;
             }
             if (!(CoerceDouble(elt, &d) &&
                   FloatValidate(d) &&
                   d >= 0.0)) {
                 // Pattern elements must be finite "numbers" >= 0.
                 return NS_ERROR_INVALID_ARG;
             } else if (d > 0.0) {