comparison lib/js/urweb.js @ 1792:3d823d8424cc

Disallow suspending operations in <active code={...}>
author Adam Chlipala <adam@chlipala.net>
date Mon, 23 Jul 2012 09:03:41 -0400
parents 2f8b8952fe27
children 446e73902b09
comparison
equal deleted inserted replaced
1791:2f8b8952fe27 1792:3d823d8424cc
911 x.closures = cls.v; 911 x.closures = cls.v;
912 node.innerHTML = html; 912 node.innerHTML = html;
913 runScripts(node); 913 runScripts(node);
914 } 914 }
915 915
916 var maySuspend = true;
917
916 function active(s) { 918 function active(s) {
917 var span = document.createElement("span"); 919 var span = document.createElement("span");
918 addNode(span); 920 addNode(span);
919 setInnerHTML(span, execF(s)); 921 var ms = maySuspend;
922 maySuspend = false;
923 try {
924 var html = execF(s);
925 } catch (e) {
926 maySuspend = ms;
927 throw e;
928 }
929 maySuspend = ms;
930 setInnerHTML(span, html);
920 } 931 }
921 932
922 function input(x, s, recreate, type, name) { 933 function input(x, s, recreate, type, name) {
923 if (name) x.name = name; 934 if (name) x.name = name;
924 if (type) x.type = type; 935 if (type) x.type = type;
1000 html = flatten(htmlCls, html); 1011 html = flatten(htmlCls, html);
1001 htmlCls = htmlCls.v; 1012 htmlCls = htmlCls.v;
1002 1013
1003 var dummy = document.createElement("body"); 1014 var dummy = document.createElement("body");
1004 dummy.innerHTML = html; 1015 dummy.innerHTML = html;
1005 runScripts(dummy);
1006 var html = dummy.firstChild; 1016 var html = dummy.firstChild;
1007 dummy.removeChild(html); 1017 dummy.removeChild(html);
1008 addNode(html); 1018 addNode(html);
1019 runScripts(html);
1009 1020
1010 if (s_class) { 1021 if (s_class) {
1011 var x = document.createElement("script"); 1022 var x = document.createElement("script");
1012 x.dead = false; 1023 x.dead = false;
1013 x.signal = s_class; 1024 x.signal = s_class;
1283 function redirect(s) { 1294 function redirect(s) {
1284 window.location = s; 1295 window.location = s;
1285 } 1296 }
1286 1297
1287 function rc(prefix, uri, parse, k, needsSig) { 1298 function rc(prefix, uri, parse, k, needsSig) {
1299 if (!maySuspend)
1300 er("May not 'rpc' in 'code' for <active>");
1301
1288 uri = cat(prefix, uri); 1302 uri = cat(prefix, uri);
1289 uri = flattenLocal(uri); 1303 uri = flattenLocal(uri);
1290 var xhr = getXHR(); 1304 var xhr = getXHR();
1291 1305
1292 xhr.onreadystatechange = function() { 1306 xhr.onreadystatechange = function() {
1461 1475
1462 connect(); 1476 connect();
1463 } 1477 }
1464 1478
1465 function rv(chn, parse, k) { 1479 function rv(chn, parse, k) {
1480 if (!maySuspend)
1481 er("May not 'recv' in 'code' for <active>");
1482
1466 if (chn == null) 1483 if (chn == null)
1467 return; 1484 return;
1468 1485
1469 if (chn < 0) 1486 if (chn < 0)
1470 whine("Out-of-bounds channel receive"); 1487 whine("Out-of-bounds channel receive");
1488 } 1505 }
1489 } 1506 }
1490 } 1507 }
1491 1508
1492 function sl(ms, k) { 1509 function sl(ms, k) {
1510 if (!maySuspend)
1511 er("May not 'sleep' in 'code' for <active>");
1512
1493 window.setTimeout(function() { k(null); }, ms); 1513 window.setTimeout(function() { k(null); }, ms);
1494 } 1514 }
1495 1515
1496 function sp(e) { 1516 function sp(e) {
1497 execF(e, null); 1517 execF(e, null);