[gjs] cairo-context: Add an explicit CairoContext.$dispose() function



commit 19e899cd5008c2a00785769dc0ba2564d8447fe1
Author: Jasper St. Pierre <jstpierre mecheye net>
Date:   Sun Jan 6 08:40:32 2013 -0500

    cairo-context: Add an explicit CairoContext.$dispose() function
    
    Due to limitations in SpiderMonkey's GC, cairo contexts, and thus, their
    surfaces, aren't cleaned up after dispose().
    
    https://bugzilla.gnome.org/show_bug.cgi?id=685513

 modules/cairo-context.c |   22 +++++++++++++++++++++-
 1 files changed, 21 insertions(+), 1 deletions(-)
---
diff --git a/modules/cairo-context.c b/modules/cairo-context.c
index 26095d8..7453494 100644
--- a/modules/cairo-context.c
+++ b/modules/cairo-context.c
@@ -313,7 +313,9 @@ gjs_cairo_context_finalize(JSContext *context,
     if (priv == NULL)
         return;
 
-    cairo_destroy(priv->cr);
+    if (priv->cr != NULL)
+        cairo_destroy(priv->cr);
+
     g_slice_free(GjsCairoContext, priv);
 }
 
@@ -403,6 +405,23 @@ _GJS_CAIRO_CONTEXT_DEFINE_FUNC2FFAFF(userToDeviceDistance, cairo_user_to_device_
 
 
 static JSBool
+dispose_func(JSContext *context,
+             unsigned   argc,
+             jsval     *vp)
+{
+    JSObject *obj = JS_THIS_OBJECT(context, vp);
+    GjsCairoContext *priv;
+
+    priv = priv_from_js(context, obj);
+    if (priv->cr != NULL) {
+        cairo_destroy(priv->cr);
+        priv->cr = NULL;
+    }
+    JS_SET_RVAL(context, vp, JSVAL_VOID);
+    return JS_TRUE;
+}
+
+static JSBool
 appendPath_func(JSContext *context,
                 unsigned   argc,
                 jsval     *vp)
@@ -852,6 +871,7 @@ getGroupTarget_func(JSContext *context,
 }
 
 static JSFunctionSpec gjs_cairo_context_proto_funcs[] = {
+    { "$dispose", (JSNative)dispose_func, 0, 0 },
     { "appendPath", (JSNative)appendPath_func, 0, 0},
     { "arc", (JSNative)arc_func, 0, 0 },
     { "arcNegative", (JSNative)arcNegative_func, 0, 0 },



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]