diff lib/js/urweb.js @ 1848:e15234fbb163

Basis.tryRpc
author Adam Chlipala <adam@chlipala.net>
date Tue, 16 Apr 2013 10:55:48 -0400
parents a8b273f1f7e3
children c40ed80be943
line wrap: on
line diff
--- a/lib/js/urweb.js	Mon Apr 01 10:13:49 2013 -0400
+++ b/lib/js/urweb.js	Tue Apr 16 10:55:48 2013 -0400
@@ -1365,7 +1365,14 @@
     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 @@
 
             if (isok) {
                 var lines = xhr.responseText.split("\n");
-                if (lines.length != 2)
-                    whine("Bad RPC response lines");
+                if (lines.length != 2) {
+                    if (isN == null)
+                        whine("Bad RPC response lines");
+                    else
+                        k(null);
+                } else {
+                    eval(lines[0]);
 
-                eval(lines[0]);
-
-                try {
-                    k(parse(lines[1]));
-                } catch (v) {
-                    doExn(v);
+                    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);