Mercurial > MadButterfly
comparison 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 |
comparison
equal
deleted
inserted
replaced
742:24038e7a365b | 743:dd1f3382d6a4 |
---|---|
11 #include "mbfly_njs.h" | 11 #include "mbfly_njs.h" |
12 | 12 |
13 #ifndef ASSERT | 13 #ifndef ASSERT |
14 #define ASSERT(x) | 14 #define ASSERT(x) |
15 #endif | 15 #endif |
16 | |
17 #define OK 0 | |
16 | 18 |
17 /*! \page jsgc How to Manage Life-cycle of Objects for Javascript. | 19 /*! \page jsgc How to Manage Life-cycle of Objects for Javascript. |
18 * | 20 * |
19 * The life-cycle of MadButterfly ojects are simple. A object is live | 21 * The life-cycle of MadButterfly ojects are simple. A object is live |
20 * when it is created and dead when it is free. When a coord or shape | 22 * when it is created and dead when it is free. When a coord or shape |
103 Handle<Value> subject_o; | 105 Handle<Value> subject_o; |
104 | 106 |
105 /* Keep associated js object in property store for retrieving, | 107 /* Keep associated js object in property store for retrieving, |
106 * later, without create new js object. | 108 * later, without create new js object. |
107 */ | 109 */ |
108 self_hdl = new Persistent<Object>(self); | 110 self_hdl = new Persistent<Object>(); |
111 *self_hdl = Persistent<Object>::New(self); | |
109 mb_prop_set(&coord->obj.props, PROP_JSOBJ, self_hdl); | 112 mb_prop_set(&coord->obj.props, PROP_JSOBJ, self_hdl); |
110 | 113 |
111 subject = coord->mouse_event; | 114 subject = coord->mouse_event; |
112 subject_o = export_xnjsmb_auto_subject_new(subject); | 115 subject_o = export_xnjsmb_auto_subject_new(subject); |
113 SET(self, "mouse_event", subject_o); | 116 SET(self, "mouse_event", subject_o); |
161 | 164 |
162 static void | 165 static void |
163 xnjsmb_coord_remove(coord_t *coord, Handle<Object> self, const char **err) { | 166 xnjsmb_coord_remove(coord_t *coord, Handle<Object> self, const char **err) { |
164 Handle<Object> js_rt; | 167 Handle<Object> js_rt; |
165 redraw_man_t *rdman; | 168 redraw_man_t *rdman; |
169 int r; | |
166 | 170 |
167 js_rt = GET(self, "mbrt")->ToObject(); | 171 js_rt = GET(self, "mbrt")->ToObject(); |
168 rdman = xnjsmb_rt_rdman(js_rt); | 172 rdman = xnjsmb_rt_rdman(js_rt); |
169 | 173 |
170 xnjsmb_coord_invalidate_subtree(self); | 174 xnjsmb_coord_invalidate_subtree(self); |
171 | 175 |
172 /* Free all coords and shapes in the subtree */ | 176 /* Free all coords and shapes in the subtree */ |
173 rdman_coord_free(rdman, coord); | 177 r = rdman_coord_free(rdman, coord); |
178 if(r != OK) | |
179 *err = "Can not remove a coord"; | |
174 } | 180 } |
175 | 181 |
176 #include "coord-inc.h" | 182 #include "coord-inc.h" |
177 | 183 |
178 /*! \brief This function used by \ref xnjsmb_mb_rt to wrap coord object. | 184 /*! \brief This function used by \ref xnjsmb_mb_rt to wrap coord object. |