summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/js/urweb.js24
-rw-r--r--tests/setActive.ur9
2 files changed, 31 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);
}
diff --git a/tests/setActive.ur b/tests/setActive.ur
new file mode 100644
index 00000000..e937c1d9
--- /dev/null
+++ b/tests/setActive.ur
@@ -0,0 +1,9 @@
+fun main () : transaction page =
+ i <- fresh;
+ x <- source <xml/>;
+ return <xml>
+ <body>
+ <dyn signal={signal x} />
+ <active code={set x <xml><ctextbox/><ctextbox id={i}/><ctextbox/><active code={giveFocus i; return <xml/>}/></xml>; return <xml/>}/>
+ </body>
+ </xml>