RPA Toolkit
898c61bbea78c177d4d670895572aa8e5fd76795
[rpatk.git] / rlib / rjsobject.c
1 #include "rjsobject.h"
2 #include "rmem.h"
3
4
5
6 void rjs_object_cleanup(robject_t *obj)
7 {
8         rjs_object_t *jso = (rjs_object_t *)obj;
9         r_object_destroy((robject_t*)jso->harray);
10         r_object_destroy((robject_t*)jso->narray);
11 }
12
13
14 robject_t *rjs_object_init(robject_t *obj, ruint32 type, r_object_cleanupfun cleanup, r_object_copyfun copy, ruint elt_size)
15 {
16         rjs_object_t *jso = (rjs_object_t *)obj;
17
18         r_object_init(obj, type, cleanup, copy);
19         jso->harray = r_harray_create(elt_size);
20         jso->narray = r_carray_create(elt_size);
21         return obj;
22 }
23
24
25 rjs_object_t *rjs_object_create(ruint elt_size)
26 {
27         rjs_object_t *jso;
28         jso = (rjs_object_t*)r_object_create(sizeof(*jso));
29         rjs_object_init((robject_t*)jso, R_OBJECT_JSOBJECT, rjs_object_cleanup, rjs_object_copy, elt_size);
30         return jso;
31 }
32
33
34 robject_t *rjs_object_copy(const robject_t *obj)
35 {
36         rjs_object_t *jso;
37         jso = (rjs_object_t*)r_object_create(sizeof(*jso));
38         jso->harray = (rharray_t*)r_object_v_copy((robject_t *)((rjs_object_t *)obj)->harray);
39         jso->narray = (rcarray_t*)r_object_v_copy((robject_t *)((rjs_object_t *)obj)->narray);
40         return (robject_t*)jso;
41 }
42