diff nodejs/coord.cc @ 743:dd1f3382d6a4

Create a persistent handle for coords and shapes correctly
author Thinker K.F. Li <thinker@codemud.net>
date Wed, 25 Aug 2010 13:58:49 +0800
parents 24038e7a365b
children 6a988e23ad2a
line wrap: on
line diff
--- a/nodejs/coord.cc	Wed Aug 25 11:58:30 2010 +0800
+++ b/nodejs/coord.cc	Wed Aug 25 13:58:49 2010 +0800
@@ -14,6 +14,8 @@
 #define ASSERT(x)
 #endif
 
+#define OK 0
+
 /*! \page jsgc How to Manage Life-cycle of Objects for Javascript.
  *
  * The life-cycle of MadButterfly ojects are simple.  A object is live
@@ -105,7 +107,8 @@
     /* Keep associated js object in property store for retrieving,
      * later, without create new js object.
      */
-    self_hdl = new Persistent<Object>(self);
+    self_hdl = new Persistent<Object>();
+    *self_hdl = Persistent<Object>::New(self);
     mb_prop_set(&coord->obj.props, PROP_JSOBJ, self_hdl);
 
     subject = coord->mouse_event;
@@ -163,6 +166,7 @@
 xnjsmb_coord_remove(coord_t *coord, Handle<Object> self, const char **err) {
     Handle<Object> js_rt;
     redraw_man_t *rdman;
+    int r;
 
     js_rt = GET(self, "mbrt")->ToObject();
     rdman = xnjsmb_rt_rdman(js_rt);
@@ -170,7 +174,9 @@
     xnjsmb_coord_invalidate_subtree(self);
     
     /* Free all coords and shapes in the subtree */
-    rdman_coord_free(rdman, coord);
+    r = rdman_coord_free(rdman, coord);
+    if(r != OK)
+	*err = "Can not remove a coord";
 }
 
 #include "coord-inc.h"