# HG changeset patch # User Thinker K.F. Li # Date 1281027386 -28800 # Node ID c643af2095c5343839a1802d05087618dac080ce # Parent 5c8387fd123ee7cf1e77a37e6ee58c9d68729df1 Keep and retrieve respective js object to/from property store diff -r 5c8387fd123e -r c643af2095c5 nodejs/mbfly_njs.cc --- a/nodejs/mbfly_njs.cc Fri Aug 06 00:50:40 2010 +0800 +++ b/nodejs/mbfly_njs.cc Fri Aug 06 00:56:26 2010 +0800 @@ -28,11 +28,16 @@ static void xnjsmb_coord_mod(Handle mbrt, Handle ret) { Handle ret_obj = ret->ToObject(); + Persistent *ret_obj_hdl; coord_t *coord; SET(ret_obj, "mbrt", mbrt); coord = (coord_t *)UNWRAP(ret_obj); - mb_prop_set(&coord->obj.props, PROP_JSOBJ, *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); } #define xnjsmb_auto_coord_new export_xnjsmb_auto_coord_new diff -r 5c8387fd123e -r c643af2095c5 nodejs/mbfly_njs.h --- a/nodejs/mbfly_njs.h Fri Aug 06 00:50:40 2010 +0800 +++ b/nodejs/mbfly_njs.h Fri Aug 06 00:56:26 2010 +0800 @@ -12,6 +12,12 @@ exc = v8::Exception::Error(v8::String::New(x)); \ return v8::ThrowException(exc); \ } while(0) +#define THROW_noret(x) \ + do { \ + v8::Handle exc; \ + exc = v8::Exception::Error(v8::String::New(x)); \ + v8::ThrowException(exc); \ + } while(0) #define UNWRAP(o) v8::External::Unwrap((o)->GetInternalField(0)) #define WRAP(o, v) (o)->SetInternalField(0, v8::External::Wrap(v)) #define SET(o, n, v) (o)->Set(v8::String::New(n), v) diff -r 5c8387fd123e -r c643af2095c5 nodejs/observer.cc --- a/nodejs/observer.cc Fri Aug 06 00:50:40 2010 +0800 +++ b/nodejs/observer.cc Fri Aug 06 00:56:26 2010 +0800 @@ -45,6 +45,39 @@ delete data; } +static Handle +xnjsmb_event_tgt_getter(Handle self, event_t *evt, const char **err) { + Persistent *hdl; + + hdl = (Persistent *) + mb_prop_get(&((mb_obj_t *)evt->tgt)->props, + PROP_JSOBJ); + return Local::New(*hdl); +} + +static void +xnjsmb_event_tgt_setter(Handle self, event_t *evt, + Handle value, const char **err) { + *err = "Not implemented"; +} + +static Handle +xnjsmb_event_cur_tgt_getter(Handle self, event_t *evt, + const char **err) { + Persistent *hdl; + + hdl = (Persistent *) + mb_prop_get(&((mb_obj_t *)evt->cur_tgt)->props, + PROP_JSOBJ); + return Local::New(*hdl); +} + +static void +xnjsmb_event_cur_tgt_setter(Handle self, event_t *evt, + Handle value, const char **err) { + *err = "Not implemented"; +} + /* This is the part of the code generated by gen_v8_binding.m4 */ #include "observer-inc.h" diff -r 5c8387fd123e -r c643af2095c5 nodejs/observer.m4 --- a/nodejs/observer.m4 Fri Aug 06 00:50:40 2010 +0800 +++ b/nodejs/observer.m4 Fri Aug 06 00:56:26 2010 +0800 @@ -11,5 +11,8 @@ (OBJ([observer], [observer], [observer_t])), 1, [])]) STRUCT([event], [event_t], - [INT([type]), OBJ([tgt], [subject], [subject_t]), - OBJ([cur_tgt], [subject], [subject_t]), INT([flags])], []) + [INT([type]), + ACCESSOR([tgt], [xnjsmb_event_tgt_getter], [xnjsmb_event_tgt_setter]), + ACCESSOR([cur_tgt], [xnjsmb_event_cur_tgt_getter], + [xnjsmb_event_cur_tgt_setter]), + INT([flags])], []) diff -r 5c8387fd123e -r c643af2095c5 nodejs/shapes.cc --- a/nodejs/shapes.cc Fri Aug 06 00:50:40 2010 +0800 +++ b/nodejs/shapes.cc Fri Aug 06 00:56:26 2010 +0800 @@ -125,6 +125,7 @@ redraw_man_t *rdman; Handle self = args.This(); // path object Handle rt; + Persistent *self_hdl; char *dstr; int argc; @@ -145,7 +146,11 @@ WRAP(self, sh); SET(self, "mbrt", rt); - mb_prop_set(&sh->obj.props, PROP_JSOBJ, *self); + /* Keep associated js object in property store for retrieving, + * later, without create new js object. + */ + self_hdl = new Persistent(self); + mb_prop_set(&sh->obj.props, PROP_JSOBJ, self_hdl); return Null(); } @@ -212,6 +217,7 @@ int argc = args.Length(); Handle self = args.This(); Handle rt; + Persistent *self_hdl; float x, y; char *data; redraw_man_t *rdman; @@ -236,7 +242,11 @@ WRAP(self, stext); SET(self, "mbrt", rt); - mb_prop_set(&stext->obj.props, PROP_JSOBJ, *self); + /* Keep associated js object in property store for retrieving, + * later, without create new js object. + */ + self_hdl = new Persistent(self); + mb_prop_set(&stext->obj.props, PROP_JSOBJ, self_hdl); return Null(); } @@ -349,6 +359,7 @@ int argc = args.Length(); Handle self = args.This(); Handle rt; + Persistent *self_hdl; float x, y; float w, h; redraw_man_t *rdman; @@ -372,7 +383,11 @@ WRAP(self, img); SET(self, "mbrt", rt); - mb_prop_set(&img->obj.props, PROP_JSOBJ, *self); + /* Keep associated js object in property store for retrieving, + * later, without create new js object. + */ + self_hdl = new Persistent(self); + mb_prop_set(&img->obj.props, PROP_JSOBJ, self_hdl); return Null(); }