summaryrefslogtreecommitdiff
path: root/lib/js
diff options
context:
space:
mode:
authorGravatar Adam Chlipala <adam@chlipala.net>2013-04-16 10:55:48 -0400
committerGravatar Adam Chlipala <adam@chlipala.net>2013-04-16 10:55:48 -0400
commitf4dbd4d3e80432cf1bd41d7f423580da153f11b8 (patch)
tree2dba7c473ff3a8063145c3cd8506ac9013faa904 /lib/js
parent82e400315d526eb6c96fd1ad21a8ce75529f7717 (diff)
Basis.tryRpc
Diffstat (limited to 'lib/js')
-rw-r--r--lib/js/urweb.js41
1 files changed, 30 insertions, 11 deletions
diff --git a/lib/js/urweb.js b/lib/js/urweb.js
index cc65ab8f..f56ba4c6 100644
--- a/lib/js/urweb.js
+++ b/lib/js/urweb.js
@@ -1365,7 +1365,14 @@ function redirect(s) {
window.location = s;
}
-function rc(prefix, uri, parse, k, needsSig) {
+function makeSome(isN, v) {
+ if (isN)
+ return {v: v};
+ else
+ return v;
+}
+
+function rc(prefix, uri, parse, k, needsSig, isN) {
if (!maySuspend)
er("May not 'rpc' in main thread of 'code' for <active>");
@@ -1384,18 +1391,30 @@ function rc(prefix, uri, parse, k, needsSig) {
if (isok) {
var lines = xhr.responseText.split("\n");
- if (lines.length != 2)
- whine("Bad RPC response lines");
-
- eval(lines[0]);
-
- try {
- k(parse(lines[1]));
- } catch (v) {
- doExn(v);
+ if (lines.length != 2) {
+ if (isN == null)
+ whine("Bad RPC response lines");
+ else
+ k(null);
+ } else {
+ eval(lines[0]);
+
+ try {
+ var v = parse(lines[1]);
+ try {
+ k(makeSome(isN, v));
+ } catch (v) {
+ doExn(v);
+ }
+ } catch (v) {
+ k(null);
+ }
}
} else {
- conn();
+ if (isN == null)
+ conn();
+ else
+ k(null);
}
xhrFinished(xhr);