Mercurial > MadButterfly
changeset 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 |
files | nodejs/coord.cc nodejs/shapes.cc nodejs/shapes.m4 nodejs/testcase.js |
diffstat | 4 files changed, 29 insertions(+), 6 deletions(-) [+] |
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"
--- 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<Object> self, shape_t *sh) { + Persistent<Object> *self_hdl; + + /* Keep associated js object in property store for retrieving, + * later, without create new js object. + */ + self_hdl = new Persistent<Object>(); + *self_hdl = Persistent<Object>::New(self); + mb_prop_set(&sh->obj.props, PROP_JSOBJ, self_hdl); +} + +static void xnjsmb_sh_stext_set_style(shape_t *sh, Handle<Object> self, Handle<Value> blks, const char **err) { Array *blksobj;
--- 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])))
--- 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);