# HG changeset patch # User Thinker K.F. Li # Date 1281106618 -28800 # Node ID a588eefd3f047cdfffec1d05e1bf7125e0699d1d # Parent 799c852b90658cdea918671813f0d83f3e10df93 Refactor to xnjsmb_coord_mod(). Move code of initializing attributes of JS coord objects to xnjsmb_coord_mod(). diff -r 799c852b9065 -r a588eefd3f04 nodejs/coord.cc --- a/nodejs/coord.cc Fri Aug 06 19:31:37 2010 +0800 +++ b/nodejs/coord.cc Fri Aug 06 22:56:58 2010 +0800 @@ -16,6 +16,23 @@ using namespace v8; +static void +xnjsmb_coord_mod(Handle self, coord_t *coord) { + Persistent *self_hdl; + subject_t *subject; + Handle subject_o; + + /* Keep associated js object in property store for retrieving, + * later, without create new js object. + */ + self_hdl = new Persistent(self); + mb_prop_set(&coord->obj.props, PROP_JSOBJ, self_hdl); + + subject = coord->mouse_event; + subject_o = export_xnjsmb_auto_subject_new(subject); + SET(self, "mouse_event", subject_o); +} + static float coord_get_index(coord_t *coord, Handle self, int idx, const char **err) { diff -r 799c852b9065 -r a588eefd3f04 nodejs/coord.m4 --- a/nodejs/coord.m4 Fri Aug 06 19:31:37 2010 +0800 +++ b/nodejs/coord.m4 Fri Aug 06 22:56:58 2010 +0800 @@ -3,4 +3,5 @@ [METHOD([add_shape], [xnjsmb_coord_add_shape], (SELF, OBJ([shape], [shape], [shape_t]), ERR), 1, [])], ((GET_INDEX, (coord_get_index, NUMBER)), - (SET_INDEX, (coord_set_index, NUMBER)))) + (SET_INDEX, (coord_set_index, NUMBER)), + ([STMOD], [xnjsmb_coord_mod]))) diff -r 799c852b9065 -r a588eefd3f04 nodejs/mbfly_njs.cc --- a/nodejs/mbfly_njs.cc Fri Aug 06 19:31:37 2010 +0800 +++ b/nodejs/mbfly_njs.cc Fri Aug 06 22:56:58 2010 +0800 @@ -28,22 +28,8 @@ static void xnjsmb_coord_new_mod(Handle mbrt, Handle ret) { Handle ret_obj = ret->ToObject(); - Persistent *ret_obj_hdl; - coord_t *coord; - subject_t *subject; - Handle subject_o; SET(ret_obj, "mbrt", mbrt); - coord = (coord_t *)UNWRAP(ret_obj); - /* Keep associated js object in property store for retrieving, - * later, without create new js object. - */ - ret_obj_hdl = new Persistent(ret_obj); - mb_prop_set(&coord->obj.props, PROP_JSOBJ, ret_obj_hdl); - - subject = coord->mouse_event; - subject_o = export_xnjsmb_auto_subject_new(subject); - SET(ret_obj, "subject", subject_o); } #define xnjsmb_auto_coord_new export_xnjsmb_auto_coord_new @@ -68,9 +54,7 @@ _X_njs_MB_new(Handle self, char *display_name, int width, int height) { njs_runtime_t *obj; - coord_t *root; subject_t *subject; - Handle root_o; Handle subject_o; obj = X_njs_MB_new(display_name, width, height); @@ -81,12 +65,6 @@ X_njs_MB_init_handle_connection(obj); xnjsmb_coord_mkroot(self); - root_o = GET(self, "root")->ToObject(); - root = (coord_t *)UNWRAP(root_o); - subject = root->mouse_event; - subject_o = export_xnjsmb_auto_subject_new(subject); - SET(root_o, "subject", subject_o); - subject = X_MB_kbevents(obj->xrt); subject_o = export_xnjsmb_auto_subject_new(subject); SET(self, "kbevent", subject_o); diff -r 799c852b9065 -r a588eefd3f04 nodejs/testcase.js --- a/nodejs/testcase.js Fri Aug 06 19:31:37 2010 +0800 +++ b/nodejs/testcase.js Fri Aug 06 22:56:58 2010 +0800 @@ -52,10 +52,10 @@ }, 20); setTimeout(function() { sys.puts("timeout"); }, 1000); -sys.puts(root.subject); +sys.puts(root.mouse_event); var observer; /* Mouse button pressed */ -observer = root.subject.add_event_observer(4, function(evt) { +observer = root.mouse_event.add_event_observer(4, function(evt) { sys.puts("mouse " + evt.x + " " + evt.y); });