changeset 742:24038e7a365b

Reorder instructions to invalidate coords correctly
author Thinker K.F. Li <thinker@codemud.net>
date Wed, 25 Aug 2010 11:58:30 +0800
parents d8764f10e141
children dd1f3382d6a4
files nodejs/coord.cc nodejs/testcase.js
diffstat 2 files changed, 15 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/nodejs/coord.cc	Wed Aug 25 10:40:30 2010 +0800
+++ b/nodejs/coord.cc	Wed Aug 25 11:58:30 2010 +0800
@@ -67,8 +67,8 @@
  */
 static void
 xnjsmb_coord_invalidate_subtree(Handle<Object> self) {
-    Handle<Object> *child_hdl;
-    Handle<Object> *mem_hdl;
+    Persistent<Object> *child_hdl;
+    Persistent<Object> *mem_hdl;
     redraw_man_t *rdman;
     coord_t *coord, *child;
     shape_t *mem;
@@ -81,18 +81,17 @@
     
     /* Invalidate all coords in the subtree */
     FOR_COORDS_PREORDER(coord, child) {
-	child_hdl = (Handle<Object> *)mb_prop_get(&child->obj.props,
-						   PROP_JSOBJ);
-	child = (coord_t *)UNWRAP(*child_hdl);
+	child_hdl = (Persistent<Object> *)mb_prop_get(&child->obj.props,
+						      PROP_JSOBJ);
+	SET(*child_hdl, "valid", _false);
 	WRAP(*child_hdl, NULL);
-	SET(*child_hdl, "valid", _false);
 	
 	/* Invalidate members of a coord */
 	FOR_COORD_SHAPES(child, mem) {
-	    mem_hdl = (Handle<Object> *)mb_prop_get(&mem->obj.props,
-						    PROP_JSOBJ);
+	    mem_hdl = (Persistent<Object> *)mb_prop_get(&mem->obj.props,
+							PROP_JSOBJ);
+	    SET(*mem_hdl, "valid", _false);
 	    WRAP(*mem_hdl, NULL);
-	    SET(*mem_hdl, "valid", _false);
 	}
     }
 }
--- a/nodejs/testcase.js	Wed Aug 25 10:40:30 2010 +0800
+++ b/nodejs/testcase.js	Wed Aug 25 11:58:30 2010 +0800
@@ -42,6 +42,13 @@
 paint.fill(rect);
 root.add_shape(rect);
 
+/* test removing a coord */
+var rm_coord = mb_rt.coord_new(root);
+var rm_rect = mb_rt.rect_new(150, 150, 50, 50, 10, 10);
+paint.fill(rm_rect);
+rm_coord.add_shape(rm_rect);
+setTimeout(function() { rm_coord.remove(); }, 3000);
+
 /* Moving a path */
 sys.puts(mb_rt.path_new);
 var path = mb_rt.path_new("m 100,50 L 120,50 L 200,150 L 180,150 z");