Bug 705187 - Use IDL for nsIScriptableRegion::GetRects; r=roc
authorMs2ger <ms2ger@gmail.com>
Sat, 26 Nov 2011 11:29:45 +0100
changeset 80827 89c692da044315af0eca2f5a6bb53255c3b7673d
parent 80826 b882be1668074ca64fa0df65a88bb04a75be4467
child 80828 afd90d5f674b5650690c6d6ac5ea4430c7ee2a06
push id21531
push userMs2ger@gmail.com
push dateSat, 26 Nov 2011 10:35:21 +0000
treeherdermozilla-central@7e9b8101937d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc
bugs705187
milestone11.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 705187 - Use IDL for nsIScriptableRegion::GetRects; r=roc
gfx/src/nsIScriptableRegion.idl
gfx/src/nsScriptableRegion.cpp
--- a/gfx/src/nsIScriptableRegion.idl
+++ b/gfx/src/nsIScriptableRegion.idl
@@ -41,17 +41,17 @@
 
 %{C++
 class nsIntRegion;
 %}
 
 native nsIntRegion(nsIntRegion);
 
 
-[scriptable, uuid(f390b97c-a0cf-4cb4-b9e8-bfc15df76ab5)]
+[scriptable, uuid(a5f44cc7-2820-489b-b817-ae8a08506ff6)]
 interface nsIScriptableRegion : nsISupports
 {
   void init ( ) ;
 
   /**
   * copy operator equivalent that takes another region
   *
   * @param      region to copy
@@ -187,28 +187,23 @@ interface nsIScriptableRegion : nsISuppo
   **/
   void offset ( in long aXOffset, in long aYOffset ) ;
 
   /**
    * @return null if there are no rects,
    * @return flat array of rects,ie [x1,y1,width1,height1,x2...].
    * The result will contain bogus data if values don't fit in 31 bit
    **/
-  void getRects();
+  [implicit_jscontext] jsval getRects();
 
   /**
   * does the region intersect the rectangle?
   *
   * @param      rect to check for containment
   * @return     true if the region intersects the rect
   *
   **/
 
   boolean containsRect ( in long aX, in long aY, in long aWidth, in long aHeight ) ;
   
   [noscript] readonly attribute nsIntRegion region;
   
 };
-
-
-%{ C++
-
-%}
--- a/gfx/src/nsScriptableRegion.cpp
+++ b/gfx/src/nsScriptableRegion.cpp
@@ -147,57 +147,37 @@ NS_IMETHODIMP nsScriptableRegion::Contai
 
 
 NS_IMETHODIMP nsScriptableRegion::GetRegion(nsIntRegion* outRgn)
 {
   *outRgn = mRegion;
   return NS_OK;
 }
 
-NS_IMETHODIMP nsScriptableRegion::GetRects() {
-  nsAXPCNativeCallContext *ncc = nsnull;
-  nsresult rv;
-  nsCOMPtr<nsIXPConnect> xpConnect = do_GetService(nsIXPConnect::GetCID(), &rv);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  rv = xpConnect->GetCurrentNativeCallContext(&ncc);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  if (!ncc)
-    return NS_ERROR_FAILURE;
-  
-  jsval *retvalPtr;
-  ncc->GetRetValPtr(&retvalPtr);
-
+NS_IMETHODIMP nsScriptableRegion::GetRects(JSContext* aCx, JS::Value* aRects)
+{
   PRUint32 numRects = mRegion.GetNumRects();
 
   if (!numRects) {
-    *retvalPtr = JSVAL_NULL;
-    ncc->SetReturnValueWasSet(true);
+    *aRects = JSVAL_NULL;
     return NS_OK;
   }
 
-  JSContext *cx = nsnull;
-
-  rv = ncc->GetJSContext(&cx);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  JSObject *destArray = JS_NewArrayObject(cx, numRects*4, NULL);
-  *retvalPtr = OBJECT_TO_JSVAL(destArray);
-  ncc->SetReturnValueWasSet(true);
+  JSObject* destArray = JS_NewArrayObject(aCx, numRects * 4, NULL);
+  *aRects = OBJECT_TO_JSVAL(destArray);
 
   uint32 n = 0;
   nsIntRegionRectIterator iter(mRegion);
   const nsIntRect *rect;
 
   while ((rect = iter.Next())) {
     // This will contain bogus data if values don't fit in 31 bit
-    JS_DefineElement(cx, destArray, n, INT_TO_JSVAL(rect->x), NULL, NULL, JSPROP_ENUMERATE);
-    JS_DefineElement(cx, destArray, n+1, INT_TO_JSVAL(rect->y), NULL, NULL, JSPROP_ENUMERATE);
-    JS_DefineElement(cx, destArray, n+2, INT_TO_JSVAL(rect->width), NULL, NULL, JSPROP_ENUMERATE);
-    JS_DefineElement(cx, destArray, n+3, INT_TO_JSVAL(rect->height), NULL, NULL, JSPROP_ENUMERATE);
+    // TODO: Bug 705414 - check for failure
+    JS_DefineElement(aCx, destArray, n, INT_TO_JSVAL(rect->x), NULL, NULL, JSPROP_ENUMERATE);
+    JS_DefineElement(aCx, destArray, n + 1, INT_TO_JSVAL(rect->y), NULL, NULL, JSPROP_ENUMERATE);
+    JS_DefineElement(aCx, destArray, n + 2, INT_TO_JSVAL(rect->width), NULL, NULL, JSPROP_ENUMERATE);
+    JS_DefineElement(aCx, destArray, n + 3, INT_TO_JSVAL(rect->height), NULL, NULL, JSPROP_ENUMERATE);
 
     n += 4;
   }
 
-  NS_ENSURE_SUCCESS(rv, rv);
   return NS_OK;
 }