comparison lib/js/urweb.js @ 693:655bcc9b77e0

_Really_ implement embedded closure GC; extend Scriptcheck to figure out when client IDs must be assigned
author Adam Chlipala <adamc@hcoop.net>
date Sat, 04 Apr 2009 14:03:39 -0400
parents 09df0c85f306
children a5d8b470d7ca
comparison
equal deleted inserted replaced
692:09df0c85f306 693:655bcc9b77e0
20 } 20 }
21 21
22 22
23 // Embedding closures in XML strings 23 // Embedding closures in XML strings
24 24
25 function cs(f) {
26 return {closure: f};
27 }
28
29 function isWeird(v) {
30 return v.closure != null || v.cat1 != null;
31 }
32
25 function cat(s1, s2) { 33 function cat(s1, s2) {
26 if (s1.length && s2.length) 34 if (isWeird(s1) || isWeird(s2))
35 return {cat1: s1, cat2: s2};
36 else
27 return s1 + s2; 37 return s1 + s2;
28 else
29 return {_1: s1, _2: s2};
30 } 38 }
31 39
32 var closures = []; 40 var closures = [];
33 41
34 function newClosure(f) { 42 function newClosure(f) {
40 function cr(n) { 48 function cr(n) {
41 return closures[n](); 49 return closures[n]();
42 } 50 }
43 51
44 function flatten(tr) { 52 function flatten(tr) {
45 if (tr.length) 53 if (tr.cat1 != null)
54 return flatten(tr.cat1) + flatten(tr.cat2);
55 else if (tr.closure != null)
56 return "cr(" + newClosure(tr.closure) + ")";
57 else
46 return tr; 58 return tr;
47 else if (tr._1)
48 return cs(tr._1) + cs(tr._2);
49 else
50 return "cr(" + newClosure(tr) + ")";
51 } 59 }
52 60
53 function clearClosures() { 61 function clearClosures() {
54 closures = []; 62 closures = [];
55 } 63 }
155 span.dead = true; 163 span.dead = true;
156 for (var ls = span.sources; ls; ls = ls.next) 164 for (var ls = span.sources; ls; ls = ls.next)
157 ls.data.dyns = remove(span, ls.data.dyns); 165 ls.data.dyns = remove(span, ls.data.dyns);
158 } 166 }
159 167
160 x.innerHTML = v; 168 x.innerHTML = flatten(v);
161 runScripts(x); 169 runScripts(x);
162 170
163 if (--dynDepth == 0) 171 if (--dynDepth == 0)
164 clearClosures(); 172 clearClosures();
165 }; 173 };
410 enqueue(ch.listeners, function(msg) { k(parse(msg))(null); }); 418 enqueue(ch.listeners, function(msg) { k(parse(msg))(null); });
411 } else { 419 } else {
412 k(parse(msg))(null); 420 k(parse(msg))(null);
413 } 421 }
414 } 422 }
423
424
425 // App-specific code
426