# HG changeset patch # User Thinker K.F. Li # Date 1282715929 -28800 # Node ID dd1f3382d6a472e0ade9ce4ae7d9a6e77f23d40d # Parent 24038e7a365b8bfc4d5f1e75029329b54c70f125 Create a persistent handle for coords and shapes correctly diff -r 24038e7a365b -r dd1f3382d6a4 nodejs/coord.cc --- 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(self); + self_hdl = new Persistent(); + *self_hdl = Persistent::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 self, const char **err) { Handle 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" diff -r 24038e7a365b -r dd1f3382d6a4 nodejs/shapes.cc --- a/nodejs/shapes.cc Wed Aug 25 11:58:30 2010 +0800 +++ b/nodejs/shapes.cc Wed Aug 25 13:58:49 2010 +0800 @@ -19,6 +19,18 @@ * @{ */ static void +xnjsmb_shape_mod(Handle self, shape_t *sh) { + Persistent *self_hdl; + + /* Keep associated js object in property store for retrieving, + * later, without create new js object. + */ + self_hdl = new Persistent(); + *self_hdl = Persistent::New(self); + mb_prop_set(&sh->obj.props, PROP_JSOBJ, self_hdl); +} + +static void xnjsmb_sh_stext_set_style(shape_t *sh, Handle self, Handle blks, const char **err) { Array *blksobj; diff -r 24038e7a365b -r dd1f3382d6a4 nodejs/shapes.m4 --- a/nodejs/shapes.m4 Wed Aug 25 11:58:30 2010 +0800 +++ b/nodejs/shapes.m4 Wed Aug 25 13:58:49 2010 +0800 @@ -13,12 +13,13 @@ [METHOD([set_text], [sh_stext_set_text], (STR([txt])), 1, []), METHOD([set_style], [xnjsmb_sh_stext_set_style], (SELF, ARRAY([blks]), ERR), 1, [])], - (([INHERIT], [shape]))) + (([INHERIT], [shape]), ([STMOD], [xnjsmb_shape_mod]))) -STRUCT([image], [shape_t], [], [], (([INHERIT], [shape]))) +STRUCT([image], [shape_t], [], [], + (([INHERIT], [shape]), ([STMOD], [xnjsmb_shape_mod]))) STRUCT([rect], [shape_t], [], [METHOD([set], [xnjsmb_sh_rect_set], (SELF, NUMBER(x), NUMBER(y), NUMBER(w), NUMBER(h), NUMBER(rx), NUMBER(ry)), 6, [])], - (([INHERIT], [shape]))) + (([INHERIT], [shape]), ([STMOD], [xnjsmb_shape_mod]))) diff -r 24038e7a365b -r dd1f3382d6a4 nodejs/testcase.js --- a/nodejs/testcase.js Wed Aug 25 11:58:30 2010 +0800 +++ b/nodejs/testcase.js Wed Aug 25 13:58:49 2010 +0800 @@ -47,7 +47,11 @@ var rm_rect = mb_rt.rect_new(150, 150, 50, 50, 10, 10); paint.fill(rm_rect); rm_coord.add_shape(rm_rect); -setTimeout(function() { rm_coord.remove(); }, 3000); +setTimeout(function() { + rm_coord.remove(); + mb_rt.redraw_changed(); + mb_rt.flush(); + }, 3000); /* Moving a path */ sys.puts(mb_rt.path_new);