comparison lib/js/urweb.js @ 798:83875a9eb9b8

Improvements while working on Graftid
author Adam Chlipala <adamc@hcoop.net>
date Thu, 14 May 2009 10:31:11 -0400
parents 2c463eee89fa
children e92cfac1608f
comparison
equal deleted inserted replaced
797:2c463eee89fa 798:83875a9eb9b8
32 32
33 function pf() { 33 function pf() {
34 whine("Pattern match failure"); 34 whine("Pattern match failure");
35 } 35 }
36 36
37 function runHandlers(ls, arg) { 37 function runHandlers(kind, ls, arg) {
38 if (ls == null)
39 alert(kind + ": " + arg);
38 for (; ls; ls = ls.next) 40 for (; ls; ls = ls.next)
39 try { 41 try {
40 ls.data(arg)(null); 42 ls.data(arg)(null);
41 } catch (v) { } 43 } catch (v) { }
42 } 44 }
46 function onError(f) { 48 function onError(f) {
47 errorHandlers = cons(f, errorHandlers); 49 errorHandlers = cons(f, errorHandlers);
48 } 50 }
49 51
50 function er(s) { 52 function er(s) {
51 runHandlers(errorHandlers, s); 53 runHandlers("Error", errorHandlers, s);
52 throw {uw_error: s}; 54 throw {uw_error: s};
53 } 55 }
54 56
55 var failHandlers = null; 57 var failHandlers = null;
56 58
59 } 61 }
60 62
61 function doExn(v) { 63 function doExn(v) {
62 if (v == null || v.uw_error == null) { 64 if (v == null || v.uw_error == null) {
63 var s = (v == null ? "null" : v.toString()); 65 var s = (v == null ? "null" : v.toString());
64 runHandlers(failHandlers, s); 66 runHandlers("Fail", failHandlers, s);
65 } 67 }
66 } 68 }
67 69
68 var disconnectHandlers = null; 70 var disconnectHandlers = null;
69 71
70 function onDisconnect(f) { 72 function onDisconnect(f) {
71 disconnectHandlers = cons(function (_){return f}, disconnectHandlers); 73 disconnectHandlers = cons(function (_){return f}, disconnectHandlers);
72 } 74 }
73 75
74 function discon() { 76 function discon() {
75 runHandlers(disconnectHandlers, null); 77 runHandlers("Disconnect", disconnectHandlers, null);
76 } 78 }
77 79
78 var connectHandlers = null; 80 var connectHandlers = null;
79 81
80 function onConnectFail(f) { 82 function onConnectFail(f) {
81 connectHandlers = cons(function (_){return f}, connectHandlers); 83 connectHandlers = cons(function (_){return f}, connectHandlers);
82 } 84 }
83 85
84 function conn() { 86 function conn() {
85 runHandlers(connectHandlers, null); 87 runHandlers("Connect", connectHandlers, null);
86 } 88 }
87 89
88 var serverHandlers = null; 90 var serverHandlers = null;
89 91
90 function onServerError(f) { 92 function onServerError(f) {
91 serverHandlers = cons(f, serverHandlers); 93 serverHandlers = cons(f, serverHandlers);
92 } 94 }
93 95
94 function servErr(s) { 96 function servErr(s) {
95 runHandlers(serverHandlers, s); 97 runHandlers("Server", serverHandlers, s);
96 } 98 }
97 99
98 100
99 // Embedding closures in XML strings 101 // Embedding closures in XML strings
100 102