From 6fead9bd93c982e05fbb5f13e3c866b3acf3ba08 Mon Sep 17 00:00:00 2001 From: Adam Chlipala Date: Sun, 1 Nov 2015 11:55:01 -0500 Subject: Basis.fromMilliseconds --- lib/js/urweb.js | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'lib/js') diff --git a/lib/js/urweb.js b/lib/js/urweb.js index 335cb525..ac4e4c9e 100644 --- a/lib/js/urweb.js +++ b/lib/js/urweb.js @@ -149,6 +149,10 @@ function toMilliseconds(tm) { return Math.round(tm / 1000); } +function fromMilliseconds(tm) { + return tm * 1000; +} + function addSeconds(tm, n) { return tm + n * 1000000; } -- cgit v1.2.3 From 808afe59b97b345f05d16d1a99bbd24c466c8cbf Mon Sep 17 00:00:00 2001 From: Adam Chlipala Date: Sun, 1 Nov 2015 12:23:44 -0500 Subject: Better client-side error messages for RPC failures --- lib/js/urweb.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'lib/js') diff --git a/lib/js/urweb.js b/lib/js/urweb.js index ac4e4c9e..45ed6be8 100644 --- a/lib/js/urweb.js +++ b/lib/js/urweb.js @@ -472,8 +472,11 @@ function onConnectFail(f) { connectHandlers = cons(flift(f), connectHandlers); } -function conn() { - runHandlers("Connect", connectHandlers, null); +function conn(msg) { + var rx = /(.*)((.|\n|\r)*)<\/body>(.*)/g; + var arr = rx.exec(msg); + msg = (arr && arr.length >= 3) ? arr[2] : msg; + runHandlers("RPC failure", connectHandlers, msg); } var serverHandlers = null; @@ -1595,7 +1598,7 @@ function rc(prefix, uri, parse, k, needsSig, isN) { } } else { if (isN == null) - conn(); + conn(xhr.responseText); else k(null); } -- cgit v1.2.3 From b16e75da8b5937914fb17852cd03127934bac08c Mon Sep 17 00:00:00 2001 From: Adam Chlipala Date: Sun, 1 Nov 2015 14:17:09 -0500 Subject: JavaScript versions of a few more functions --- lib/js/urweb.js | 8 ++++++++ src/settings.sml | 5 ++++- 2 files changed, 12 insertions(+), 1 deletion(-) (limited to 'lib/js') diff --git a/lib/js/urweb.js b/lib/js/urweb.js index 45ed6be8..6cf8a3f3 100644 --- a/lib/js/urweb.js +++ b/lib/js/urweb.js @@ -1475,6 +1475,14 @@ function strcmp(str1, str2) { return ((str1 == str2) ? 0 : ((str1 > str2) ? 1 : -1)); } +function chr(n) { + return String.fromCharCode(n); +} + +function htmlifySpecialChar(ch) { + return "&#" + ch.charCodeAt(0) + ";"; +} + // Remote calls diff --git a/src/settings.sml b/src/settings.sml index 0140ddc0..b021b587 100644 --- a/src/settings.sml +++ b/src/settings.sml @@ -376,7 +376,10 @@ val jsFuncsBase = basisM [("alert", "alert"), ("atom", "atom"), ("css_url", "css_url"), ("property", "property"), - ("giveFocus", "giveFocus")] + ("giveFocus", "giveFocus"), + + ("htmlifySpecialChar", "htmlifySpecialChar"), + ("chr", "chr")] val jsFuncs = ref jsFuncsBase fun setJsFuncs ls = jsFuncs := foldl (fn ((k, v), m) => M.insert (m, k, v)) jsFuncsBase ls fun jsFunc x = M.find (!jsFuncs, x) -- cgit v1.2.3