Mercurial > MadButterfly
comparison nodejs/shapes.cc @ 675:c643af2095c5
Keep and retrieve respective js object to/from property store
author | Thinker K.F. Li <thinker@branda.to> |
---|---|
date | Fri, 06 Aug 2010 00:56:26 +0800 |
parents | fc29a343ce7c |
children | 7685c57e29d0 |
comparison
equal
deleted
inserted
replaced
674:5c8387fd123e | 675:c643af2095c5 |
---|---|
123 xnjsmb_shape_path(const Arguments &args) { | 123 xnjsmb_shape_path(const Arguments &args) { |
124 shape_t *sh; | 124 shape_t *sh; |
125 redraw_man_t *rdman; | 125 redraw_man_t *rdman; |
126 Handle<Object> self = args.This(); // path object | 126 Handle<Object> self = args.This(); // path object |
127 Handle<Object> rt; | 127 Handle<Object> rt; |
128 Persistent<Object> *self_hdl; | |
128 char *dstr; | 129 char *dstr; |
129 int argc; | 130 int argc; |
130 | 131 |
131 argc = args.Length(); | 132 argc = args.Length(); |
132 if(argc != 2) | 133 if(argc != 2) |
143 rdman = xnjsmb_rt_rdman(rt); | 144 rdman = xnjsmb_rt_rdman(rt); |
144 sh = rdman_shape_path_new(rdman, dstr); | 145 sh = rdman_shape_path_new(rdman, dstr); |
145 | 146 |
146 WRAP(self, sh); | 147 WRAP(self, sh); |
147 SET(self, "mbrt", rt); | 148 SET(self, "mbrt", rt); |
148 mb_prop_set(&sh->obj.props, PROP_JSOBJ, *self); | 149 /* Keep associated js object in property store for retrieving, |
150 * later, without create new js object. | |
151 */ | |
152 self_hdl = new Persistent<Object>(self); | |
153 mb_prop_set(&sh->obj.props, PROP_JSOBJ, self_hdl); | |
149 | 154 |
150 return Null(); | 155 return Null(); |
151 } | 156 } |
152 | 157 |
153 /*! \brief Initial function template for constructor of path objects. | 158 /*! \brief Initial function template for constructor of path objects. |
210 static Handle<Value> | 215 static Handle<Value> |
211 xnjsmb_shape_stext(const Arguments &args) { | 216 xnjsmb_shape_stext(const Arguments &args) { |
212 int argc = args.Length(); | 217 int argc = args.Length(); |
213 Handle<Object> self = args.This(); | 218 Handle<Object> self = args.This(); |
214 Handle<Object> rt; | 219 Handle<Object> rt; |
220 Persistent<Object> *self_hdl; | |
215 float x, y; | 221 float x, y; |
216 char *data; | 222 char *data; |
217 redraw_man_t *rdman; | 223 redraw_man_t *rdman; |
218 shape_t *stext; | 224 shape_t *stext; |
219 | 225 |
234 | 240 |
235 stext = rdman_shape_stext_new(rdman, data, x, y); | 241 stext = rdman_shape_stext_new(rdman, data, x, y); |
236 | 242 |
237 WRAP(self, stext); | 243 WRAP(self, stext); |
238 SET(self, "mbrt", rt); | 244 SET(self, "mbrt", rt); |
239 mb_prop_set(&stext->obj.props, PROP_JSOBJ, *self); | 245 /* Keep associated js object in property store for retrieving, |
246 * later, without create new js object. | |
247 */ | |
248 self_hdl = new Persistent<Object>(self); | |
249 mb_prop_set(&stext->obj.props, PROP_JSOBJ, self_hdl); | |
240 | 250 |
241 return Null(); | 251 return Null(); |
242 } | 252 } |
243 | 253 |
244 static Persistent<FunctionTemplate> xnjsmb_shape_stext_temp; | 254 static Persistent<FunctionTemplate> xnjsmb_shape_stext_temp; |
347 static Handle<Value> | 357 static Handle<Value> |
348 xnjsmb_shape_image(const Arguments &args) { | 358 xnjsmb_shape_image(const Arguments &args) { |
349 int argc = args.Length(); | 359 int argc = args.Length(); |
350 Handle<Object> self = args.This(); | 360 Handle<Object> self = args.This(); |
351 Handle<Object> rt; | 361 Handle<Object> rt; |
362 Persistent<Object> *self_hdl; | |
352 float x, y; | 363 float x, y; |
353 float w, h; | 364 float w, h; |
354 redraw_man_t *rdman; | 365 redraw_man_t *rdman; |
355 shape_t *img; | 366 shape_t *img; |
356 | 367 |
370 rdman = xnjsmb_rt_rdman(rt); | 381 rdman = xnjsmb_rt_rdman(rt); |
371 img = rdman_shape_image_new(rdman, x, y, w, h); | 382 img = rdman_shape_image_new(rdman, x, y, w, h); |
372 | 383 |
373 WRAP(self, img); | 384 WRAP(self, img); |
374 SET(self, "mbrt", rt); | 385 SET(self, "mbrt", rt); |
375 mb_prop_set(&img->obj.props, PROP_JSOBJ, *self); | 386 /* Keep associated js object in property store for retrieving, |
387 * later, without create new js object. | |
388 */ | |
389 self_hdl = new Persistent<Object>(self); | |
390 mb_prop_set(&img->obj.props, PROP_JSOBJ, self_hdl); | |
376 | 391 |
377 return Null(); | 392 return Null(); |
378 } | 393 } |
379 | 394 |
380 static Persistent<FunctionTemplate> xnjsmb_shape_image_temp; | 395 static Persistent<FunctionTemplate> xnjsmb_shape_image_temp; |