Mercurial > MadButterfly
comparison nodejs/coord.cc @ 739:4916c3a3fe3c
Design doc for life-cycle of MB objects for JS
author | Thinker K.F. Li <thinker@codemud.net> |
---|---|
date | Mon, 23 Aug 2010 10:23:30 +0800 |
parents | 763a4e2bbd85 |
children | d8764f10e141 |
comparison
equal
deleted
inserted
replaced
738:4f9773574234 | 739:4916c3a3fe3c |
---|---|
11 #include "mbfly_njs.h" | 11 #include "mbfly_njs.h" |
12 | 12 |
13 #ifndef ASSERT | 13 #ifndef ASSERT |
14 #define ASSERT(x) | 14 #define ASSERT(x) |
15 #endif | 15 #endif |
16 | |
17 /*! \page jsgc How to Manage Life-cycle of Objects for Javascript. | |
18 * | |
19 * The life-cycle of MadButterfly ojects are simple. A object is live | |
20 * when it is created and dead when it is free. When a coord or shape | |
21 * is free, it is also removed from the tree. There is not way to | |
22 * remove a coord or a shape without freeing it. So, if you want to | |
23 * remove a coord or a shape object from the tree, you can only free | |
24 * it. | |
25 * | |
26 * Javascript, in conventional, does not free an object. It has GC, | |
27 * the engine, being used, will free an object if it is no more | |
28 * referenced. So, we had better provide a removing function, but | |
29 * actually free an object. In idea situation, a new MB object would | |
30 * be created for and attached on the JS object, when an object added | |
31 * back to the tree. But, it means we need to keep states of an | |
32 * object and create a new one with the same states later. It is | |
33 * complicated. So, once an object is removed, it is invalidated. | |
34 * | |
35 * I hope someone would implement a higher abstract layer, in JS, to | |
36 * implement the idea model that recreate a new object when an | |
37 * invalidated JS object being added back. | |
38 * | |
39 * An invalid object is the one with NULL internal field and obj.valid | |
40 * == false. The binding of MadButterfly hold a reference to every | |
41 * object added to the tree of a mbrt (runtime object), and remove the | |
42 * reference and invalidate it when it being removed. | |
43 * | |
44 * The binding also hold a weak reference to every object, it free the | |
45 * object when the callback of the weak reference being called and it | |
46 * being valid. If the object is invalid, the callback does nothing. | |
47 */ | |
16 | 48 |
17 using namespace v8; | 49 using namespace v8; |
18 | 50 |
19 /*! \defgroup xnjsmb_coord JS binding for coord objects. | 51 /*! \defgroup xnjsmb_coord JS binding for coord objects. |
20 * \ingroup xnjsmb | 52 * \ingroup xnjsmb |