summaryrefslogtreecommitdiff
path: root/lib/js
diff options
context:
space:
mode:
authorGravatar Adam Chlipala <adam@chlipala.net>2012-07-23 09:03:41 -0400
committerGravatar Adam Chlipala <adam@chlipala.net>2012-07-23 09:03:41 -0400
commit8a2b82151a52f3c2e99d60b76026b22b088b9e56 (patch)
tree4e519e4d4a0bd9a3e0c823866ff23c65992e4d03 /lib/js
parent0cb456bbab73abfd9c08af101d1dfe71cf2d41d4 (diff)
Disallow suspending operations in <active code={...}>
Diffstat (limited to 'lib/js')
-rw-r--r--lib/js/urweb.js24
1 files changed, 22 insertions, 2 deletions
diff --git a/lib/js/urweb.js b/lib/js/urweb.js
index 63aab9b5..4435bffa 100644
--- a/lib/js/urweb.js
+++ b/lib/js/urweb.js
@@ -913,10 +913,21 @@ function setInnerHTML(node, html) {
runScripts(node);
}
+var maySuspend = true;
+
function active(s) {
var span = document.createElement("span");
addNode(span);
- setInnerHTML(span, execF(s));
+ var ms = maySuspend;
+ maySuspend = false;
+ try {
+ var html = execF(s);
+ } catch (e) {
+ maySuspend = ms;
+ throw e;
+ }
+ maySuspend = ms;
+ setInnerHTML(span, html);
}
function input(x, s, recreate, type, name) {
@@ -1002,10 +1013,10 @@ function dynClass(html, s_class, s_style) {
var dummy = document.createElement("body");
dummy.innerHTML = html;
- runScripts(dummy);
var html = dummy.firstChild;
dummy.removeChild(html);
addNode(html);
+ runScripts(html);
if (s_class) {
var x = document.createElement("script");
@@ -1285,6 +1296,9 @@ function redirect(s) {
}
function rc(prefix, uri, parse, k, needsSig) {
+ if (!maySuspend)
+ er("May not 'rpc' in 'code' for <active>");
+
uri = cat(prefix, uri);
uri = flattenLocal(uri);
var xhr = getXHR();
@@ -1463,6 +1477,9 @@ function listener() {
}
function rv(chn, parse, k) {
+ if (!maySuspend)
+ er("May not 'recv' in 'code' for <active>");
+
if (chn == null)
return;
@@ -1490,6 +1507,9 @@ function rv(chn, parse, k) {
}
function sl(ms, k) {
+ if (!maySuspend)
+ er("May not 'sleep' in 'code' for <active>");
+
window.setTimeout(function() { k(null); }, ms);
}