summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Adam Chlipala <adam@chlipala.net>2012-04-28 12:00:35 -0400
committerGravatar Adam Chlipala <adam@chlipala.net>2012-04-28 12:00:35 -0400
commit626d7f93ab6873961e6b8c64f28ad36c808efd38 (patch)
treef5adaf9114e53a401ad26536bd644f4e1b1d6691
parent79655cfc46cd36b6c52038cacb33ea5d5adac0fe (diff)
Include JavaScript files properly in error handler pages
-rw-r--r--src/cjr_print.sml35
-rw-r--r--tests/onerrorJs.ur4
-rw-r--r--tests/onerrorJs.urp4
-rw-r--r--tests/onerrorJs.urs1
4 files changed, 32 insertions, 12 deletions
diff --git a/src/cjr_print.sml b/src/cjr_print.sml
index d11b8f30..ba3e58f6 100644
--- a/src/cjr_print.sml
+++ b/src/cjr_print.sml
@@ -2905,6 +2905,19 @@ fun p_file env (ds, ps) =
val app_js = OS.Path.joinDirFile {dir = Settings.getUrlPrefix (),
file = "app." ^ timestamp ^ ".js"}
+ val allScripts =
+ let
+ val scripts =
+ "<script type=\\\"text/javascript\\\" src=\\\""
+ ^ app_js
+ ^ "\\\"></script>\\n"
+ in
+ foldl (fn (x, scripts) =>
+ scripts
+ ^ "<script type=\\\"text/javascript\\\" src=\\\"" ^ x ^ "\\\"></script>\\n")
+ scripts (Settings.getScripts ())
+ end
+
fun p_page (ek, s, n, ts, ran, side, tellSig) =
let
val (ts, defInputs, inputsVar, fields) =
@@ -3032,18 +3045,7 @@ fun p_file env (ds, ps) =
val scripts =
case side of
ServerOnly => ""
- | _ =>
- let
- val scripts =
- "<script type=\\\"text/javascript\\\" src=\\\""
- ^ app_js
- ^ "\\\"></script>\\n"
- in
- foldl (fn (x, scripts) =>
- scripts
- ^ "<script type=\\\"text/javascript\\\" src=\\\"" ^ x ^ "\\\"></script>\\n")
- scripts (Settings.getScripts ())
- end
+ | _ => allScripts
in
string scripts
end,
@@ -3129,6 +3131,7 @@ fun p_file env (ds, ps) =
val expunge = ref 0
val initialize = ref 0
val prepped = ref []
+ val hasJs = ref false
val _ = foldl (fn (d, env) =>
((case #1 d of
@@ -3136,6 +3139,7 @@ fun p_file env (ds, ps) =
dbstring := x;
expunge := y;
initialize := z)
+ | DJavaScript _ => hasJs := true
| DTable (s, xts, _, _) => tables := (s, map (fn (x, t) =>
(x, sql_type_in env t)) xts) :: !tables
| DView (s, xts, _) => views := (s, map (fn (x, t) =>
@@ -3499,6 +3503,13 @@ fun p_file env (ds, ps) =
else
box [string "uw_cutErrorLocation(msg);",
newline],
+ if !hasJs then
+ box [string "uw_set_script_header(ctx, \"",
+ string allScripts,
+ string "\");",
+ newline]
+ else
+ box [],
box [string "uw_write(ctx, ",
p_enamed env n,
string "(ctx, msg, 0));",
diff --git a/tests/onerrorJs.ur b/tests/onerrorJs.ur
new file mode 100644
index 00000000..b53f883e
--- /dev/null
+++ b/tests/onerrorJs.ur
@@ -0,0 +1,4 @@
+fun main n =
+ case n of
+ 0 => error <xml>Zero is bad! <button value="Capische?" onclick={alert "GOOD!"}/></xml>
+ | _ => return <xml/>
diff --git a/tests/onerrorJs.urp b/tests/onerrorJs.urp
new file mode 100644
index 00000000..2ce197e6
--- /dev/null
+++ b/tests/onerrorJs.urp
@@ -0,0 +1,4 @@
+onError OnerrorE.err
+
+onerrorE
+onerrorJs
diff --git a/tests/onerrorJs.urs b/tests/onerrorJs.urs
new file mode 100644
index 00000000..38b757ea
--- /dev/null
+++ b/tests/onerrorJs.urs
@@ -0,0 +1 @@
+val main : int -> transaction page