comparison 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
comparison
equal deleted inserted replaced
1847:8958b580d026 1848:e15234fbb163
1363 1363
1364 function redirect(s) { 1364 function redirect(s) {
1365 window.location = s; 1365 window.location = s;
1366 } 1366 }
1367 1367
1368 function rc(prefix, uri, parse, k, needsSig) { 1368 function makeSome(isN, v) {
1369 if (isN)
1370 return {v: v};
1371 else
1372 return v;
1373 }
1374
1375 function rc(prefix, uri, parse, k, needsSig, isN) {
1369 if (!maySuspend) 1376 if (!maySuspend)
1370 er("May not 'rpc' in main thread of 'code' for <active>"); 1377 er("May not 'rpc' in main thread of 'code' for <active>");
1371 1378
1372 uri = cat(prefix, uri); 1379 uri = cat(prefix, uri);
1373 uri = flattenLocal(uri); 1380 uri = flattenLocal(uri);
1382 isok = true; 1389 isok = true;
1383 } catch (e) { } 1390 } catch (e) { }
1384 1391
1385 if (isok) { 1392 if (isok) {
1386 var lines = xhr.responseText.split("\n"); 1393 var lines = xhr.responseText.split("\n");
1387 if (lines.length != 2) 1394 if (lines.length != 2) {
1388 whine("Bad RPC response lines"); 1395 if (isN == null)
1389 1396 whine("Bad RPC response lines");
1390 eval(lines[0]); 1397 else
1391 1398 k(null);
1392 try { 1399 } else {
1393 k(parse(lines[1])); 1400 eval(lines[0]);
1394 } catch (v) { 1401
1395 doExn(v); 1402 try {
1403 var v = parse(lines[1]);
1404 try {
1405 k(makeSome(isN, v));
1406 } catch (v) {
1407 doExn(v);
1408 }
1409 } catch (v) {
1410 k(null);
1411 }
1396 } 1412 }
1397 } else { 1413 } else {
1398 conn(); 1414 if (isN == null)
1415 conn();
1416 else
1417 k(null);
1399 } 1418 }
1400 1419
1401 xhrFinished(xhr); 1420 xhrFinished(xhr);
1402 } 1421 }
1403 }; 1422 };